Skip to content

Commit 7119fae

Browse files
authored
Change the way focus is set in skip link example code (#3164)
update skip link example code
1 parent c0e81ef commit 7119fae

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/guide/best-practices/accessibility.md

+8-4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ You should add a link at the top of each page that goes directly to the main con
1313
Typically this is done on the top of `App.vue` as it will be the first focusable element on all your pages:
1414

1515
```vue-html
16+
<span ref="backToTop" tabindex="-1" />
1617
<ul class="skip-links">
1718
<li>
1819
<a href="#main" ref="skipLink" class="skip-link">Skip to main content</a>
@@ -23,6 +24,9 @@ Typically this is done on the top of `App.vue` as it will be the first focusable
2324
To hide the link unless it is focused, you can add the following style:
2425

2526
```css
27+
.skip-links {
28+
list-style: none;
29+
}
2630
.skip-link {
2731
white-space: nowrap;
2832
margin: 1em auto;
@@ -40,7 +44,7 @@ To hide the link unless it is focused, you can add the following style:
4044
}
4145
```
4246

43-
Once a user changes route, bring focus back to the skip link. This can be achieved by calling focus on the skip link's template ref (assuming usage of `vue-router`):
47+
Once a user changes route, bring focus back to the very beginning of the page, right before the skip link. This can be achieved by calling focus on the `backToTop` template ref (assuming usage of `vue-router`):
4448

4549
<div class="options-api">
4650

@@ -49,7 +53,7 @@ Once a user changes route, bring focus back to the skip link. This can be achiev
4953
export default {
5054
watch: {
5155
$route() {
52-
this.$refs.skipLink.focus()
56+
this.$refs.backToTop.focus()
5357
}
5458
}
5559
}
@@ -65,12 +69,12 @@ import { ref, watch } from 'vue'
6569
import { useRoute } from 'vue-router'
6670
6771
const route = useRoute()
68-
const skipLink = ref()
72+
const backToTop = ref()
6973
7074
watch(
7175
() => route.path,
7276
() => {
73-
skipLink.value.focus()
77+
backToTop.value.focus()
7478
}
7579
)
7680
</script>

0 commit comments

Comments
 (0)