Skip to content

Commit 706b823

Browse files
committed
feat: customize aria-label and aria-live through props
1 parent 63488d6 commit 706b823

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

Diff for: src/vue-dark-mode.vue

+20-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
<template>
22
<button
3-
:aria-label="`toggle to ${getNextMode} mode color`"
4-
:title="`toggle to ${getNextMode} mode color`"
3+
:aria-label="getAriaLabel"
4+
:title="getAriaLabel"
55
class="vue-dark-mode"
66
@click="toggleColorMode"
77
>
88
<span
99
class="visually-hidden"
1010
aria-live="assertive"
11-
>
12-
{{ chosenMode }} color mode is enabled
13-
</span>
11+
v-text="getAriaLive"
12+
/>
1413
<slot :mode="chosenMode" />
1514
</button>
1615
</template>
@@ -37,6 +36,14 @@ export default {
3736
metaThemeColor: {
3837
type: Object,
3938
default: () => ({})
39+
},
40+
ariaLabel: {
41+
type: String,
42+
default: 'toggle to %cm mode color'
43+
},
44+
ariaLive: {
45+
type: String,
46+
default: '%cm color mode is enabled'
4047
}
4148
},
4249
@@ -61,6 +68,14 @@ export default {
6168
return colorScheme
6269
},
6370
71+
getAriaLabel () {
72+
return this.ariaLabel.replace(/%cm/g, this.getNextMode)
73+
},
74+
75+
getAriaLive () {
76+
return this.ariaLive.replace(/%cm/g, this.chosenMode)
77+
},
78+
6479
getNextMode () {
6580
const currentIndex = this.modes.findIndex(mode => mode === this.chosenMode)
6681
return this.modes[currentIndex === (this.modes.length - 1) ? 0 : currentIndex + 1]

0 commit comments

Comments
 (0)