Skip to content

Commit 065ee99

Browse files
authored
fix: search modal unexpectedly activated by input-like elements (#1502)
* 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.
1 parent fad80da commit 065ee99

File tree

1 file changed

+6
-1
lines changed
  • src/client/theme-default/slots/SearchBar

1 file changed

+6
-1
lines changed

src/client/theme-default/slots/SearchBar/index.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ const isAppleDevice = /(mac|iphone|ipod|ipad)/i.test(
1414
typeof navigator !== 'undefined' ? navigator?.platform : '',
1515
);
1616

17+
/** Determine if the element that triggered the event is an input element */
18+
const isInput = (target: HTMLElement) =>
19+
['TEXTAREA', 'INPUT'].includes(target.tagName) ||
20+
target.contentEditable === 'true';
21+
1722
const SearchBar: FC = () => {
1823
const [focusing, setFocusing] = useState(false);
1924
const inputRef = useRef<HTMLInputElement>(null);
@@ -32,7 +37,7 @@ const SearchBar: FC = () => {
3237
const handler = (ev: KeyboardEvent) => {
3338
if (
3439
((isAppleDevice ? ev.metaKey : ev.ctrlKey) && ev.key === 'k') ||
35-
ev.key === '/'
40+
(ev.key === '/' && !isInput(ev.target as HTMLElement))
3641
) {
3742
ev.preventDefault();
3843

0 commit comments

Comments
 (0)