fix: DirectoryTree keyboard error (#32551)

* 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
This commit is contained in:
D-to-the-K 2021-10-19 02:05:17 -03:00 committed by GitHub
parent 413d979731
commit 0a8065e5bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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[];