summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiDeoo2024-03-20 11:13:16 +0100
committerGitHub2024-03-20 11:13:16 +0100
commit13ed30cd335798177dfe24a27851d2c14d2fe80a (patch)
treef4d95d18fc1f3374f23c17e684d1b5759d44bd49
parent68ff7aeb24c9a9e48dfb22ce3aef6b94f48fde50 (diff)
downloadIT.starlight-13ed30cd335798177dfe24a27851d2c14d2fe80a.tar.gz
IT.starlight-13ed30cd335798177dfe24a27851d2c14d2fe80a.tar.bz2
IT.starlight-13ed30cd335798177dfe24a27851d2c14d2fe80a.zip
Support toggling the built-in search modal using `Ctrl+k` (#1596)
* feat: add `ctrl+k` support for toggling the search modal * chore: update to `patch` --------- Co-authored-by: Chris Swithinbank <swithinbank@gmail.com>
-rw-r--r--.changeset/happy-eggs-switch.md5
-rw-r--r--packages/starlight/components/Search.astro4
2 files changed, 7 insertions, 2 deletions
diff --git a/.changeset/happy-eggs-switch.md b/.changeset/happy-eggs-switch.md
new file mode 100644
index 00000000..0a16166b
--- /dev/null
+++ b/.changeset/happy-eggs-switch.md
@@ -0,0 +1,5 @@
+---
+'@astrojs/starlight': patch
+---
+
+Adds support for toggling the built-in search modal using the `Ctrl+k` keyboard shortcut.
diff --git a/packages/starlight/components/Search.astro b/packages/starlight/components/Search.astro
index ec53fc3e..a565ef42 100644
--- a/packages/starlight/components/Search.astro
+++ b/packages/starlight/components/Search.astro
@@ -96,13 +96,13 @@ const pagefindTranslations = {
window.removeEventListener('click', onClick);
});
- // Listen for `/` and `cmd + k` keyboard shortcuts.
+ // Listen for `/`, `ctrl + k`, and `cmd + k` keyboard shortcuts.
window.addEventListener('keydown', (e) => {
const isInput =
document.activeElement instanceof HTMLElement &&
(['input', 'select', 'textarea'].includes(document.activeElement.tagName.toLowerCase()) ||
document.activeElement.isContentEditable);
- if (e.metaKey === true && e.key === 'k') {
+ if ((e.metaKey === true || e.ctrlKey === true) && e.key === 'k') {
dialog.open ? closeModal() : openModal();
e.preventDefault();
} else if (e.key === '/' && !dialog.open && !isInput) {