Skip to content

Commit

Permalink
fix: search modal unexpectedly activated by input-like elements (#1502)
Browse files Browse the repository at this point in the history
* chore: debug

* fix: fix the bug that the search shortcut key causes the input box to be out of focus

* Revert "chore: debug"

This reverts commit 734cd24.
  • Loading branch information
Wxh16144 authored Feb 23, 2023
1 parent fad80da commit 065ee99
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/client/theme-default/slots/SearchBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ const isAppleDevice = /(mac|iphone|ipod|ipad)/i.test(
typeof navigator !== 'undefined' ? navigator?.platform : '',
);

/** Determine if the element that triggered the event is an input element */
const isInput = (target: HTMLElement) =>
['TEXTAREA', 'INPUT'].includes(target.tagName) ||
target.contentEditable === 'true';

const SearchBar: FC = () => {
const [focusing, setFocusing] = useState(false);
const inputRef = useRef<HTMLInputElement>(null);
Expand All @@ -32,7 +37,7 @@ const SearchBar: FC = () => {
const handler = (ev: KeyboardEvent) => {
if (
((isAppleDevice ? ev.metaKey : ev.ctrlKey) && ev.key === 'k') ||
ev.key === '/'
(ev.key === '/' && !isInput(ev.target as HTMLElement))
) {
ev.preventDefault();

Expand Down

0 comments on commit 065ee99

Please sign in to comment.