Skip to content

Commit

Permalink
fix: DirectoryTree keyboard error (ant-design#32551)
Browse files Browse the repository at this point in the history
* Fix bug in keyboard navigation

When selecting a node using the keyboard (spacebar), the event received by onSelect has an undefined MouseEvent. Keyboard navigation was not possible because an error was thrown when trying to access properties from the undefined nativeEvent. We are now testing if nativeEvent is defined before accessing its properties.

* fix: DirectoryTree throws error during keyboard navigation
  • Loading branch information
D-to-the-K authored Oct 19, 2021
1 parent 413d979 commit 0a8065e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions components/tree/DirectoryTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ const DirectoryTree: React.ForwardRefRenderFunction<RcTree, DirectoryTreeProps>
};

// Windows / Mac single pick
const ctrlPick: boolean = nativeEvent.ctrlKey || nativeEvent.metaKey;
const shiftPick: boolean = nativeEvent.shiftKey;
const ctrlPick: boolean = nativeEvent?.ctrlKey || nativeEvent?.metaKey;
const shiftPick: boolean = nativeEvent?.shiftKey;

// Generate new selected keys
let newSelectedKeys: Key[];
Expand Down

0 comments on commit 0a8065e

Please sign in to comment.