File tree 3 files changed +19
-4
lines changed
3 files changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -504,6 +504,7 @@ describe('CdkDrag', () => {
504
504
expect ( dragElement . style . touchAction )
505
505
. not . toEqual ( 'none' , 'should not disable touchAction on when there is a drag handle' ) ;
506
506
} ) ;
507
+
507
508
it ( 'should be able to reset a freely-dragged item to its initial position' , fakeAsync ( ( ) => {
508
509
const fixture = createComponent ( StandaloneDraggable ) ;
509
510
fixture . detectChanges ( ) ;
@@ -556,7 +557,17 @@ describe('CdkDrag', () => {
556
557
expect ( fixture . componentInstance . endedSpy ) . toHaveBeenCalledTimes ( 1 ) ;
557
558
} ) ) ;
558
559
559
- } ) ;
560
+ it ( 'should round the transform value' , fakeAsync ( ( ) => {
561
+ const fixture = createComponent ( StandaloneDraggable ) ;
562
+ fixture . detectChanges ( ) ;
563
+ const dragElement = fixture . componentInstance . dragElement . nativeElement ;
564
+
565
+ expect ( dragElement . style . transform ) . toBeFalsy ( ) ;
566
+ dragElementViaMouse ( fixture , dragElement , 13.37 , 37 ) ;
567
+ expect ( dragElement . style . transform ) . toBe ( 'translate3d(13px, 37px, 0px)' ) ;
568
+ } ) ) ;
569
+
570
+ } ) ;
560
571
561
572
describe ( 'draggable with a handle' , ( ) => {
562
573
it ( 'should not be able to drag the entire element if it has a handle' , fakeAsync ( ( ) => {
Original file line number Diff line number Diff line change @@ -866,7 +866,9 @@ interface Point {
866
866
* @param y Desired position of the element along the Y axis.
867
867
*/
868
868
function getTransform ( x : number , y : number ) : string {
869
- return `translate3d(${ x } px, ${ y } px, 0)` ;
869
+ // Round the transforms since some browsers will
870
+ // blur the elements, for sub-pixel transforms.
871
+ return `translate3d(${ Math . round ( x ) } px, ${ Math . round ( y ) } px, 0)` ;
870
872
}
871
873
872
874
/** Creates a deep clone of an element. */
Original file line number Diff line number Diff line change @@ -362,10 +362,12 @@ export class CdkDropList<T = any> implements OnInit, OnDestroy {
362
362
// Note that we shouldn't use `getBoundingClientRect` here to update the cache, because the
363
363
// elements may be mid-animation which will give us a wrong result.
364
364
if ( isHorizontal ) {
365
- elementToOffset . style . transform = `translate3d(${ sibling . offset } px, 0, 0)` ;
365
+ // Round the transforms since some browsers will
366
+ // blur the elements, for sub-pixel transforms.
367
+ elementToOffset . style . transform = `translate3d(${ Math . round ( sibling . offset ) } px, 0, 0)` ;
366
368
this . _adjustClientRect ( sibling . clientRect , 0 , offset ) ;
367
369
} else {
368
- elementToOffset . style . transform = `translate3d(0, ${ sibling . offset } px, 0)` ;
370
+ elementToOffset . style . transform = `translate3d(0, ${ Math . round ( sibling . offset ) } px, 0)` ;
369
371
this . _adjustClientRect ( sibling . clientRect , offset , 0 ) ;
370
372
}
371
373
} ) ;
You can’t perform that action at this time.
0 commit comments