Skip to content

Commit a6b9eef

Browse files
authored
test(*): a11y testing with chai axe core that penetrates shadow dom [run-chromatic][skip-cd] (#655)
2 parents 49db08f + a7a3550 commit a6b9eef

58 files changed

Lines changed: 871 additions & 109 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

rollup.test.config.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ function getFilesInDirectorySync(directoryPath) {
2828

2929
export default [
3030
{
31-
input: [...getFilesInDirectorySync("./test"), ...getFilesInDirectorySync("./test/utils")],
31+
input: [
32+
...getFilesInDirectorySync("./test"),
33+
...getFilesInDirectorySync("./test/utils"),
34+
...getFilesInDirectorySync("./test/a11y")
35+
],
3236
output: [
3337
{
3438
dir: "test-outdir",

src/components/Datepicker/sgds-datepicker.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,6 @@ export class SgdsDatepicker extends SgdsFormValidatorMixin(DropdownElement) impl
443443
</sgds-datepicker-input>
444444
<sgds-icon-button
445445
${ref(this.myDropdown)}
446-
role="button"
447446
tone="neutral"
448447
class=${classMap({
449448
"calendar-btn": true,

src/components/Drawer/sgds-drawer.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { html, PropertyValueMap } from "lit";
1+
import { html, nothing, PropertyValueMap } from "lit";
22
import { property, query } from "lit/decorators.js";
33
import { classMap } from "lit/directives/class-map.js";
44
import SgdsElement from "../../base/sgds-element";
@@ -63,6 +63,11 @@ export class SgdsDrawer extends SgdsElement {
6363
/** The direction from which the drawer will open. */
6464
@property({ type: String, reflect: true }) placement: "top" | "end" | "bottom" | "start" = "end";
6565

66+
/**
67+
* The accessible label for the drawer dialog. This is required for assistive technology.
68+
*/
69+
@property({ type: String, reflect: true }) ariaLabel = "";
70+
6671
/**
6772
* By default, the drawer slides out of its containing block (usually the viewport). To make the drawer slide out of
6873
* its parent element, set this attribute and add `position: relative` to the parent.
@@ -270,6 +275,7 @@ export class SgdsDrawer extends SgdsElement {
270275
class="drawer-panel"
271276
role="dialog"
272277
aria-modal="true"
278+
aria-label=${this.ariaLabel || nothing}
273279
aria-hidden=${this.open ? "false" : "true"}
274280
tabindex="0"
275281
>

src/components/Dropdown/sgds-dropdown.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,24 @@ export class SgdsDropdown extends DropdownListElement {
9292
this._handleDisabled();
9393
}
9494

95+
private _handleTogglerSlotChange(e: Event) {
96+
const slot = e.target as HTMLSlotElement;
97+
const elements = slot.assignedElements({ flatten: true });
98+
const button = elements[0];
99+
if (button) {
100+
button.setAttribute("aria-haspopup", "menu");
101+
button.setAttribute("aria-expanded", String(this.menuIsOpen));
102+
}
103+
}
104+
105+
@watch("menuIsOpen")
106+
_handleMenuIsOpenChange() {
107+
const button = this._toggler[0];
108+
if (button) {
109+
button.setAttribute("aria-expanded", String(this.menuIsOpen));
110+
}
111+
}
112+
95113
@watch("disabled", { waitUntilFirstUpdate: true })
96114
_handleDisabled() {
97115
const button = this._toggler[0];
@@ -107,8 +125,8 @@ export class SgdsDropdown extends DropdownListElement {
107125
render() {
108126
return html`
109127
<div class="dropdown" @click=${this._handleClick}>
110-
<div class="toggler-container" ${ref(this.myDropdown)} aria-expanded="${this.menuIsOpen}" aria-haspopup="menu">
111-
<slot name="toggler"></slot>
128+
<div class="toggler-container" ${ref(this.myDropdown)}>
129+
<slot name="toggler" @slotchange=${this._handleTogglerSlotChange}></slot>
112130
</div>
113131
<div class="dropdown-menu" role="menu" ${ref(this.menuRef)}>
114132
<slot id="default" @click=${this.handleSelectSlot}></slot>

src/components/Mainnav/sgds-mainnav.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ export class SgdsMainnav extends SgdsElement {
324324
@click=${this._handleSummaryClick}
325325
aria-controls="${this.collapseId}"
326326
aria-expanded="${this.expanded}"
327-
aria-label="Toggle navigation"
327+
.ariaLabel=${"Toggle navigation"}
328328
></sgds-icon-button>
329329
</div>
330330
</nav>

src/components/OverflowMenu/sgds-overflow-menu.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class SgdsOverflowMenu extends SgdsElement {
2323
render() {
2424
return html`
2525
<sgds-dropdown>
26-
<button slot="toggler" class="overflow-btn">
26+
<button slot="toggler" class="overflow-btn" aria-label="More options">
2727
<sgds-icon name="three-dots" size=${this.size}></sgds-icon>
2828
</button>
2929
<slot></slot>

src/components/Pagination/sgds-pagination.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ export class SgdsPagination extends SgdsElement {
7878
}
7979

8080
private _handlePageClick(event: MouseEvent) {
81-
const liTarget = event.target as HTMLElement;
82-
const clickedLi = liTarget.closest("li");
81+
const target = event.target as HTMLElement;
82+
const clickedItem = target.closest(".page-item");
8383

84-
if (clickedLi) {
85-
const clickedPage = Number(clickedLi.getAttribute("key"));
84+
if (clickedItem) {
85+
const clickedPage = Number(clickedItem.getAttribute("key"));
8686
if (clickedPage !== this.currentPage) {
8787
this.currentPage = clickedPage;
8888
}
@@ -124,7 +124,7 @@ export class SgdsPagination extends SgdsElement {
124124

125125
private _renderFirstPage() {
126126
return html`
127-
<li key=${1} class="page-item ${this.currentPage === 1 ? "active" : ""}">
127+
<div key=${1} class="page-item ${this.currentPage === 1 ? "active" : ""}">
128128
<span
129129
role="button"
130130
class="page-link"
@@ -135,7 +135,7 @@ export class SgdsPagination extends SgdsElement {
135135
@keydown=${(e: KeyboardEvent) => this._handleKeyDown(e, "pageNumber", 1)}
136136
>1</span
137137
>
138-
</li>
138+
</div>
139139
`;
140140
}
141141

@@ -184,7 +184,7 @@ export class SgdsPagination extends SgdsElement {
184184
private _renderPgNumbers(pagesToShow: number[]) {
185185
return pagesToShow.map(
186186
number => html`
187-
<li key=${number} class="page-item ${this.currentPage === number ? "active" : ""}">
187+
<div key=${number} class="page-item ${this.currentPage === number ? "active" : ""}">
188188
<span
189189
role="button"
190190
class="page-link"
@@ -195,7 +195,7 @@ export class SgdsPagination extends SgdsElement {
195195
@keydown=${(e: KeyboardEvent) => this._handleKeyDown(e, "pageNumber", number)}
196196
>${number}</span
197197
>
198-
</li>
198+
</div>
199199
`
200200
);
201201
}
@@ -214,9 +214,9 @@ export class SgdsPagination extends SgdsElement {
214214
}
215215

216216
return html`
217-
<li class="page-item ">
217+
<div class="page-item">
218218
<span class="page-link ellipsis">${this.ellipsisContent}</span>
219-
</li>
219+
</div>
220220
`;
221221
};
222222

@@ -233,15 +233,15 @@ export class SgdsPagination extends SgdsElement {
233233
return null;
234234
}
235235
return html`
236-
<li class="page-item">
236+
<div class="page-item">
237237
<span class="page-link ellipsis ">${this.ellipsisContent}</span>
238-
</li>
238+
</div>
239239
`;
240240
}
241241

242242
private _renderLastPage() {
243243
return html`
244-
<li key=${this.pages.length} class="page-item ${this.currentPage === this.pages.length ? "active" : ""}">
244+
<div key=${this.pages.length} class="page-item ${this.currentPage === this.pages.length ? "active" : ""}">
245245
<span
246246
role="button"
247247
class="page-link"
@@ -254,7 +254,7 @@ export class SgdsPagination extends SgdsElement {
254254
@keydown=${(e: KeyboardEvent) => this._handleKeyDown(e, "pageNumber", this.pages.length)}
255255
>${this.pages.length}</span
256256
>
257-
</li>
257+
</div>
258258
`;
259259
}
260260

@@ -338,12 +338,12 @@ export class SgdsPagination extends SgdsElement {
338338
render() {
339339
return html`
340340
<nav aria-label="pagination" role="navigation">
341-
<ul class="pagination pagination-${this.size}">
341+
<div class="pagination pagination-${this.size}">
342342
${this.variant === "description" ? this._renderDescriptionPagination() : nothing}
343343
${this.variant === "default" ? this._renderDefaultPagination() : nothing}
344344
${this.variant === "number" ? this._renderNumberPagination() : nothing}
345345
${this.variant === "button" ? this._renderButtonPagination() : nothing}
346-
</ul>
346+
</div>
347347
</nav>
348348
`;
349349
}

src/components/ProgressBar/sgds-progress-bar.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ export class SgdsProgressBar extends SgdsElement {
3232
/**
3333
* Sets the aria label for assistive devices.
3434
*/
35+
@property({ type: String, reflect: true }) ariaLabel = "";
36+
37+
/**
38+
* @deprecated Use `ariaLabel` instead.
39+
*/
3540
@property({ type: String, reflect: true }) arialabel = "";
3641

3742
/** Add label on top of progress bar */
@@ -45,10 +50,10 @@ export class SgdsProgressBar extends SgdsElement {
4550
class="progress-bar"
4651
role="progressbar"
4752
style=${styleMap({ width: `${this.value}%` })}
48-
aria-label=${this.arialabel}
53+
aria-label=${this.ariaLabel || this.arialabel || nothing}
4954
aria-valuenow=${this.value}
50-
aria-valuemin=${this.ariamin}
51-
aria-valuemax=${this.ariamax}
55+
aria-valuemin=${this.ariamin ?? nothing}
56+
aria-valuemax=${this.ariamax ?? nothing}
5257
></div>
5358
</div>
5459
${this.label ? html`<span class="label">${this.label}</span>` : nothing}

src/components/Radio/sgds-radio.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ export class SgdsRadio extends SgdsElement {
5151
if (this.checked && this.autofocus) {
5252
this.input?.focus();
5353
}
54-
this.setAttribute("aria-checked", this.checked ? "true" : "false");
5554
this.setAttribute("tabindex", this.checked ? "0" : "-1");
5655
}
5756

@@ -81,7 +80,6 @@ export class SgdsRadio extends SgdsElement {
8180
}
8281

8382
private setInitialAttributes() {
84-
this.setAttribute("role", "radio");
8583
this.setAttribute("tabindex", "-1");
8684
this.setAttribute("aria-disabled", this.disabled ? "true" : "false");
8785
}

src/components/Sidebar/sgds-sidebar-item.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { html, nothing } from "lit";
22
import { classMap } from "lit/directives/class-map.js";
3+
import { ifDefined } from "lit/directives/if-defined.js";
34
import SgdsElement from "../../base/sgds-element";
45
import sidebarOptionStyle from "./sidebar-item.css";
56

@@ -28,7 +29,7 @@ export class SgdsSidebarItem extends SidebarElement {
2829
active: this._selected
2930
})}
3031
@click=${() => this._handleClick()}
31-
aria-label=${this.title || this.name}
32+
aria-label=${ifDefined(this.title || this.name || undefined)}
3233
name=${this.name}
3334
tabindex=${this._hidden ? -1 : 0}
3435
role="button"

0 commit comments

Comments
 (0)