Skip to content

Commit f3ce903

Browse files
authored
fix(a11y): improve keyboard accessibility for sidebar and external links (#8014)
1 parent e4f4aa8 commit f3ce903

6 files changed

Lines changed: 40 additions & 10 deletions

File tree

src/components/Link/Link.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ const Link = ({ to = "", url, ...props }) => {
88

99
if (to.startsWith("http") || to.startsWith("//")) {
1010
return (
11-
<a href={to} target="_blank" rel="noopener noreferrer" {...others} />
11+
<a href={to} target="_blank" rel="noopener noreferrer" {...others}>
12+
{others.children}
13+
<span className="screen-reader-only">(opens in a new tab)</span>
14+
</a>
1215
);
1316
}
1417

src/components/SidebarItem/SidebarItem.jsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,19 @@ export default class SidebarItem extends Component {
6464
return (
6565
<div className={`${block} ${openMod} ${disabledMod}`}>
6666
{anchors.length > 0 ? (
67-
<ChevronRightIcon
68-
width={15}
69-
height={17}
70-
fill="#175d96"
71-
className={`${block}__toggle`}
67+
<button
68+
className={`${block}__toggle-button`}
7269
onClick={this._toggle.bind(this)}
73-
/>
70+
aria-label={`Toggle ${title} section`}
71+
aria-expanded={this.state.open}
72+
>
73+
<ChevronRightIcon
74+
width={15}
75+
height={17}
76+
fill="#175d96"
77+
className={`${block}__toggle`}
78+
/>
79+
</button>
7480
) : (
7581
<BarIcon
7682
className={`${block}__toggle`}

src/components/SidebarItem/SidebarItem.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@
2121
}
2222
}
2323

24+
&__toggle-button {
25+
background: none;
26+
border: none;
27+
padding: 0;
28+
display: flex;
29+
align-items: center;
30+
}
31+
2432
&__title {
2533
flex: 1 1 auto;
2634
color: getColor(elephant);

src/components/SidebarMobile/SidebarMobile.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ export default class SidebarMobile extends Component {
4040
/>
4141

4242
<div className="sidebar-mobile__content">
43-
<span
44-
role="button"
43+
<button
4544
className="sidebar-mobile__close"
4645
onClick={toggle.bind(null, false)}
46+
aria-label="Close navigation menu"
4747
>
4848
<CloseIcon fill="#fff" width={20} />
49-
</span>
49+
</button>
5050

5151
{this._getSections()}
5252
</div>

src/components/SidebarMobile/SidebarMobile.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
.sidebar-mobile__close {
5454
position: absolute;
5555
cursor: pointer;
56+
border: none;
5657
right: 22px;
5758
top: 10px;
5859
font-size: 1.3em;

src/styles/index.scss

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,15 @@ body {
6666
}
6767
}
6868
}
69+
70+
.screen-reader-only {
71+
position: absolute;
72+
width: 1px;
73+
height: 1px;
74+
padding: 0;
75+
margin: -1px;
76+
overflow: hidden;
77+
clip: rect(0, 0, 0, 0);
78+
white-space: nowrap;
79+
border: 0;
80+
}

0 commit comments

Comments
 (0)