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

[TreeView] Fix drag and drop issue with label editing #15636

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

noraleonte
Copy link
Contributor

closes #15533

@noraleonte noraleonte added bug 🐛 Something doesn't work component: tree view TreeView, TreeItem. This is the name of the generic UI component, not the React module! labels Nov 27, 2024
@noraleonte noraleonte self-assigned this Nov 27, 2024
@mui-bot
Copy link

mui-bot commented Nov 27, 2024

Deploy preview: https://deploy-preview-15636--material-ui-x.netlify.app/

Generated by 🚫 dangerJS against dd339ee

Copy link
Member

@flaviendelangle flaviendelangle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll check the behavior later 🙏

@@ -34,6 +36,9 @@ export const useTreeViewItemsReorderingItemPlugin: TreeViewItemPlugin = ({ props
itemId,
);
const isValidTarget = useSelector(store, selectorItemsReorderingIsValidTarget, itemId);
const draggedItemId = useSelector(store, selectorDraggedItem);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will cause every item to re-render everytime draggedItemId changes.

You could create a selectorIsDraggedItemBeingEdited, but same you will still re-render every item everytime you start dragging your edited item.

Could you instead prevent putting in the state an item that is being edited in the first place?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't seem to solve the problem. The best thing I could think of is to disable dragging when editing is enabled on any item. WDYT?


const isBeingEdited = useSelector(store, selectorIsItemBeingEdited, draggedItemId);
const isEditing = useSelector(store, selectorIsAnItemEdited);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will re-render all the items when starting editing.
In term of perfs, I think the best trade-off would be:

  1. Use !!isItemEditable instead of isEditing on line 54 (if the label editing is not configured at all then we don't create the callbacks

  2. Use the selector to know if an item is being edited inside handleDragStart, handleRootDragOver and handleRootDragEnd

The only diff is that draggable would be true even when editing an item, not sure if thats a problem.
If it is, then I don't have a great solution to avoid the full re-render 😬

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: tree view TreeView, TreeItem. This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[tree view] Can't move RichTreeView editable label input caret when itemsReordering is enabled (Firefox)
3 participants