Skip to content

Commit 5d7584c

Browse files
authored
Merge pull request #726 from craftcms/a11y/skip-link
Accessibility improvements: Skip links and focus management
2 parents dae547d + 03309b5 commit 5d7584c

File tree

5 files changed

+69
-3
lines changed

5 files changed

+69
-3
lines changed

docs/.vuepress/theme/components/DocSetPanel.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@
102102
}
103103
104104
&.active {
105-
@apply text-blue text-lg;
105+
@apply text-lg;
106+
color: var(--sidebar-active-link-color);
106107
107108
.home-icon {
108109
@apply inline-block;
@@ -116,7 +117,8 @@
116117
}
117118
118119
.home-title {
119-
@apply relative pl-0 text-blue;
120+
@apply relative pl-0;
121+
color: var(--sidebar-active-link-color);
120122
left: -2px;
121123
}
122124
}

docs/.vuepress/theme/components/Page.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<main class="page">
33
<slot name="top" />
44

5-
<Content id="content" class="theme-default-content" />
5+
<Content id="content" class="theme-default-content" tabindex="-1" />
66

77
<PageNav v-bind="{ sidebarItems }" />
88

docs/.vuepress/theme/layouts/Layout.vue

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
@touchstart="onTouchStart"
66
@touchend="onTouchEnd"
77
>
8+
<span ref="backToTop" tabindex="-1" />
9+
<ul class="skip-links">
10+
<li>
11+
<a @click="handleSkipLink" href="#content" class="skip-link">Skip to main content</a>
12+
</li>
13+
</ul>
814
<div id="nprogress-container"></div>
915
<div class="sidebar-mask" @click="toggleSidebar(false)" />
1016
<LeftBar
@@ -179,6 +185,12 @@ export default {
179185
Hamburger,
180186
},
181187
188+
watch: {
189+
'$route.path'() {
190+
this.$refs.backToTop.focus()
191+
}
192+
},
193+
182194
data: () => ({
183195
isSidebarOpen: false,
184196
isSidebarTransitioning: false,
@@ -358,6 +370,16 @@ export default {
358370
this.$emit("toggle-sidebar", this.isSidebarOpen);
359371
},
360372
373+
handleSkipLink(event) {
374+
event.preventDefault();
375+
const {target} = event;
376+
const skipLinkTarget = this.$el.querySelector(target.getAttribute('href'));
377+
378+
if (skipLinkTarget) {
379+
skipLinkTarget.focus({focusVisible: false});
380+
}
381+
},
382+
361383
handleWidthChange() {
362384
if (typeof document === "undefined") {
363385
return;

docs/.vuepress/theme/styles/base.pcss

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,16 @@
2323
--custom-block-bg-color: theme("colors.softer");
2424
--custom-block-border-color: theme("colors.soft");
2525
--craft-red: #e5422b;
26+
--white: theme("colors.white");
27+
--black: theme("colors.black");
2628
--custom-focus-outline: 2px solid var(--link-color-default);
2729

30+
/* Custom button */
31+
--button-background-color: theme("colors.blue.default");
32+
--button-text-color: var(--white);
33+
--button-border-color: theme("colors.blue.darker");
34+
--button-border-radius: 4px;
35+
2836
/* Code */
2937
--code-color-default: #476582;
3038
--code-color-gold: #8A6700;
@@ -69,6 +77,30 @@ a {
6977
color: var(--link-color-default);
7078
}
7179

80+
.skip-links {
81+
list-style: none;
82+
}
83+
84+
.skip-link {
85+
white-space: nowrap;
86+
top: .5em;
87+
position: fixed;
88+
left: -1000px;
89+
opacity: 0;
90+
background-color: var(--button-background-color);
91+
color: var(--button-text-color);
92+
font-weight: 500;
93+
padding: .75em 1.5em;
94+
border: 1px solid var(--button-border-color);
95+
border-radius: var(--button-border-radius);
96+
}
97+
98+
.skip-link:focus {
99+
opacity: 1;
100+
z-index: 100;
101+
left: .5em;
102+
}
103+
72104
img {
73105
@apply max-w-full;
74106
}

docs/.vuepress/theme/styles/color-mode.pcss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
--sidebar-active-link-color: var(--link-color-default);
3030
--code-link-color: theme("colors.blue.lighter");
3131

32+
/* Buttons */
33+
--button-background-color: theme("colors.gray.800");
34+
--button-text-color: var(--white);
35+
--button-border-color: #818EA2;
36+
3237
/* Code */
3338
--code-color-default: #7F9CB8;
3439
--code-color-gold: #BD8E00;
@@ -67,6 +72,11 @@
6772
--sidebar-active-link-color: var(--link-color-default);
6873
--code-link-color: theme("colors.blue.lighter");
6974

75+
/* Buttons */
76+
--button-background-color: theme("colors.gray.800");
77+
--button-text-color: var(--white);
78+
--button-border-color: #818EA2;
79+
7080
/* Code */
7181
--code-color-default: #7F9CB8;
7282
--code-color-gold: #BD8E00;

0 commit comments

Comments
 (0)