Skip to content

Commit 85d2471

Browse files
authoredFeb 9, 2025
Change the way focus is set in skip link example code (#2506)
1 parent 7d45c5f commit 85d2471

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 @@ Web アクセシビリティー(a11y としても知られます)とは、
1313
通常、これは `App.vue` の上部に置かれ、すべてのページで最初にフォーカス可能な要素になります:
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 @@ Web アクセシビリティー(a11y としても知られます)とは、
2324
フォーカスされない限りリンクを非表示にするには、以下のようなスタイルを追加します:
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 @@ Web アクセシビリティー(a11y としても知られます)とは、
4044
}
4145
```
4246

43-
ユーザーがルートを変更したら、スキップリンクにフォーカスを戻します。これは、スキップリンクのテンプレート参照でフォーカスを呼び出すことで実現できます`vue-router` の使用を想定しています):
47+
ユーザーがルートを変更したら、ページの一番最初、スキップリンクの直前にフォーカスを戻します。これは `backToTop` テンプレート参照でフォーカスを呼び出すことで実現できます`vue-router` の使用を想定しています):
4448

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

@@ -49,7 +53,7 @@ Web アクセシビリティー(a11y としても知られます)とは、
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)