Skip to content

Commit 0088434

Browse files
authoredAug 31, 2023
fix(theme): prevent layout shift in search button key (#2889)
1 parent 18adc07 commit 0088434

File tree

5 files changed

+22
-23
lines changed

5 files changed

+22
-23
lines changed
 

‎docs/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"private": true,
44
"type": "module",
55
"scripts": {
6-
"dev": "vitepress",
6+
"dev": "vitepress dev",
77
"build": "vitepress build",
88
"preview": "vitepress preview"
99
},

‎src/client/theme-default/components/VPDocAsideOutline.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ useActiveAnchor(container, marker)
3434
<div class="content">
3535
<div class="outline-marker" ref="marker" />
3636

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

3939
<nav aria-labelledby="doc-outline-aria-label">
4040
<span class="visually-hidden" id="doc-outline-aria-label">

‎src/client/theme-default/components/VPNavBarSearch.vue

+1-10
Original file line numberDiff line numberDiff line change
@@ -137,20 +137,11 @@ if (__VP_LOCAL_SEARCH__) {
137137
})
138138
}
139139
140-
const metaKey = ref(`'Meta'`)
141-
142-
onMounted(() => {
143-
// meta key detect (same logic as in @docsearch/js)
144-
metaKey.value = /(Mac|iPhone|iPod|iPad)/i.test(navigator.platform)
145-
? `'⌘'`
146-
: `'Ctrl'`
147-
})
148-
149140
const provider = __ALGOLIA__ ? 'algolia' : __VP_LOCAL_SEARCH__ ? 'local' : ''
150141
</script>
151142

152143
<template>
153-
<div class="VPNavBarSearch" :style="{ '--vp-meta-key': metaKey }">
144+
<div class="VPNavBarSearch">
154145
<template v-if="provider === 'local'">
155146
<VPLocalSearchBox
156147
v-if="showSearch"

‎src/client/theme-default/components/VPNavBarSearchButton.vue

+5-1
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,16 @@ defineProps<{
194194
}
195195
196196
.DocSearch-Button .DocSearch-Button-Key:first-child:after {
197-
content: var(--vp-meta-key);
197+
content: 'Ctrl';
198198
font-size: 12px;
199199
letter-spacing: normal;
200200
color: var(--docsearch-muted-color);
201201
}
202202
203+
.mac .DocSearch-Button .DocSearch-Button-Key:first-child:after {
204+
content: '\2318';
205+
}
206+
203207
.DocSearch-Button .DocSearch-Button-Key:first-child > * {
204208
display: none;
205209
}

‎src/node/config.ts

+14-10
Original file line numberDiff line numberDiff line change
@@ -255,19 +255,23 @@ function resolveSiteDataHead(userConfig?: UserConfig): HeadConfig[] {
255255
? userConfig.appearance.initialValue ?? 'auto'
256256
: 'auto'
257257

258-
head.push([
259-
'script',
260-
{ id: 'check-dark-light' },
261-
`
262-
;(() => {
258+
head.push(
259+
[
260+
'script',
261+
{ id: 'check-dark-light' },
262+
`;(() => {
263263
const preference = localStorage.getItem('${APPEARANCE_KEY}') || '${fallbackPreference}'
264264
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches
265-
if (!preference || preference === 'auto' ? prefersDark : preference === 'dark') {
265+
if (!preference || preference === 'auto' ? prefersDark : preference === 'dark')
266266
document.documentElement.classList.add('dark')
267-
}
268-
})()
269-
`
270-
])
267+
})()`
268+
],
269+
[
270+
'script',
271+
{ id: 'check-mac-os' },
272+
`document.documentElement.classList.toggle('mac', /Mac|iPhone|iPod|iPad/i.test(navigator.platform))`
273+
]
274+
)
271275
}
272276

273277
return head

0 commit comments

Comments
 (0)
Please sign in to comment.