Skip to content

Commit

Permalink
fix: respect canRename property in item payload
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasbach committed Nov 30, 2023
1 parent bbdbfe4 commit 1789408
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
5 changes: 4 additions & 1 deletion next-release-notes.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
### Breaking Changes
- Changed the behavior for dropping an item at the bottom of an open folder has changed, and will now drop
into the open folder at its top, instead of the parent folder below the open folder. See discussion at #148 for details.
You can opt out of this behavior by setting the `canDropBelowOpenFolders` prop on the tree environment (#148).
You can opt out of this behavior by setting the `canDropBelowOpenFolders` prop on the tree environment (#148).

### Bug Fixes
- Fixed a bug where the `canRename` property in a tree item payload was not respected.
17 changes: 12 additions & 5 deletions packages/core/src/tree/useTreeKeyboardBindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,19 @@ export const useTreeKeyboardBindings = () => {
useHotkey(
'renameItem',
e => {
if (viewState.focusedItem !== undefined) {
e.preventDefault();
const item = environment.items[viewState.focusedItem];
environment.onStartRenamingItem?.(item, treeId);
setRenamingItem(item.index);
if (viewState.focusedItem === undefined) {
return;
}

e.preventDefault();
const item = environment.items[viewState.focusedItem];

if (item.canRename === false) {
return;
}

environment.onStartRenamingItem?.(item, treeId);
setRenamingItem(item.index);
},
isActiveTree && (environment.canRename ?? true) && !isRenaming
);
Expand Down

0 comments on commit 1789408

Please sign in to comment.