Skip to content

fix(cdk/drag-drop): incorrect type DragConstrainPosition #30510

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/cdk/drag-drop/directives/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,14 @@
*/

import {InjectionToken} from '@angular/core';
import {DragRefConfig, Point, DragRef} from '../drag-ref';
import {DragRefConfig, DragConstrainPosition} from '../drag-ref';

/** Possible values that can be used to configure the drag start delay. */
export type DragStartDelay = number | {touch: number; mouse: number};

/** Possible axis along which dragging can be locked. */
export type DragAxis = 'x' | 'y';

/** Function that can be used to constrain the position of a dragged element. */
export type DragConstrainPosition = (point: Point, dragRef: DragRef) => Point;

/** Possible orientations for a drop list. */
export type DropListOrientation = 'horizontal' | 'vertical' | 'mixed';

Expand Down
9 changes: 2 additions & 7 deletions src/cdk/drag-drop/directives/drag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import {CDK_DRAG_HANDLE, CdkDragHandle} from './drag-handle';
import {CdkDragPlaceholder} from './drag-placeholder';
import {CdkDragPreview} from './drag-preview';
import {CDK_DRAG_PARENT} from '../drag-parent';
import {DragRef, Point, PreviewContainer} from '../drag-ref';
import {DragRef, Point, PreviewContainer, DragConstrainPosition} from '../drag-ref';
import type {CdkDropList} from './drop-list';
import {DragDrop} from '../drag-drop';
import {CDK_DRAG_CONFIG, DragDropConfig, DragStartDelay, DragAxis} from './config';
Expand Down Expand Up @@ -137,12 +137,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnChanges, OnDestroy {
* of the user's pointer on the page, a reference to the item being dragged and its dimensions.
* Should return a point describing where the item should be rendered.
*/
@Input('cdkDragConstrainPosition') constrainPosition?: (
userPointerPosition: Point,
dragRef: DragRef,
dimensions: DOMRect,
pickupPositionInElement: Point,
) => Point;
@Input('cdkDragConstrainPosition') constrainPosition?: DragConstrainPosition;

/** Class to be added to the preview element. */
@Input('cdkDragPreviewClass') previewClass: string | string[];
Expand Down
15 changes: 9 additions & 6 deletions src/cdk/drag-drop/drag-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ export interface DragRefConfig {
parentDragRef?: DragRef;
}

/** Function that can be used to constrain the position of a dragged element. */
export type DragConstrainPosition = (
userPointerPosition: Point,
dragRef: DragRef,
dimensions: DOMRect,
pickupPositionInElement: Point,
) => Point;

/** Options that can be used to bind a passive event listener. */
const passiveEventListenerOptions = {passive: true};

Expand Down Expand Up @@ -364,12 +372,7 @@ export class DragRef<T = any> {
* of the user's pointer on the page, a reference to the item being dragged and its dimensions.
* Should return a point describing where the item should be rendered.
*/
constrainPosition?: (
userPointerPosition: Point,
dragRef: DragRef,
dimensions: DOMRect,
pickupPositionInElement: Point,
) => Point;
constrainPosition?: DragConstrainPosition;

constructor(
element: ElementRef<HTMLElement> | HTMLElement,
Expand Down
2 changes: 1 addition & 1 deletion src/cdk/drag-drop/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

export {DragDrop} from './drag-drop';
export {DragRef, DragRefConfig, Point, PreviewContainer} from './drag-ref';
export {DragRef, DragRefConfig, Point, PreviewContainer, DragConstrainPosition} from './drag-ref';
export {DropListRef} from './drop-list-ref';
export {CDK_DRAG_PARENT} from './drag-parent';

Expand Down
6 changes: 3 additions & 3 deletions tools/public_api_guard/cdk/drag-drop.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnChanges, OnDestroy {
// (undocumented)
_addHandle(handle: CdkDragHandle): void;
boundaryElement: string | ElementRef<HTMLElement> | HTMLElement;
constrainPosition?: (userPointerPosition: Point, dragRef: DragRef, dimensions: DOMRect, pickupPositionInElement: Point) => Point;
constrainPosition?: DragConstrainPosition;
data: T;
get disabled(): boolean;
set disabled(value: boolean);
Expand Down Expand Up @@ -300,7 +300,7 @@ export function copyArrayItem<T = any>(currentArray: T[], targetArray: T[], curr
export type DragAxis = 'x' | 'y';

// @public
export type DragConstrainPosition = (point: Point, dragRef: DragRef) => Point;
export type DragConstrainPosition = (userPointerPosition: Point, dragRef: DragRef, dimensions: DOMRect, pickupPositionInElement: Point) => Point;

// @public
export class DragDrop {
Expand Down Expand Up @@ -381,7 +381,7 @@ export class DragDropRegistry<_ = unknown, __ = unknown> implements OnDestroy {
export class DragRef<T = any> {
constructor(element: ElementRef<HTMLElement> | HTMLElement, _config: DragRefConfig, _document: Document, _ngZone: NgZone, _viewportRuler: ViewportRuler, _dragDropRegistry: DragDropRegistry, _renderer: Renderer2);
readonly beforeStarted: Subject<void>;
constrainPosition?: (userPointerPosition: Point, dragRef: DragRef, dimensions: DOMRect, pickupPositionInElement: Point) => Point;
constrainPosition?: DragConstrainPosition;
data: T;
get disabled(): boolean;
set disabled(value: boolean);
Expand Down
Loading