Skip to content

Conversation

benjamincanac
Copy link
Member

@benjamincanac benjamincanac commented Oct 15, 2025

πŸ”— Linked issue

Resolves #4508

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@github-actions github-actions bot added the v4 #4488 label Oct 15, 2025
@benjamincanac
Copy link
Member Author

@J-Michalek We still need to implement some logic even with the newest nested prop as the items prop isn't. What do you think of the implementation?

Copy link

pkg-pr-new bot commented Oct 15, 2025

npm i https://pkg.pr.new/@nuxt/ui@5239

commit: 6664049

@benjamincanac benjamincanac changed the title fix(Tree): expose $el for drag and drop example feat(Tree): expose $el for drag and drop example Oct 15, 2025
@J-Michalek
Copy link
Contributor

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.

@benjamincanac
Copy link
Member Author

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.

@J-Michalek
Copy link
Contributor

Maybe we could expose the items refs but we haven't done that in any component 😬

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.

I'd like to improve the current behavior to support moving in directories but not sure how to achieve this in a simple way.

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...

Copy link
Member Author

Reka UI has a demo with @atlaskit/pragmatic-drag-and-drop but it requires a lot of code πŸ˜… https://stackblitz.com/edit/github-8f3fzs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v4 #4488

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UTree: drag-and-drop

2 participants