Skip to content

Commit a97ec45

Browse files
committed
fix(ui): sync kbd-shortcuts data attribute on toggle
1 parent 3c0d4a0 commit a97ec45

3 files changed

Lines changed: 21 additions & 7 deletions

File tree

app/components/Button/Base.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ const props = withDefaults(
2727
const el = useTemplateRef('el')
2828
2929
const keyboardShortcutsEnabled = useKeyboardShortcuts()
30-
const showKbdHint = computed(() => keyboardShortcutsEnabled.value && !!props.ariaKeyshortcuts)
3130
3231
defineExpose({
3332
focus: () => el.value?.focus(),
@@ -64,7 +63,7 @@ defineExpose({
6463
<span v-if="classicon" class="size-[1em]" :class="classicon" aria-hidden="true" />
6564
<slot />
6665
<kbd
67-
v-if="showKbdHint"
66+
v-if="keyboardShortcutsEnabled && ariaKeyshortcuts"
6867
data-kbd-hint
6968
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"
7069
aria-hidden="true"

app/components/Link/Base.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ 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)
6463
</script>
6564

6665
<template>
@@ -116,7 +115,7 @@ const showKbdHint = computed(() => keyboardShortcutsEnabled.value && !!props.ari
116115
aria-hidden="true"
117116
/>
118117
<kbd
119-
v-if="showKbdHint"
118+
v-if="keyboardShortcutsEnabled && ariaKeyshortcuts"
120119
data-kbd-hint
121120
class="ms-2 inline-flex items-center justify-center size-4 text-xs text-fg bg-bg-muted border border-border rounded no-underline"
122121
aria-hidden="true"

app/composables/useSettings.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,26 @@ export function useRelativeDates() {
104104
* Composable for accessing just the keyboard shortcuts setting.
105105
* Useful for components that only need to read this specific setting.
106106
*/
107-
export function useKeyboardShortcuts() {
107+
export const useKeyboardShortcuts = createSharedComposable(function useKeyboardShortcuts() {
108108
const { settings } = useSettings()
109-
return computed(() => settings.value.keyboardShortcuts)
110-
}
109+
const enabled = computed(() => settings.value.keyboardShortcuts)
110+
111+
if (import.meta.client) {
112+
watch(
113+
enabled,
114+
value => {
115+
if (value) {
116+
delete document.documentElement.dataset.kbdShortcuts
117+
} else {
118+
document.documentElement.dataset.kbdShortcuts = 'false'
119+
}
120+
},
121+
{ immediate: true },
122+
)
123+
}
124+
125+
return enabled
126+
})
111127

112128
/**
113129
* Composable for managing accent color.

0 commit comments

Comments
 (0)