Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Feb 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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))
PeachScript marked this conversation as resolved.
Show resolved Hide resolved
) {
ev.preventDefault();

Expand Down