Skip to content

Draggable element is not inside of the node passed into cdkDragBoundary. #23767

Closed
@mgameover

Description

@mgameover

Hi everyone,

Is there a specific reason for this check drag.ts#L363-L366?

    if ((typeof ngDevMode === 'undefined' || ngDevMode) &&
      !element.contains(this.element.nativeElement)) {
      throw Error('Draggable element is not inside of the node passed into cdkDragBoundary.');
    }

The thing is it throws the error only in devMode, but it works perfectly fine in production. I think those lines can be removed.

Reproduction

Steps to reproduce:

  1. Use the following html markup
<div #boundaryHTMLElement style="width:640px;height:480px"></div>
<div 
	cdkDrag
	[cdkDragBoundary]="boundaryHTMLElement"
>...</div>

  1. run application in dev mode (ng serve)
  2. Drag element: error appears in console log, draggable's position is not constrained
  3. Build app for production (ng build --configuration production)
  4. Drag element: no errors in console log, draggable's position is constrained

Expected Behavior

Same (production) behavior for dev environment

Actual Behavior

The following exception is thrown (in ngDevMode only)

Uncaught Error: Draggable element is not inside of the node passed into cdkDragBoundary.
    at CdkDrag._getBoundaryElement (drag-drop.js:3418)
    at SafeSubscriber._next (drag-drop.js:3446)
    at SafeSubscriber.__tryOrUnsub (Subscriber.js:183)
    at SafeSubscriber.next (Subscriber.js:122)
    at Subscriber._next (Subscriber.js:72)
    at Subscriber.next (Subscriber.js:49)
    at Subject.next (Subject.js:39)
    at HTMLDivElement.DragRef._pointerDown (drag-drop.js:411)
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:434)
    at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:205)
_getBoundaryElement @ drag-drop.js:3418

Environment

  • Angular: 12.2.10
  • CDK/Material: 12.2.9
  • Browser(s): any
  • Operating System (e.g. Windows, macOS, Ubuntu): any

Metadata

Metadata

Assignees

Labels

P4A relatively minor issue that is not relevant to core functionsarea: cdk/drag-drop

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions