Skip to content

Commit

Permalink
Fix: Prevent browser default browser behaviour on Ctrl + K keybind to…
Browse files Browse the repository at this point in the history
… open Search Box (#850)
  • Loading branch information
raflymln authored Aug 21, 2024
1 parent 18d3a74 commit 5f29293
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/ui/searchbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
RegisterSearchButtonProps,
} from "@orama/searchbox/dist/index.js";
import { OramaClient } from "@oramacloud/client";
import { createEffect } from "solid-js";
import { createEffect, onCleanup, onMount } from "solid-js";
import { useThemeContext } from "~/data/theme-provider";
import "@orama/searchbox/dist/index.css";

Expand All @@ -20,6 +20,24 @@ export function SearchBox() {
const selectedTheme = ctx.selectedTheme;

if (!isServer) {
const onSearchBoxOpen = (e: Event) => {
/**
* These will prevent the default behavior of the browser
* when the user presses Ctrl + K.
*/
if (e instanceof KeyboardEvent && e.ctrlKey && e.key === "k") {
e.preventDefault();
}
};

onMount(() => {
window.addEventListener("keydown", onSearchBoxOpen);
});

onCleanup(() => {
window.removeEventListener("keydown", onSearchBoxOpen);
});

createEffect(() => {
/**
* These function calls create/register web components like
Expand Down

0 comments on commit 5f29293

Please sign in to comment.