Skip to content

Commit fec384b

Browse files
committed
Add keyboard shortcut for focusing on sidebar search
1 parent 3b8336d commit fec384b

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/components/overrides/Sidebar.astro

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,30 @@ const [product, module] = Astro.url.pathname.split("/").filter(Boolean);
255255
}
256256
}
257257
});
258+
259+
document.addEventListener(
260+
"keydown",
261+
(keyboardEvent) => {
262+
const target = keyboardEvent.target;
263+
264+
const isInput =
265+
target instanceof EventTarget &&
266+
(("tagName" in target &&
267+
(target.tagName === "INPUT" ||
268+
target.tagName === "TEXTAREA" ||
269+
target.tagName === "SELECT")) ||
270+
("isContentEditable" in target && target.isContentEditable));
271+
272+
if (keyboardEvent.key === "/" && !isInput) {
273+
keyboardEvent.preventDefault();
274+
keyboardEvent.stopPropagation();
275+
searchInput.focus();
276+
}
277+
},
278+
{
279+
capture: true,
280+
},
281+
);
258282
}
259283

260284
// Initialize when DOM is loaded

0 commit comments

Comments
 (0)