Skip to content

Commit 3c0d4a0

Browse files
committed
fix(ui): use prehydrate to prevent kbd hint layout shift
1 parent 69066fe commit 3c0d4a0

4 files changed

Lines changed: 16 additions & 2 deletions

File tree

app/assets/main.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,11 @@ input[type='search']::-webkit-search-results-decoration {
335335
animation-timing-function: cubic-bezier(0.22, 1, 0.36, 1);
336336
}
337337

338+
/* Hide keyboard shortcut hints before hydration when user disabled them */
339+
:root[data-kbd-shortcuts='false'] [data-kbd-hint] {
340+
display: none;
341+
}
342+
338343
/* Locking the scroll whenever any of the modals are open */
339344
html:has(dialog:modal) {
340345
overflow: hidden;

app/components/Button/Base.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const props = withDefaults(
2727
const el = useTemplateRef('el')
2828
2929
const keyboardShortcutsEnabled = useKeyboardShortcuts()
30+
const showKbdHint = computed(() => keyboardShortcutsEnabled.value && !!props.ariaKeyshortcuts)
3031
3132
defineExpose({
3233
focus: () => el.value?.focus(),
@@ -63,7 +64,8 @@ defineExpose({
6364
<span v-if="classicon" class="size-[1em]" :class="classicon" aria-hidden="true" />
6465
<slot />
6566
<kbd
66-
v-if="keyboardShortcutsEnabled && ariaKeyshortcuts"
67+
v-if="showKbdHint"
68+
data-kbd-hint
6769
class="ms-2 inline-flex items-center justify-center w-4 h-4 text-xs text-fg bg-bg-muted border border-border rounded no-underline"
6870
aria-hidden="true"
6971
>

app/components/Link/Base.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ const isButton = computed(() => !isLink.value)
6060
const isButtonSmall = computed(() => props.size === 'small' && !isLink.value)
6161
const isButtonMedium = computed(() => props.size === 'medium' && !isLink.value)
6262
const keyboardShortcutsEnabled = useKeyboardShortcuts()
63+
const showKbdHint = computed(() => keyboardShortcutsEnabled.value && !!props.ariaKeyshortcuts)
6364
</script>
6465

6566
<template>
@@ -115,7 +116,8 @@ const keyboardShortcutsEnabled = useKeyboardShortcuts()
115116
aria-hidden="true"
116117
/>
117118
<kbd
118-
v-if="keyboardShortcutsEnabled && ariaKeyshortcuts"
119+
v-if="showKbdHint"
120+
data-kbd-hint
119121
class="ms-2 inline-flex items-center justify-center size-4 text-xs text-fg bg-bg-muted border border-border rounded no-underline"
120122
aria-hidden="true"
121123
>

app/utils/prehydrate.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,10 @@ export function initPreferencesOnPrehydrate() {
5353
document.documentElement.dataset.pm = pm
5454

5555
document.documentElement.dataset.collapsed = settings.sidebar?.collapsed?.join(' ') ?? ''
56+
57+
// Keyboard shortcuts (default: true)
58+
if (settings.keyboardShortcuts === false) {
59+
document.documentElement.dataset.kbdShortcuts = 'false'
60+
}
5661
})
5762
}

0 commit comments

Comments
 (0)