diff --git a/packages/toolpad-app/src/components/EditableTreeItem.tsx b/packages/toolpad-app/src/components/EditableTreeItem.tsx index 27e833ee4de..734e76b2310 100644 --- a/packages/toolpad-app/src/components/EditableTreeItem.tsx +++ b/packages/toolpad-app/src/components/EditableTreeItem.tsx @@ -81,11 +81,9 @@ export default function EditableTreeItem({ handleCancel(); return; } - if (onEdit) { onEdit(itemNameInput); } - setItemNameInput(''); setIsInternalEditing(false); }, [handleCancel, itemNameInput, newItemValidationResult.isValid, onEdit]); @@ -96,6 +94,7 @@ export default function EditableTreeItem({ const handleFocus = React.useCallback((event: React.FocusEvent) => { event.target.select(); + event.stopPropagation(); }, []); const handleBlur = React.useCallback( @@ -111,11 +110,11 @@ export default function EditableTreeItem({ const handleKeyDown = React.useCallback( (event: React.KeyboardEvent) => { + event.stopPropagation(); if (event.key === 'Enter') { handleConfirm(); } else if (event.key === 'Escape') { handleCancel(); - event.stopPropagation(); } }, [handleCancel, handleConfirm], diff --git a/packages/toolpad-app/src/toolpad/AppEditor/NodeMenu.tsx b/packages/toolpad-app/src/toolpad/AppEditor/NodeMenu.tsx index 0d081a8a758..a1428579e52 100644 --- a/packages/toolpad-app/src/toolpad/AppEditor/NodeMenu.tsx +++ b/packages/toolpad-app/src/toolpad/AppEditor/NodeMenu.tsx @@ -50,7 +50,6 @@ export default function NodeMenu({ const handleDeleteNodeDialogClose = React.useCallback( (confirmed: boolean, event: React.MouseEvent) => { event.stopPropagation(); - setDeletedNodeId(null); if (confirmed && deletedNode) { onDeleteNode?.(deletedNodeId); @@ -61,8 +60,8 @@ export default function NodeMenu({ const handleRenameClick = React.useCallback( (event: React.MouseEvent) => { - onMenuClose(event); onRenameNode?.(nodeId); + onMenuClose(event); }, [nodeId, onRenameNode, onMenuClose], ); @@ -88,24 +87,30 @@ export default function NodeMenu({ menuProps.onClick?.(event); }} > - - - - - {renameLabelText} - - - - - - {duplicateLabelText} - - - - - - {deleteLabelText} - + {onRenameNode ? ( + + + + + {renameLabelText} + + ) : null} + {onDuplicateNode ? ( + + + + + {duplicateLabelText} + + ) : null} + {onDeleteNode ? ( + + + + + {deleteLabelText} + + ) : null}