Correctly detect keyboard input "Enter" (#479)

The "code" property returns the physical key that was pressed.
Thus, e.g. "Enter" on the numpad is "NumpadEnter" and not "Enter".
This commit is contained in:
schroda
2023-11-26 14:29:03 +01:00
committed by GitHub
parent c6cc7c14dd
commit ee9811bf53
4 changed files with 9 additions and 10 deletions

View File

@@ -66,15 +66,9 @@ export const AppbarSearch: React.FunctionComponent<IProps> = (props) => {
};
const handleKeyboardEvent = (e: KeyboardEvent) => {
if (e.code === 'F3' || (e.ctrlKey && e.code === 'KeyF')) {
if (e.key === 'F3' || (e.ctrlKey && e.key === 'f')) {
e.preventDefault();
updateSearchOpenState(true);
return;
}
if (e.code === 'Enter') {
e.preventDefault();
handleChange(searchString);
}
};
@@ -131,6 +125,11 @@ export const AppbarSearch: React.FunctionComponent<IProps> = (props) => {
<Input
value={searchString}
onChange={(e) => setSearchString(e.target.value)}
onKeyDown={(e) => {
if (e.key === 'Enter') {
handleChange(searchString);
}
}}
onBlur={handleBlur}
inputRef={inputRef}
endAdornment={