@@ -763,6 +763,24 @@ describe('CdkDrag', () => {
763763 expect ( dragElement . style . transform ) . toBe ( 'translate3d(100px, 100px, 0px)' ) ;
764764 } ) ) ;
765765
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+
766784 it ( 'should handle the element and boundary dimensions changing between drag sequences' ,
767785 fakeAsync ( ( ) => {
768786 const fixture = createComponent ( StandaloneDraggable ) ;
@@ -782,6 +800,60 @@ describe('CdkDrag', () => {
782800 expect ( dragElement . style . transform ) . toBe ( 'translate3d(150px, 150px, 0px)' ) ;
783801 } ) ) ;
784802
803+ it ( 'should adjust the y offset if the boundary becomes shorter after a viewport resize' ,
804+ fakeAsync ( ( ) => {
805+ const fixture = createComponent ( StandaloneDraggable ) ;
806+ const boundary : HTMLElement = fixture . nativeElement . querySelector ( '.wrapper' ) ;
807+ fixture . componentInstance . boundary = boundary ;
808+ fixture . detectChanges ( ) ;
809+ const dragElement = fixture . componentInstance . dragElement . nativeElement ;
810+
811+ dragElementViaMouse ( fixture , dragElement , 300 , 300 ) ;
812+ expect ( dragElement . style . transform ) . toBe ( 'translate3d(100px, 100px, 0px)' ) ;
813+
814+ boundary . style . height = '150px' ;
815+ dispatchFakeEvent ( window , 'resize' ) ;
816+ tick ( 20 ) ;
817+
818+ expect ( dragElement . style . transform ) . toBe ( 'translate3d(100px, 50px, 0px)' ) ;
819+ } ) ) ;
820+
821+ it ( 'should reset the x offset if the boundary becomes narrower than the element ' +
822+ 'after a resize' , fakeAsync ( ( ) => {
823+ const fixture = createComponent ( StandaloneDraggable ) ;
824+ const boundary : HTMLElement = fixture . nativeElement . querySelector ( '.wrapper' ) ;
825+ fixture . componentInstance . boundary = boundary ;
826+ fixture . detectChanges ( ) ;
827+ const dragElement = fixture . componentInstance . dragElement . nativeElement ;
828+
829+ dragElementViaMouse ( fixture , dragElement , 300 , 300 ) ;
830+ expect ( dragElement . style . transform ) . toBe ( 'translate3d(100px, 100px, 0px)' ) ;
831+
832+ boundary . style . width = '50px' ;
833+ dispatchFakeEvent ( window , 'resize' ) ;
834+ tick ( 20 ) ;
835+
836+ expect ( dragElement . style . transform ) . toBe ( 'translate3d(0px, 100px, 0px)' ) ;
837+ } ) ) ;
838+
839+ it ( 'should reset the y offset if the boundary becomes shorter than the element after a resize' ,
840+ fakeAsync ( ( ) => {
841+ const fixture = createComponent ( StandaloneDraggable ) ;
842+ const boundary : HTMLElement = fixture . nativeElement . querySelector ( '.wrapper' ) ;
843+ fixture . componentInstance . boundary = boundary ;
844+ fixture . detectChanges ( ) ;
845+ const dragElement = fixture . componentInstance . dragElement . nativeElement ;
846+
847+ dragElementViaMouse ( fixture , dragElement , 300 , 300 ) ;
848+ expect ( dragElement . style . transform ) . toBe ( 'translate3d(100px, 100px, 0px)' ) ;
849+
850+ boundary . style . height = '50px' ;
851+ dispatchFakeEvent ( window , 'resize' ) ;
852+ tick ( 20 ) ;
853+
854+ expect ( dragElement . style . transform ) . toBe ( 'translate3d(100px, 0px, 0px)' ) ;
855+ } ) ) ;
856+
785857 it ( 'should allow for the position constrain logic to be customized' , fakeAsync ( ( ) => {
786858 const fixture = createComponent ( StandaloneDraggable ) ;
787859 const spy = jasmine . createSpy ( 'constrain position spy' ) . and . returnValue ( {
0 commit comments