mirror of
https://github.com/dnote/dnote
synced 2026-03-18 00:09:56 +01:00
Allow to select books with printable characters while trigger is focused (#262)
This commit is contained in:
parent
97ff614ab9
commit
46384b237a
2 changed files with 14 additions and 0 deletions
|
|
@ -24,3 +24,8 @@ export const KEYCODE_TAB = 9;
|
|||
|
||||
// alphabet
|
||||
export const KEYCODE_LOWERCASE_B = 66;
|
||||
|
||||
// isPrintableKey returns if the key represented in the given event is printable.
|
||||
export function isPrintableKey(e: KeyboardEvent) {
|
||||
return e.key.length === 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import React, { useState, useEffect } from 'react';
|
|||
import classnames from 'classnames';
|
||||
|
||||
import { booksToOptions } from 'jslib/helpers/select';
|
||||
import { isPrintableKey } from 'jslib/helpers/keyboard';
|
||||
import Popover from '../../Popover';
|
||||
import SearchableMenu from '../../SearchableMenu';
|
||||
import BookIcon from '../../../Icons/Book';
|
||||
|
|
@ -117,6 +118,14 @@ const BookSelector: React.SFC<Props> = ({
|
|||
onClick={() => {
|
||||
setIsOpen(!isOpen);
|
||||
}}
|
||||
onKeyDown={e => {
|
||||
if (isPrintableKey(e.nativeEvent)) {
|
||||
e.preventDefault();
|
||||
|
||||
setTextboxValue(e.key);
|
||||
setIsOpen(true);
|
||||
}
|
||||
}}
|
||||
aria-haspopup="menu"
|
||||
aria-expanded={ariaExpanded}
|
||||
aria-controls="book-filter"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue