@@ -763,6 +763,78 @@ describe('CdkDrag', () => {
763
763
expect ( dragElement . style . transform ) . toBe ( 'translate3d(100px, 100px, 0px)' ) ;
764
764
} ) ) ;
765
765
766
+ it ( 'should adjust the x offset if the boundary becomes narrower after a viewport resize' ,
767
+ fakeAsync ( ( ) => {
768
+ const fixture = createComponent ( StandaloneDraggable ) ;
769
+ const boundary : HTMLElement = fixture . nativeElement . querySelector ( '.wrapper' ) ;
770
+ fixture . componentInstance . boundary = boundary ;
771
+ fixture . detectChanges ( ) ;
772
+ const dragElement = fixture . componentInstance . dragElement . nativeElement ;
773
+
774
+ dragElementViaMouse ( fixture , dragElement , 300 , 300 ) ;
775
+ expect ( dragElement . style . transform ) . toBe ( 'translate3d(100px, 100px, 0px)' ) ;
776
+
777
+ boundary . style . width = '150px' ;
778
+ dispatchFakeEvent ( window , 'resize' ) ;
779
+ tick ( 20 ) ;
780
+
781
+ expect ( dragElement . style . transform ) . toBe ( 'translate3d(50px, 100px, 0px)' ) ;
782
+ } ) ) ;
783
+
784
+ it ( 'should adjust the y offset if the boundary becomes shorter after a viewport resize' ,
785
+ fakeAsync ( ( ) => {
786
+ const fixture = createComponent ( StandaloneDraggable ) ;
787
+ const boundary : HTMLElement = fixture . nativeElement . querySelector ( '.wrapper' ) ;
788
+ fixture . componentInstance . boundary = boundary ;
789
+ fixture . detectChanges ( ) ;
790
+ const dragElement = fixture . componentInstance . dragElement . nativeElement ;
791
+
792
+ dragElementViaMouse ( fixture , dragElement , 300 , 300 ) ;
793
+ expect ( dragElement . style . transform ) . toBe ( 'translate3d(100px, 100px, 0px)' ) ;
794
+
795
+ boundary . style . height = '150px' ;
796
+ dispatchFakeEvent ( window , 'resize' ) ;
797
+ tick ( 20 ) ;
798
+
799
+ expect ( dragElement . style . transform ) . toBe ( 'translate3d(100px, 50px, 0px)' ) ;
800
+ } ) ) ;
801
+
802
+ it ( 'should reset the x offset if the boundary becomes narrower than the element ' +
803
+ 'after a resize' , fakeAsync ( ( ) => {
804
+ const fixture = createComponent ( StandaloneDraggable ) ;
805
+ const boundary : HTMLElement = fixture . nativeElement . querySelector ( '.wrapper' ) ;
806
+ fixture . componentInstance . boundary = boundary ;
807
+ fixture . detectChanges ( ) ;
808
+ const dragElement = fixture . componentInstance . dragElement . nativeElement ;
809
+
810
+ dragElementViaMouse ( fixture , dragElement , 300 , 300 ) ;
811
+ expect ( dragElement . style . transform ) . toBe ( 'translate3d(100px, 100px, 0px)' ) ;
812
+
813
+ boundary . style . width = '50px' ;
814
+ dispatchFakeEvent ( window , 'resize' ) ;
815
+ tick ( 20 ) ;
816
+
817
+ expect ( dragElement . style . transform ) . toBe ( 'translate3d(0px, 100px, 0px)' ) ;
818
+ } ) ) ;
819
+
820
+ it ( 'should reset the y offset if the boundary becomes shorter than the element after a resize' ,
821
+ fakeAsync ( ( ) => {
822
+ const fixture = createComponent ( StandaloneDraggable ) ;
823
+ const boundary : HTMLElement = fixture . nativeElement . querySelector ( '.wrapper' ) ;
824
+ fixture . componentInstance . boundary = boundary ;
825
+ fixture . detectChanges ( ) ;
826
+ const dragElement = fixture . componentInstance . dragElement . nativeElement ;
827
+
828
+ dragElementViaMouse ( fixture , dragElement , 300 , 300 ) ;
829
+ expect ( dragElement . style . transform ) . toBe ( 'translate3d(100px, 100px, 0px)' ) ;
830
+
831
+ boundary . style . height = '50px' ;
832
+ dispatchFakeEvent ( window , 'resize' ) ;
833
+ tick ( 20 ) ;
834
+
835
+ expect ( dragElement . style . transform ) . toBe ( 'translate3d(100px, 0px, 0px)' ) ;
836
+ } ) ) ;
837
+
766
838
it ( 'should allow for the position constrain logic to be customized' , fakeAsync ( ( ) => {
767
839
const fixture = createComponent ( StandaloneDraggable ) ;
768
840
const spy = jasmine . createSpy ( 'constrain position spy' ) . and . returnValue ( {
0 commit comments