diff --git a/goldens/cdk/drag-drop/index.api.md b/goldens/cdk/drag-drop/index.api.md index 2cc3e5d36cab..63b89f3124e8 100644 --- a/goldens/cdk/drag-drop/index.api.md +++ b/goldens/cdk/drag-drop/index.api.md @@ -66,7 +66,7 @@ export class CdkDrag implements AfterViewInit, OnChanges, OnDestroy { getFreeDragPosition(): Readonly; getPlaceholderElement(): HTMLElement; getRootElement(): HTMLElement; - lockAxis: DragAxis; + lockAxis: DragAxis | null; readonly moved: Observable>; // (undocumented) static ngAcceptInputType_disabled: unknown; @@ -259,7 +259,7 @@ export class CdkDropList implements OnDestroy { getSortedItems(): CdkDrag[]; hasAnchor: boolean; id: string; - lockAxis: DragAxis; + lockAxis: DragAxis | null; // (undocumented) static ngAcceptInputType_autoScrollDisabled: unknown; // (undocumented) @@ -330,7 +330,7 @@ export interface DragDropConfig extends Partial { // (undocumented) listOrientation?: DropListOrientation; // (undocumented) - lockAxis?: DragAxis; + lockAxis?: DragAxis | null; // (undocumented) previewClass?: string | string[]; // (undocumented) @@ -423,7 +423,7 @@ export class DragRef { getRootElement(): HTMLElement; getVisibleElement(): HTMLElement; isDragging(): boolean; - lockAxis: 'x' | 'y'; + lockAxis: 'x' | 'y' | null; readonly moved: Observable<{ source: DragRef; pointerPosition: { @@ -523,7 +523,7 @@ export class DropListRef { isDragging(): boolean; _isOverContainer(x: number, y: number): boolean; isReceiving(): boolean; - lockAxis: 'x' | 'y'; + lockAxis: 'x' | 'y' | null; readonly receivingStarted: Subject<{ receiver: DropListRef; initiator: DropListRef; diff --git a/src/cdk/drag-drop/directives/config.ts b/src/cdk/drag-drop/directives/config.ts index 2263935d85c0..72794f8277b3 100644 --- a/src/cdk/drag-drop/directives/config.ts +++ b/src/cdk/drag-drop/directives/config.ts @@ -29,7 +29,7 @@ export const CDK_DRAG_CONFIG = new InjectionToken('CDK_DRAG_CONF * items and drop lists within a module or a component. */ export interface DragDropConfig extends Partial { - lockAxis?: DragAxis; + lockAxis?: DragAxis | null; dragStartDelay?: DragStartDelay; constrainPosition?: DragConstrainPosition; previewClass?: string | string[]; diff --git a/src/cdk/drag-drop/directives/drag.ts b/src/cdk/drag-drop/directives/drag.ts index 9e8c738a3b60..436b9935943f 100644 --- a/src/cdk/drag-drop/directives/drag.ts +++ b/src/cdk/drag-drop/directives/drag.ts @@ -91,7 +91,7 @@ export class CdkDrag implements AfterViewInit, OnChanges, OnDestroy { @Input('cdkDragData') data: T; /** Locks the position of the dragged element along the specified axis. */ - @Input('cdkDragLockAxis') lockAxis: DragAxis; + @Input('cdkDragLockAxis') lockAxis: DragAxis | null = null; /** * Selector that will be used to determine the root draggable element, starting from @@ -560,10 +560,7 @@ export class CdkDrag implements AfterViewInit, OnChanges, OnDestroy { this.disabled = draggingDisabled == null ? false : draggingDisabled; this.dragStartDelay = dragStartDelay || 0; - - if (lockAxis) { - this.lockAxis = lockAxis; - } + this.lockAxis = lockAxis || null; if (constrainPosition) { this.constrainPosition = constrainPosition; diff --git a/src/cdk/drag-drop/directives/drop-list.ts b/src/cdk/drag-drop/directives/drop-list.ts index bab8a65c91d1..7049d55409d0 100644 --- a/src/cdk/drag-drop/directives/drop-list.ts +++ b/src/cdk/drag-drop/directives/drop-list.ts @@ -95,7 +95,7 @@ export class CdkDropList implements OnDestroy { @Input() id: string = inject(_IdGenerator).getId('cdk-drop-list-'); /** Locks the position of the draggable elements inside the container along the specified axis. */ - @Input('cdkDropListLockAxis') lockAxis: DragAxis; + @Input('cdkDropListLockAxis') lockAxis: DragAxis | null = null; /** Whether starting a dragging sequence from this container is disabled. */ @Input({alias: 'cdkDropListDisabled', transform: booleanAttribute}) @@ -425,10 +425,7 @@ export class CdkDropList implements OnDestroy { this.sortingDisabled = sortingDisabled == null ? false : sortingDisabled; this.autoScrollDisabled = listAutoScrollDisabled == null ? false : listAutoScrollDisabled; this.orientation = listOrientation || 'vertical'; - - if (lockAxis) { - this.lockAxis = lockAxis; - } + this.lockAxis = lockAxis || null; } /** Syncs up the registered drag items with underlying drop list ref. */ diff --git a/src/cdk/drag-drop/drag-ref.ts b/src/cdk/drag-drop/drag-ref.ts index 7ec72ab499b7..63c83d0881af 100644 --- a/src/cdk/drag-drop/drag-ref.ts +++ b/src/cdk/drag-drop/drag-ref.ts @@ -293,7 +293,7 @@ export class DragRef { private _cachedShadowRoot: ShadowRoot | null | undefined; /** Axis along which dragging is locked. */ - lockAxis: 'x' | 'y'; + lockAxis: 'x' | 'y' | null = null; /** * Amount of milliseconds to wait after the user has put their diff --git a/src/cdk/drag-drop/drop-list-ref.ts b/src/cdk/drag-drop/drop-list-ref.ts index f62ff93616ec..2e2fd8436676 100644 --- a/src/cdk/drag-drop/drop-list-ref.ts +++ b/src/cdk/drag-drop/drop-list-ref.ts @@ -63,7 +63,7 @@ export class DropListRef { sortingDisabled: boolean = false; /** Locks the position of the draggable elements inside the container along the specified axis. */ - lockAxis: 'x' | 'y'; + lockAxis: 'x' | 'y' | null = null; /** * Whether auto-scrolling the view when the user