fix search dialog opening multiple times via the keybind
Took 5 minutes
This commit is contained in:
parent
83ea83bd18
commit
fe56169874
@ -30,7 +30,7 @@ const Navbar = (): ReactElement => {
|
|||||||
<div className="flex gap-5 sm:gap-7 items-center transition-all transform-gpu">
|
<div className="flex gap-5 sm:gap-7 items-center transition-all transform-gpu">
|
||||||
{/* Search */}
|
{/* Search */}
|
||||||
<div className="hidden xs:flex">
|
<div className="hidden xs:flex">
|
||||||
<QuickSearchDialog pages={pages} />
|
<QuickSearchDialog pages={pages} bindKeybind />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Social */}
|
{/* Social */}
|
||||||
|
@ -21,14 +21,19 @@ import { AppRouterInstance } from "next/dist/shared/lib/app-router-context.share
|
|||||||
*/
|
*/
|
||||||
const QuickSearchDialog = ({
|
const QuickSearchDialog = ({
|
||||||
pages,
|
pages,
|
||||||
|
bindKeybind = false,
|
||||||
}: {
|
}: {
|
||||||
pages: DocsContentMetadata[];
|
pages: DocsContentMetadata[];
|
||||||
|
bindKeybind?: boolean;
|
||||||
}): ReactElement => {
|
}): ReactElement => {
|
||||||
const [open, setOpen] = useState<boolean>(false);
|
const [open, setOpen] = useState<boolean>(false);
|
||||||
const router: AppRouterInstance = useRouter();
|
const router: AppRouterInstance = useRouter();
|
||||||
|
|
||||||
// Listen for CTRL + K keybinds to open this dialog
|
// Listen for CTRL + K keybinds to open this dialog
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (!bindKeybind) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const handleKeyDown = (event: KeyboardEvent): void => {
|
const handleKeyDown = (event: KeyboardEvent): void => {
|
||||||
if ((event.ctrlKey || event.metaKey) && event.key === "k") {
|
if ((event.ctrlKey || event.metaKey) && event.key === "k") {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user