Skip to content
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

fix: multifield item not scrollable when dragged #376

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions coral-component-multifield/src/scripts/MultifieldItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ const MultifieldItem = Decorator(class extends BaseComponent(HTMLElement) {
const dragAction = new DragAction(this);
dragAction.axis = 'vertical';
dragAction.handle = this._elements.move;
dragAction.scroll = true;
dragAction.useScrollParent = true;
}
});

Expand Down
19 changes: 18 additions & 1 deletion coral-dragaction/src/scripts/DragAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ function isOverDropZone(dragAction) {
return el;
}

function getScrollParent(node) {
if (!node) {
return null;
}

return node.scrollHeight > node.clientHeight ? node : getScrollParent(node.parentNode);
}

/**
@class Coral.DragAction
@classdesc This a decorator which adds draggable functionality to elements.
Expand Down Expand Up @@ -391,6 +399,14 @@ class DragAction {
this._scroll = transform.boolean(value);
}

get useScrollParent() {
return this._useScrollParent || false;
}

set useScrollParent(value) {
this._useScrollParent = transform.boolean(value);
}

/**
Whether to constrain the draggable element to its container viewport.

Expand All @@ -414,7 +430,8 @@ class DragAction {
}

// Container
this._container = getViewContainer(this._dragElement) || document.body;
const viewContainer = getViewContainer(this._dragElement) || document.body;
this._container = this.useScrollParent ? getScrollParent(this._dragElement) || viewContainer : viewContainer;

// Prevent dragging ghost image
if (event.target.tagName === 'IMG') {
Expand Down
Loading