-
Notifications
You must be signed in to change notification settings - Fork 902
feat(Tree): expose $el
for drag and drop example
#5239
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
base: v4
Are you sure you want to change the base?
Conversation
@J-Michalek We still need to implement some logic even with the newest |
commit: |
$el
for drag and drop example$el
for drag and drop example
I think this is great! I am just wondering if we could somehow take it a step further and find a good way to expose the element of each tree item - it is necessary for some other DnD solutions for example I like to use https://atlassian.design/components/pragmatic-drag-and-drop/about but it requires access to the individual elements, not just the wrapping element like SortableJS does. My first thought would be to add ref property on the item, then you could do something like the following: {
label: 'app/',
ref: (el: HTMLElement | null) => {
if (el == null) {
// handle cleanup
} else {
// init draggable
}
}
} that still requires extra work, because you would usually need to keep the cleanup somewhere to be accessed later so something like this perhaps: function createItemDndFn() {
let cleanup: (() => void) | undefined
return (el: HTMLElement | null) => {
cleanup?.()
if (el) {
cleanup = draggable(el)
}
}
}
{
label: 'app/',
ref: createItemDndFn()
} just thinking out loud here, I feel like exposing nested elements is always such a hussle... but this would be usable in my eyes, but we would need to make sure to document it properly as not everyone might think of the correct usage. |
Maybe we could expose the items refs but we haven't done that in any component π¬ I'd like to improve the current behavior to support moving in directories but not sure how to achieve this in a simple way. |
Perhaps we can try it out maybe in a different PR, see if it makes sense. I could prepare an example using the pragmatic DnD to see the usage in practice.
Not sure how to easily achieve that without access to the item elements tbh. I had to implement a directory structure using SortableJS in the past and it was tough and I had to hack it in ways you should not... |
Reka UI has a demo with |
π Linked issue
Resolves #4508
β Type of change
π Description
π Checklist