Skip to content

Commit

Permalink
fix(theme): prevent layout shift in search button key (#2889)
Browse files Browse the repository at this point in the history
  • Loading branch information
brc-dd committed Aug 31, 2023
1 parent 18adc07 commit 0088434
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 23 deletions.
2 changes: 1 addition & 1 deletion docs/package.json
Expand Up @@ -3,7 +3,7 @@
"private": true,
"type": "module",
"scripts": {
"dev": "vitepress",
"dev": "vitepress dev",
"build": "vitepress build",
"preview": "vitepress preview"
},
Expand Down
2 changes: 1 addition & 1 deletion src/client/theme-default/components/VPDocAsideOutline.vue
Expand Up @@ -34,7 +34,7 @@ useActiveAnchor(container, marker)
<div class="content">
<div class="outline-marker" ref="marker" />

<div class="outline-title" role="heading">{{ resolveTitle(theme) }}</div>
<div class="outline-title" role="heading" aria-level="2">{{ resolveTitle(theme) }}</div>

<nav aria-labelledby="doc-outline-aria-label">
<span class="visually-hidden" id="doc-outline-aria-label">
Expand Down
11 changes: 1 addition & 10 deletions src/client/theme-default/components/VPNavBarSearch.vue
Expand Up @@ -137,20 +137,11 @@ if (__VP_LOCAL_SEARCH__) {
})
}
const metaKey = ref(`'Meta'`)
onMounted(() => {
// meta key detect (same logic as in @docsearch/js)
metaKey.value = /(Mac|iPhone|iPod|iPad)/i.test(navigator.platform)
? `'⌘'`
: `'Ctrl'`
})
const provider = __ALGOLIA__ ? 'algolia' : __VP_LOCAL_SEARCH__ ? 'local' : ''
</script>

<template>
<div class="VPNavBarSearch" :style="{ '--vp-meta-key': metaKey }">
<div class="VPNavBarSearch">
<template v-if="provider === 'local'">
<VPLocalSearchBox
v-if="showSearch"
Expand Down
6 changes: 5 additions & 1 deletion src/client/theme-default/components/VPNavBarSearchButton.vue
Expand Up @@ -194,12 +194,16 @@ defineProps<{
}
.DocSearch-Button .DocSearch-Button-Key:first-child:after {
content: var(--vp-meta-key);
content: 'Ctrl';
font-size: 12px;
letter-spacing: normal;
color: var(--docsearch-muted-color);
}
.mac .DocSearch-Button .DocSearch-Button-Key:first-child:after {
content: '\2318';
}
.DocSearch-Button .DocSearch-Button-Key:first-child > * {
display: none;
}
Expand Down
24 changes: 14 additions & 10 deletions src/node/config.ts
Expand Up @@ -255,19 +255,23 @@ function resolveSiteDataHead(userConfig?: UserConfig): HeadConfig[] {
? userConfig.appearance.initialValue ?? 'auto'
: 'auto'

head.push([
'script',
{ id: 'check-dark-light' },
`
;(() => {
head.push(
[
'script',
{ id: 'check-dark-light' },
`;(() => {
const preference = localStorage.getItem('${APPEARANCE_KEY}') || '${fallbackPreference}'
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches
if (!preference || preference === 'auto' ? prefersDark : preference === 'dark') {
if (!preference || preference === 'auto' ? prefersDark : preference === 'dark')
document.documentElement.classList.add('dark')
}
})()
`
])
})()`
],
[
'script',
{ id: 'check-mac-os' },
`document.documentElement.classList.toggle('mac', /Mac|iPhone|iPod|iPad/i.test(navigator.platform))`
]
)
}

return head
Expand Down

0 comments on commit 0088434

Please sign in to comment.