Skip to content

Commit

Permalink
Merge pull request #301 from easyops-cn/steve/use-keyboard-key-instea…
Browse files Browse the repository at this point in the history
…d-of-code

fix: use key instead of code for keyboard events
  • Loading branch information
weareoutman authored Nov 28, 2022
2 parents fec72ce + 5e919f4 commit 0d96045
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions docusaurus-search-local/src/client/theme/SearchBar/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,10 @@ export default function SearchBar({
}
// Add shortcuts command/ctrl + K
const handleShortcut = (event: KeyboardEvent): void => {
if ((isMac ? event.metaKey : event.ctrlKey) && event.code === "KeyK") {
if (
(isMac ? event.metaKey : event.ctrlKey) &&
(event.key === "k" || event.key === "K")
) {
event.preventDefault();
searchBarRef.current?.focus();
onInputFocus();
Expand Down Expand Up @@ -381,10 +384,12 @@ export default function SearchBar({
</button>
) : (
<div className={styles.searchHintContainer}>
<kbd className={styles.searchHint}>{isMac ? "⌘" : "ctrl"}</kbd>
<kbd className={styles.searchHint}>K</kbd>
</div>
ExecutionEnvironment.canUseDOM && (
<div className={styles.searchHintContainer}>
<kbd className={styles.searchHint}>{isMac ? "⌘" : "ctrl"}</kbd>
<kbd className={styles.searchHint}>K</kbd>
</div>
)
))}
</div>
);
Expand Down

0 comments on commit 0d96045

Please sign in to comment.