Skip to content

Commit 5da70a9

Browse files
committed
feat: introduce disableArrowKeys flag (#362)
1 parent b5f06fc commit 5da70a9

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

packages/core/src/stories/Accessibility.stories.tsx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,39 @@ export const NoDescriptors = () => (
142142
<Tree treeId="tree-1" rootItem="root" treeLabel="Tree Example" />
143143
</UncontrolledTreeEnvironment>
144144
);
145+
146+
export const NoKeyboardBindings = () => (
147+
<UncontrolledTreeEnvironment<string>
148+
canDragAndDrop
149+
canDropOnFolder
150+
canReorderItems
151+
dataProvider={
152+
new StaticTreeDataProvider(longTree.items, (item, data) => ({
153+
...item,
154+
data,
155+
}))
156+
}
157+
getItemTitle={item => item.data}
158+
viewState={{
159+
'tree-1': {},
160+
}}
161+
keyboardBindings={{
162+
primaryAction: [],
163+
moveFocusToFirstItem: [],
164+
moveFocusToLastItem: [],
165+
expandSiblings: [],
166+
renameItem: [],
167+
abortRenameItem: [],
168+
toggleSelectItem: [],
169+
abortSearch: [],
170+
startSearch: [],
171+
selectAll: [],
172+
startProgrammaticDnd: [],
173+
abortProgrammaticDnd: [],
174+
completeProgrammaticDnd: [],
175+
}}
176+
disableArrowKeys
177+
>
178+
<Tree treeId="tree-1" rootItem="root" treeLabel="Tree Example" />
179+
</UncontrolledTreeEnvironment>
180+
);

packages/core/src/tree/useTreeKeyboardBindings.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export const useTreeKeyboardBindings = () => {
1919

2020
const isActiveTree = environment.activeTreeId === treeId;
2121
const isRenaming = !!renamingItem;
22+
const { disableArrowKeys } = environment;
23+
const enableArrowKeys = !disableArrowKeys && isActiveTree && !isRenaming;
2224

2325
useKey(
2426
'arrowdown',
@@ -34,7 +36,7 @@ export const useTreeKeyboardBindings = () => {
3436
}
3537
}
3638
},
37-
isActiveTree && !isRenaming
39+
enableArrowKeys
3840
);
3941

4042
useKey(
@@ -51,7 +53,7 @@ export const useTreeKeyboardBindings = () => {
5153
}
5254
}
5355
},
54-
isActiveTree && !isRenaming
56+
enableArrowKeys
5557
);
5658

5759
useHotkey(
@@ -87,7 +89,7 @@ export const useTreeKeyboardBindings = () => {
8789
return currentIndex;
8890
});
8991
},
90-
isActiveTree && !dnd.isProgrammaticallyDragging && !isRenaming
92+
enableArrowKeys && !dnd.isProgrammaticallyDragging
9193
);
9294

9395
useKey(
@@ -111,7 +113,7 @@ export const useTreeKeyboardBindings = () => {
111113
return currentIndex;
112114
});
113115
},
114-
isActiveTree && !dnd.isProgrammaticallyDragging && !isRenaming
116+
enableArrowKeys && !dnd.isProgrammaticallyDragging
115117
);
116118

117119
useHotkey(

packages/core/src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ export interface TreeCapabilities<T = any, C extends string = never> {
193193
* at the top.
194194
*/
195195
canDropBelowOpenFolders?: boolean;
196+
197+
disableArrowKeys?: boolean;
196198
}
197199

198200
export type IndividualTreeViewState<C extends string = never> = {

0 commit comments

Comments
 (0)