Skip to content

Commit a3aaf46

Browse files
committed
feat: Custom announcer complementRoute by locale
1 parent 6518857 commit a3aaf46

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

‎docs/.vuepress/config.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ module.exports ={
2222
ariaLabel: 'toggle to %cm mode color',
2323
ariaLive: '%cm color mode is enabled'
2424
},
25+
announcer: {
26+
complementRoute: 'has loaded'
27+
},
2528
nav: [
2629
{
2730
text: 'Guide',

‎docs/guide/config.md‎

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,21 @@ module.exports ={
3939
// ...
4040
locales:{
4141
'/':{
42+
// ...
4243
colorMode:{
4344
ariaLabel:'toggle to %cm mode color',
4445
ariaLive:'%cm color mode is enabled'
4546
}
4647
},
4748
'/pt':{
49+
// ...
4850
colorMode:{
4951
ariaLabel:'Trocar para o modo de cor %cm',
5052
ariaLive:'Modo de cor %cm está habilitado'
5153
}
5254
},
5355
'/es':{
56+
// ...
5457
colorMode:{
5558
ariaLabel:'Cambiar al modo de color %cm',
5659
ariaLive:'Se eligió el modo de color %cm'
@@ -66,4 +69,38 @@ Pretty soon
6669
6770
## Announcer
6871
69-
Pretty soon
72+
The [@vue-a11y/announcer](https://github.com/vue-a11y/vue-announcer) provides an easy way for people using screen readers to know what’s going on in your app.
73+
74+
It is already installed and configured in the theme to announce the routes changes.
75+
76+
You can configure the title add-on according to the location, by default the value is `has loaded`.
77+
78+
```javascript
79+
// e.g. docs/.vuepress/config.js
80+
module.exports={
81+
theme:'vuepress-theme-default-vue-a11y',
82+
// ...
83+
themeConfig:{
84+
// ...
85+
locales:{
86+
'/':{
87+
// ...
88+
announcer:{
89+
complementRoute:'has loaded'// optional
90+
}
91+
},
92+
'/pt':{
93+
// ...
94+
announcer:{
95+
complementRoute:'foi carregado'
96+
}
97+
},
98+
'/es':{
99+
// ...
100+
announcer:{
101+
complementRoute:'ha cargado'
102+
}
103+
}
104+
}
105+
}
106+
```

‎layouts/Layout.vue‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,15 @@ export default{
4747
this.$nextTick(() =>{
4848
this.setMainId()
4949
this.setWarningInExternalLinks()
50+
this.setComplementRouteToAnnouncer()
5051
})
5152
},
53+
5254
setMainId (){
5355
constmain=document.getElementsByTagName('main')
5456
if (main.length) main[0].setAttribute('id', 'main')
5557
},
58+
5659
setWarningInExternalLinks (){
5760
constlinks=document.querySelectorAll('a[target="_blank"]')
5861
if (!links.length) return
@@ -61,6 +64,12 @@ export default{
6164
constwarning=`<span class="visually-hidden">, ${this.$themeLocaleConfig.warningExternalLinkText||'opens in a new window'}</span>`
6265
link.innerHTML=link.innerHTML.replace(textContent, `${textContent}${warning}`)
6366
})
67+
},
68+
69+
setComplementRouteToAnnouncer (){
70+
if (this.$themeLocaleConfig.announcer){
71+
this.$announcer.setComplementRoute(this.$themeLocaleConfig.announcer.complementRoute)
72+
}
6473
}
6574
}
6675
}

0 commit comments

Comments
(0)