@@ -282,7 +282,7 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {
282282 public ghostHost ;
283283
284284 /**
285- * An @Input property that specifies the offset of the ghost created relative to the mouse in pixels.
285+ * An @Input property that specifies the offset of the dragged element relative to the mouse in pixels.
286286 * By default it's taking the relative position to the mouse when the drag started and keeps it the same.
287287 * ```html
288288 * <div #hostDiv></div>
@@ -294,15 +294,15 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {
294294 */
295295 @Input ( )
296296 public set ghostOffsetX ( value ) {
297- this . _ghostOffsetX = parseInt ( value , 10 ) ;
297+ this . _offsetX = parseInt ( value , 10 ) ;
298298 }
299299
300300 public get ghostOffsetX ( ) {
301- return this . _ghostOffsetX ;
301+ return this . _offsetX !== undefined ? this . _offsetX : this . _defaultOffsetX ;
302302 }
303303
304304 /**
305- * An @Input property that specifies the offset of the ghost created relative to the mouse in pixels.
305+ * An @Input property that specifies the offset of the dragged element relative to the mouse in pixels.
306306 * By default it's taking the relative position to the mouse when the drag started and keeps it the same.
307307 * ```html
308308 * <div #hostDiv></div>
@@ -314,11 +314,11 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {
314314 */
315315 @Input ( )
316316 public set ghostOffsetY ( value ) {
317- this . _ghostOffsetY = parseInt ( value , 10 ) ;
317+ this . _offsetY = parseInt ( value , 10 ) ;
318318 }
319319
320320 public get ghostOffsetY ( ) {
321- return this . _ghostOffsetY ;
321+ return this . _offsetY !== undefined ? this . _offsetY : this . _defaultOffsetY ;
322322 }
323323
324324 /**
@@ -613,17 +613,17 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {
613613 protected _baseMarginTop = 0 ;
614614 protected _baseOriginX ;
615615 protected _baseOriginY ;
616- protected _baseLeft ;
617- protected _baseTop ;
618616 protected _startX = 0 ;
619617 protected _startY = 0 ;
620618 protected _lastX = 0 ;
621619 protected _lastY = 0 ;
622620 protected _dragStarted = false ;
623621
624622 /** Drag ghost related properties */
625- protected _ghostOffsetX ;
626- protected _ghostOffsetY ;
623+ protected _defaultOffsetX ;
624+ protected _defaultOffsetY ;
625+ protected _offsetX ;
626+ protected _offsetY ;
627627 protected _ghostStartX ;
628628 protected _ghostStartY ;
629629 protected _ghostHostX = 0 ;
@@ -887,22 +887,10 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {
887887 this . _startY = event . touches [ 0 ] . pageY ;
888888 }
889889
890- let offsetX ;
891- if ( this . ghostOffsetX !== undefined ) {
892- offsetX = this . ghostOffsetX ;
893- } else {
894- offsetX = this . baseLeft + this . getWindowScrollLeft ( ) - this . _startX ;
895- }
896-
897- let offsetY ;
898- if ( this . ghostOffsetY !== undefined ) {
899- offsetY = this . ghostOffsetY ;
900- } else {
901- offsetY = this . baseTop + this . getWindowScrollTop ( ) - this . _startY ;
902- }
903-
904- this . _ghostStartX = this . _startX + offsetX ;
905- this . _ghostStartY = this . _startY + offsetY ;
890+ this . _defaultOffsetX = this . baseLeft + this . getWindowScrollLeft ( ) - this . _startX ;
891+ this . _defaultOffsetY = this . baseTop + this . getWindowScrollTop ( ) - this . _startY ;
892+ this . _ghostStartX = this . _startX + this . ghostOffsetX ;
893+ this . _ghostStartY = this . _startY + this . ghostOffsetY ;
906894 this . _lastX = this . _startX ;
907895 this . _lastY = this . _startY ;
908896 }
@@ -950,7 +938,15 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {
950938 this . _dragStarted = true ;
951939 if ( this . ghost ) {
952940 // We moved enough so ghostElement can be rendered and actual dragging to start.
941+ // When creating it will take into account any offset set by the user by default.
953942 this . createGhost ( pageX , pageY ) ;
943+ } else if ( this . _offsetX !== undefined || this . _offsetY !== undefined ) {
944+ // There is no need for ghost, but we will need to position initially the base element to reflect any offset.
945+ const transformX = ( this . _offsetX !== undefined ? this . _offsetX - this . _defaultOffsetX : 0 ) +
946+ this . getTransformX ( this . element . nativeElement ) ;
947+ const transformY = ( this . _offsetY !== undefined ? this . _offsetY - this . _defaultOffsetY : 0 ) +
948+ this . getTransformY ( this . element . nativeElement ) ;
949+ this . setTransformXY ( transformX , transformY ) ;
954950 }
955951 } else {
956952 return ;
@@ -1393,10 +1389,6 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {
13931389
13941390 /** Method setting transformation to the base draggable element. */
13951391 protected setTransformXY ( x : number , y : number ) {
1396- const curX = this . getTransformX ( this . element . nativeElement ) ;
1397- const curY = this . getTransformY ( this . element . nativeElement ) ;
1398- this . _baseLeft += x - curX ;
1399- this . _baseTop += y - curY ;
14001392 this . element . nativeElement . style . transform = 'translate3d(' + x + 'px, ' + y + 'px, 0px)' ;
14011393 }
14021394
0 commit comments