@@ -560,6 +560,32 @@ describe('CdkDrag', () => {
560
560
expect ( dragElement . style . transform ) . toBe ( 'translate3d(150px, 0px, 0px)' ) ;
561
561
} ) ) ;
562
562
563
+ it ( 'should be able to lock dragging along the x axis while using constrainPosition' , fakeAsync ( ( ) => {
564
+ const fixture = createComponent ( StandaloneDraggable ) ;
565
+ fixture . detectChanges ( ) ;
566
+ fixture . componentInstance . dragInstance . lockAxis = 'x' ;
567
+ fixture . componentInstance . dragInstance . constrainPosition = (
568
+ { x, y} : Point ,
569
+ _dragRef : DragRef ,
570
+ _dimensions : ClientRect ,
571
+ pickup : Point ,
572
+ ) => {
573
+ x -= pickup . x ;
574
+ y -= pickup . y ;
575
+ return { x, y} ;
576
+ } ;
577
+
578
+ const dragElement = fixture . componentInstance . dragElement . nativeElement ;
579
+
580
+ expect ( dragElement . style . transform ) . toBeFalsy ( ) ;
581
+
582
+ dragElementViaMouse ( fixture , dragElement , 50 , 100 ) ;
583
+ expect ( dragElement . style . transform ) . toBe ( 'translate3d(50px, 0px, 0px)' ) ;
584
+
585
+ dragElementViaMouse ( fixture , dragElement , 100 , 200 ) ;
586
+ expect ( dragElement . style . transform ) . toBe ( 'translate3d(150px, 0px, 0px)' ) ;
587
+ } ) ) ;
588
+
563
589
it ( 'should be able to lock dragging along the y axis' , fakeAsync ( ( ) => {
564
590
const fixture = createComponent ( StandaloneDraggable ) ;
565
591
fixture . detectChanges ( ) ;
@@ -576,6 +602,33 @@ describe('CdkDrag', () => {
576
602
expect ( dragElement . style . transform ) . toBe ( 'translate3d(0px, 300px, 0px)' ) ;
577
603
} ) ) ;
578
604
605
+ it ( 'should be able to lock dragging along the y axis while using constrainPosition' , fakeAsync ( ( ) => {
606
+ const fixture = createComponent ( StandaloneDraggable ) ;
607
+ fixture . detectChanges ( ) ;
608
+
609
+ fixture . componentInstance . dragInstance . lockAxis = 'y' ;
610
+ fixture . componentInstance . dragInstance . constrainPosition = (
611
+ { x, y} : Point ,
612
+ _dragRef : DragRef ,
613
+ _dimensions : ClientRect ,
614
+ pickup : Point ,
615
+ ) => {
616
+ x -= pickup . x ;
617
+ y -= pickup . y ;
618
+ return { x, y} ;
619
+ } ;
620
+
621
+ const dragElement = fixture . componentInstance . dragElement . nativeElement ;
622
+
623
+ expect ( dragElement . style . transform ) . toBeFalsy ( ) ;
624
+
625
+ dragElementViaMouse ( fixture , dragElement , 50 , 100 ) ;
626
+ expect ( dragElement . style . transform ) . toBe ( 'translate3d(0px, 100px, 0px)' ) ;
627
+
628
+ dragElementViaMouse ( fixture , dragElement , 100 , 200 ) ;
629
+ expect ( dragElement . style . transform ) . toBe ( 'translate3d(0px, 300px, 0px)' ) ;
630
+ } ) ) ;
631
+
579
632
it ( 'should add a class while an element is being dragged' , fakeAsync ( ( ) => {
580
633
const fixture = createComponent ( StandaloneDraggable ) ;
581
634
fixture . detectChanges ( ) ;
@@ -946,6 +999,29 @@ describe('CdkDrag', () => {
946
999
expect ( dragElement . style . transform ) . toBe ( 'translate3d(100px, 100px, 0px)' ) ;
947
1000
} ) ) ;
948
1001
1002
+ it ( 'should allow for dragging to be constrained to an element while using constrainPosition' , fakeAsync ( ( ) => {
1003
+ const fixture = createComponent ( StandaloneDraggable ) ;
1004
+ fixture . componentInstance . boundary = '.wrapper' ;
1005
+ fixture . detectChanges ( ) ;
1006
+
1007
+ fixture . componentInstance . dragInstance . constrainPosition = (
1008
+ { x, y} : Point ,
1009
+ _dragRef : DragRef ,
1010
+ _dimensions : ClientRect ,
1011
+ pickup : Point ,
1012
+ ) => {
1013
+ x -= pickup . x ;
1014
+ y -= pickup . y ;
1015
+ return { x, y} ;
1016
+ } ;
1017
+
1018
+ const dragElement = fixture . componentInstance . dragElement . nativeElement ;
1019
+
1020
+ expect ( dragElement . style . transform ) . toBeFalsy ( ) ;
1021
+ dragElementViaMouse ( fixture , dragElement , 300 , 300 ) ;
1022
+ expect ( dragElement . style . transform ) . toBe ( 'translate3d(100px, 100px, 0px)' ) ;
1023
+ } ) ) ;
1024
+
949
1025
it ( 'should be able to pass in a DOM node as the boundary' , fakeAsync ( ( ) => {
950
1026
const fixture = createComponent ( StandaloneDraggable ) ;
951
1027
fixture . componentInstance . boundary = fixture . nativeElement . querySelector ( '.wrapper' ) ;
0 commit comments