Skip to content

Commit

Permalink
Correctly detect keyboard input "Enter" (#479)
Browse files Browse the repository at this point in the history
The "code" property returns the physical key that was pressed.
Thus, e.g. "Enter" on the numpad is "NumpadEnter" and not "Enter".
  • Loading branch information
schroda authored Nov 26, 2023
1 parent c6cc7c1 commit ee9811b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/components/reader/pager/DoublePagedPager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export function DoublePagedPager(props: IReaderProps) {
}

function keyboardControl(e: KeyboardEvent) {
switch (e.code) {
switch (e.key) {
case 'Space':
e.preventDefault();
nextPage();
Expand Down
2 changes: 1 addition & 1 deletion src/components/reader/pager/PagedPager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export function PagedPager(props: IReaderProps) {
}

function keyboardControl(e: KeyboardEvent) {
switch (e.code) {
switch (e.key) {
case 'Space':
e.preventDefault();
nextPage();
Expand Down
2 changes: 1 addition & 1 deletion src/components/reader/pager/VerticalPager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export function VerticalPager(props: IReaderProps) {

useEffect(() => {
const handleKeyboard = (e: KeyboardEvent) => {
switch (e.code) {
switch (e.key) {
case 'Space':
e.preventDefault();
go(e.shiftKey ? 'up' : 'down');
Expand Down
13 changes: 6 additions & 7 deletions src/components/util/AppbarSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};

Expand Down Expand Up @@ -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={
Expand Down

0 comments on commit ee9811b

Please sign in to comment.