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(value-list, sortable-list): fix nested sorting components #6983
Conversation
…nents into dris0000/sortable-fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking good! 😎 I think we could iterate on it to make the utils more seamless (i.e., unify observing and sorting steps, if possible).
this.cleanUpDragAndDrop(); | ||
this.items = Array.from(this.el.children); | ||
this.setUpDragAndDrop(); | ||
this.setUpSorting(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setUpSorting
handles the preceding logic already.
this.items = Array.from(this.el.children); | ||
this.setUpDragAndDrop(); | ||
connectSortableComponent(this); | ||
this.setUpSorting(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setUpSorting
handles the preceding logic already.
@@ -166,15 +173,16 @@ export class SortableList implements InteractiveComponent { | |||
this.items = Array.from(this.el.children); | |||
|
|||
handle.activated = true; | |||
handle.setFocus(); | |||
focusElement(handle); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
calls setFocus
if applicable to the handle.
this.mutationObserver?.disconnect(); | ||
this.cleanUpDragAndDrop(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
disconnectSortableComponent
handles this already.
@@ -220,7 +235,6 @@ export class ValueList< | |||
|
|||
componentDidLoad(): void { | |||
setComponentLoaded(this); | |||
this.setUpDragAndDrop(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is better handled in connectedCallback
since componentDidLoad
is only called once. If a component is removed then the sortable will be destroyed in disconnectedCallback
so this is needed here.
requestAnimationFrame(() => focusElement(handle)); | ||
|
||
if ("activated" in handle) { | ||
handle.activated = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since handleSelector can be anything we need to do this check. Maybe we shouldn't support a handleSelector if we want to maintain drag consistency thoughout components and require use of a calcite-handle.
|
||
const handle = event | ||
.composedPath() | ||
.find((el: HTMLElement) => el.matches(this.handleSelector)) as HTMLElement; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to find the handle in the composedPath. This was broken.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤏🤏🤏🤏🤏🤏🤏🤏🤏🤏🤏🤏🤏🤏🤏🤏🤏🤏🤏🤏🤏🤏🤏🤏🤏🤏🤏🤏
🤏🔃🤏🤏🤏🔃🤏🤏🔃🔃🤏🤏🔃🔃🔃🤏🤏🔃🔃🔃🤏🔃🔃🔃🔃🤏🔃🤏
🤏🔃🔃🤏🤏🔃🤏🔃🤏🤏🔃🤏🤏🔃🤏🤏🔃🤏🤏🤏🤏🔃🤏🤏🤏🤏🔃🤏
🤏🔃🤏🔃🤏🔃🤏🔃🤏🤏🔃🤏🤏🔃🤏🤏🔃🤏🤏🤏🤏🔃🔃🔃🤏🤏🔃🤏
🤏🔃🤏🤏🔃🔃🤏🔃🤏🤏🔃🤏🤏🔃🤏🤏🔃🤏🤏🤏🤏🔃🤏🤏🤏🤏🤏🤏
🤏🔃🤏🤏🤏🔃🤏🤏🔃🔃🤏🤏🔃🔃🔃🤏🤏🔃🔃🔃🤏🔃🔃🔃🔃🤏🔃🤏
🤏🤏🤏🤏🤏🤏🤏🤏🤏🤏🤏🤏🤏🤏🤏🤏🤏🤏🤏🤏🤏🤏🤏🤏🤏🤏🤏🤏
@@ -313,31 +327,34 @@ export class ValueList< | |||
this.filteredItems = filteredItems; | |||
}; | |||
|
|||
setUpDragAndDrop(): void { | |||
this.cleanUpDragAndDrop(); | |||
setUpSorting(): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this be something we need defined in the interface as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be but it doesn't need to be. I left it out for now since it wouldn't do anything by being added to the interface.
Related Issue: #6024
Summary
The main problem is:
Sortable
instance onconnectedCallback
and destroySortable
ondisconnectedCallback
.Sortable
component with anotherSortable
component inside of it, it triggers the child component'sconnectedCallback
/disconnectedCallback
methods which initialize/destroy aSortable
. This causes JS errors and UI problems.connectedCallback
/disconnectedCallback
from doing anything with the inactiveSortable
instances. (not destroy them & recreate them).Solution:
SortableComponent
components to follow.