Skip to content

Commit

Permalink
added handleKeyDown
Browse files Browse the repository at this point in the history
  • Loading branch information
coderwelsch committed Nov 7, 2023
1 parent 7743db8 commit d414a5e
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/components/form-field/search-input/search-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ export const SearchInput = ({
}
}, [autoSelect]);

const handleKeyDown = useCallback(
(event: React.KeyboardEvent<HTMLDivElement>) => {
if (event.key === "Enter" || event.key === " ") {
event.preventDefault();
event.stopPropagation();

onClear();
}
},
[onClear]
);

return (
<div className={classNames("relative w-full")}>
<div
Expand Down Expand Up @@ -66,14 +78,7 @@ export const SearchInput = ({
<div
tabIndex={0}
onClick={onClear}
onKeyDown={(e) => {
if (e.key === "Enter" || e.key === " ") {
e.preventDefault();
e.stopPropagation();

onClear();
}
}}
onKeyDown={handleKeyDown}
className="absolute right-0 top-1/2 z-10 mr-1.5 flex h-5 w-5 -translate-y-1/2 transform cursor-pointer items-center justify-center rounded border border-transparent bg-neutral-100 hover:border-neutral-300"
aria-label="Clear Search Input"
role="button"
Expand Down

0 comments on commit d414a5e

Please sign in to comment.