File tree Expand file tree Collapse file tree 3 files changed +19
-4
lines changed Expand file tree Collapse file tree 3 files changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -504,6 +504,7 @@ describe('CdkDrag', () => {
504504 expect ( dragElement . style . touchAction )
505505 . not . toEqual ( 'none' , 'should not disable touchAction on when there is a drag handle' ) ;
506506 } ) ;
507+
507508 it ( 'should be able to reset a freely-dragged item to its initial position' , fakeAsync ( ( ) => {
508509 const fixture = createComponent ( StandaloneDraggable ) ;
509510 fixture . detectChanges ( ) ;
@@ -556,7 +557,17 @@ describe('CdkDrag', () => {
556557 expect ( fixture . componentInstance . endedSpy ) . toHaveBeenCalledTimes ( 1 ) ;
557558 } ) ) ;
558559
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+ } ) ;
560571
561572 describe ( 'draggable with a handle' , ( ) => {
562573 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 {
866866 * @param y Desired position of the element along the Y axis.
867867 */
868868function 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)` ;
870872}
871873
872874/** 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 {
362362 // Note that we shouldn't use `getBoundingClientRect` here to update the cache, because the
363363 // elements may be mid-animation which will give us a wrong result.
364364 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)` ;
366368 this . _adjustClientRect ( sibling . clientRect , 0 , offset ) ;
367369 } else {
368- elementToOffset . style . transform = `translate3d(0, ${ sibling . offset } px, 0)` ;
370+ elementToOffset . style . transform = `translate3d(0, ${ Math . round ( sibling . offset ) } px, 0)` ;
369371 this . _adjustClientRect ( sibling . clientRect , offset , 0 ) ;
370372 }
371373 } ) ;
You can’t perform that action at this time.
0 commit comments