Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(theme): prevent docsearch button key from changing #986

Merged
merged 1 commit into from
Jul 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions src/client/theme-default/components/VPNavBarSearch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ 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) {
return
}

// 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)) {
Expand Down Expand Up @@ -79,7 +79,7 @@ function load() {
<span class="DocSearch-Button-Placeholder">{{ theme.algolia?.buttonText || 'Search' }}</span>
</span>
<span class="DocSearch-Button-Keys">
<kbd class="DocSearch-Button-Key" ref="metaKey">Meta</kbd>
<kbd class="DocSearch-Button-Key"></kbd>
<kbd class="DocSearch-Button-Key">K</kbd>
</span>
</button>
Expand Down Expand Up @@ -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);
}
Expand Down