Skip to content

Commit 32c558d

Browse files
committed
core: fix renaming input cancel and not receiving keys from hotkeys
1 parent 66e4ecc commit 32c558d

File tree

5 files changed

+16
-5
lines changed

5 files changed

+16
-5
lines changed

.prettierignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ packages/*/lib
33
packages/*/node_modules
44
storybook-static
55
packages/docs/.docusaurus
6-
packages/docs/build
6+
packages/docs/build
7+
lerna.json

lerna.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
{
2-
"packages": [
3-
"packages/*"
4-
],
2+
"packages": ["packages/*"],
53
"npmClient": "yarn",
64
"useWorkspaces": true,
75
"version": "0.2.1"

packages/core/src/hotkeys/useHotkey.ts

+11
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,16 @@ import { KeyboardBindings } from '../types';
44
import { defaultKeyboardBindings } from './defaultKeyboardBindings';
55
import { useTreeEnvironment } from '../controlledEnvironment/ControlledTreeEnvironment';
66

7+
const elementsThatCanTakeText = [
8+
'input',
9+
'textarea'
10+
]
11+
712
export const useHotkey = (
813
combinationName: keyof KeyboardBindings,
914
onHit: (e: KeyboardEvent) => void,
1015
active?: boolean,
16+
activatableWhileFocusingInput = false,
1117
deps?: any[]
1218
) => {
1319
const environment = useTreeEnvironment();
@@ -28,6 +34,11 @@ export const useHotkey = (
2834
return;
2935
}
3036

37+
if ((elementsThatCanTakeText.includes((e.target as HTMLElement).tagName.toLowerCase())
38+
|| (e.target as HTMLElement).isContentEditable) && !activatableWhileFocusingInput) {
39+
return;
40+
}
41+
3142
if (!pressedKeys.current.includes(e.key)) {
3243
pressedKeys.current.push(e.key);
3344
const pressedKeysLowercase = pressedKeys.current.map(key => key.toLowerCase());

packages/core/src/search/SearchInput.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export const SearchInput: React.FC<{
3838
});
3939
},
4040
isActiveTree && search !== null,
41+
true,
4142
[search, isActiveTree]
4243
);
4344

packages/core/src/treeItem/TreeItemRenamingInput.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const TreeItemRenamingInput: React.FC<{
4040

4141
useHotkey('abortRenameItem', () => {
4242
abort();
43-
});
43+
}, true, true);
4444

4545
const inputProps: InputHTMLAttributes<HTMLInputElement> = {
4646
value: title,

0 commit comments

Comments
 (0)