Skip to content

Commit

Permalink
[v4] Don't focus search input on ⌘ + Shift + k or `Ctrl + Shift + k…
Browse files Browse the repository at this point in the history
…`. (shuding#3911)

fix
  • Loading branch information
dimaMachina authored Jan 9, 2025
1 parent 8b08067 commit aca79fa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 8 additions & 0 deletions .changeset/blue-sloths-play.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"nextra": patch
"nextra-theme-blog": patch
"nextra-theme-docs": patch
---

Don't focus search input on `Ctrl + k` on non Mac devices.
Don't focus search input on `⌘ + Shift + k` or `Ctrl + Shift + k`.
5 changes: 3 additions & 2 deletions packages/nextra/src/client/components/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export const Search: FC<SearchProps> = ({
const inputRef = useRef<HTMLInputElement>(null!)

useEffect(() => {
function handleKeyDown(event: globalThis.KeyboardEvent) {
function handleKeyDown(event: KeyboardEvent) {
const el = document.activeElement
if (
!el ||
Expand All @@ -148,7 +148,8 @@ export const Search: FC<SearchProps> = ({
if (
event.key === '/' ||
(event.key === 'k' &&
(event.metaKey /* for Mac */ || /* for non-Mac */ event.ctrlKey))
!event.shiftKey &&
(navigator.userAgent.includes('Mac') ? event.metaKey : event.ctrlKey))
) {
event.preventDefault()
// prevent to scroll to top
Expand Down

0 comments on commit aca79fa

Please sign in to comment.