-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
base: master
Are you sure you want to change the base?
Conversation
Deploy preview: https://deploy-preview-15636--material-ui-x.netlify.app/ |
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.
I'll check the behavior later 🙏
...ro/src/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.itemPlugin.ts
Outdated
Show resolved
Hide resolved
...ro/src/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.itemPlugin.ts
Outdated
Show resolved
Hide resolved
...pro/src/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.selectors.ts
Outdated
Show resolved
Hide resolved
...pro/src/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.selectors.ts
Outdated
Show resolved
Hide resolved
@@ -34,6 +36,9 @@ export const useTreeViewItemsReorderingItemPlugin: TreeViewItemPlugin = ({ props | |||
itemId, | |||
); | |||
const isValidTarget = useSelector(store, selectorItemsReorderingIsValidTarget, itemId); | |||
const draggedItemId = useSelector(store, selectorDraggedItem); |
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 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?
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.
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); |
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 will re-render all the items when starting editing.
In term of perfs, I think the best trade-off would be:
-
Use
!!isItemEditable
instead ofisEditing
on line 54 (if the label editing is not configured at all then we don't create the callbacks -
Use the selector to know if an item is being edited inside
handleDragStart
,handleRootDragOver
andhandleRootDragEnd
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 😬
closes #15533