fix: Escape key in keyboard shortcut guide should clear search input if search term
This commit is contained in:
@ -22,7 +22,9 @@ type Props = {
|
|||||||
collectionId?: string,
|
collectionId?: string,
|
||||||
redirectDisabled?: boolean,
|
redirectDisabled?: boolean,
|
||||||
maxWidth?: string,
|
maxWidth?: string,
|
||||||
|
value: string,
|
||||||
onChange: (event: SyntheticInputEvent<>) => mixed,
|
onChange: (event: SyntheticInputEvent<>) => mixed,
|
||||||
|
onKeyDown: (event: SyntheticKeyboardEvent<>) => mixed,
|
||||||
t: TFunction,
|
t: TFunction,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -59,7 +61,7 @@ class InputSearch extends React.Component<Props> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { t, redirectDisabled, onChange } = this.props;
|
const { t, redirectDisabled, value, onChange, onKeyDown } = this.props;
|
||||||
const { theme, placeholder = `${t("Search")}…` } = this.props;
|
const { theme, placeholder = `${t("Search")}…` } = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -68,7 +70,9 @@ class InputSearch extends React.Component<Props> {
|
|||||||
type="search"
|
type="search"
|
||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
onInput={redirectDisabled ? undefined : this.handleSearchInput}
|
onInput={redirectDisabled ? undefined : this.handleSearchInput}
|
||||||
|
value={value}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
|
onKeyDown={onKeyDown}
|
||||||
icon={
|
icon={
|
||||||
<SearchIcon
|
<SearchIcon
|
||||||
color={this.focused ? theme.inputBorderFocused : theme.inputBorder}
|
color={this.focused ? theme.inputBorderFocused : theme.inputBorder}
|
||||||
|
@ -347,16 +347,30 @@ function KeyboardShortcuts() {
|
|||||||
const [searchTerm, setSearchTerm] = React.useState("");
|
const [searchTerm, setSearchTerm] = React.useState("");
|
||||||
|
|
||||||
const handleChange = React.useCallback((event) => {
|
const handleChange = React.useCallback((event) => {
|
||||||
setSearchTerm(event.target.value.toLowerCase());
|
setSearchTerm(event.target.value);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleKeyDown = React.useCallback((event) => {
|
||||||
|
if (event.target.value && event.key === "Escape") {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
setSearchTerm("");
|
||||||
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Flex column>
|
<Flex column>
|
||||||
<Input type="search" onChange={handleChange} redirectDisabled />
|
<Input
|
||||||
|
type="search"
|
||||||
|
onChange={handleChange}
|
||||||
|
onKeyDown={handleKeyDown}
|
||||||
|
value={searchTerm}
|
||||||
|
redirectDisabled
|
||||||
|
/>
|
||||||
{categories.map((category, x) => {
|
{categories.map((category, x) => {
|
||||||
const filtered = searchTerm
|
const filtered = searchTerm
|
||||||
? category.items.filter((item) =>
|
? category.items.filter((item) =>
|
||||||
item.label.toLowerCase().includes(searchTerm)
|
item.label.toLowerCase().includes(searchTerm.toLowerCase())
|
||||||
)
|
)
|
||||||
: category.items;
|
: category.items;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user