From d65667b8d49a11fccee6bc0cd06a75333a65f22c Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Thu, 14 Jul 2022 18:21:46 +0530 Subject: [PATCH] fix(theme): prevent docsearch button key from changing (#986) --- .../components/VPNavBarSearch.vue | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/client/theme-default/components/VPNavBarSearch.vue b/src/client/theme-default/components/VPNavBarSearch.vue index 58e2c81f..e2907549 100644 --- a/src/client/theme-default/components/VPNavBarSearch.vue +++ b/src/client/theme-default/components/VPNavBarSearch.vue @@ -14,7 +14,7 @@ const { theme } = useData() // hit the hotkey to invoke it. const loaded = ref(false) -const metaKey = ref() +const metaKey = ref(`'Meta'`) onMounted(() => { if (!theme.value.algolia) { @@ -22,9 +22,9 @@ onMounted(() => { } // meta key detect (same logic as in @docsearch/js) - metaKey.value.textContent = /(Mac|iPhone|iPod|iPad)/i.test(navigator.platform) - ? '⌘' - : 'Ctrl' + metaKey.value = /(Mac|iPhone|iPod|iPad)/i.test(navigator.platform) + ? `'⌘'` + : `'Ctrl'` const handleSearchHotKey = (e: KeyboardEvent) => { if (e.key === 'k' && (e.ctrlKey || e.metaKey)) { @@ -79,7 +79,7 @@ function load() { {{ theme.algolia?.buttonText || 'Search' }} - Meta + K @@ -255,6 +255,23 @@ function load() { padding-right: 6px; } +.DocSearch-Button .DocSearch-Button-Key:first-child { + font-size: 1px; + letter-spacing: -1px; + color: transparent; +} + +.DocSearch-Button .DocSearch-Button-Key:first-child:after { + content: v-bind(metaKey); + font-size: 12px; + letter-spacing: normal; + color: var(--docsearch-muted-color); +} + +.DocSearch-Button .DocSearch-Button-Key:first-child > * { + display: none; +} + .dark .DocSearch-Footer { border-top: 1px solid var(--vp-c-divider); }