Skip to content

Commit b2e1b9b

Browse files
authored
fix(list, list-item): support keyboard sorting in screen readers (#9038)
**Related Issue:** #7426 ## Summary - support keyboard sorting in screen readers by setting internal role to radio - add e2e test. - https://stackoverflow.com/questions/52261977/why-javascript-if-keycode-enter-key-or-spacebar-key-does-not-work-with-nvda
1 parent eebe8ca commit b2e1b9b

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

packages/calcite-components/src/components/handle/handle.e2e.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,22 @@ describe("calcite-handle", () => {
125125
describe("translation support", () => {
126126
t9n("calcite-handle");
127127
});
128+
129+
it("sets radio role properly", async () => {
130+
const page = await newE2EPage();
131+
const label = "Hello World";
132+
await page.setContent(`<calcite-handle lang="en" label="${label}"></calcite-handle>`);
133+
await page.waitForChanges();
134+
135+
const handle = await page.find("calcite-handle");
136+
137+
const internalHandle = await page.find(`calcite-handle >>> .${CSS.handle}`);
138+
expect(internalHandle.getAttribute("role")).toBe("radio");
139+
expect(internalHandle.getAttribute("aria-checked")).toBe("false");
140+
141+
handle.setProperty("selected", true);
142+
143+
await page.waitForChanges();
144+
expect(internalHandle.getAttribute("aria-checked")).toBe("true");
145+
});
128146
});

packages/calcite-components/src/components/handle/handle.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,13 +300,14 @@ export class Handle implements LoadableComponent, T9nComponent, InteractiveCompo
300300
return (
301301
// Needs to be a span because of https://github.com/SortableJS/Sortable/issues/1486
302302
<span
303+
aria-checked={this.disabled ? null : toAriaBoolean(this.selected)}
303304
aria-disabled={this.disabled ? toAriaBoolean(this.disabled) : null}
304305
aria-label={this.disabled ? null : this.getAriaText("label")}
305-
aria-pressed={this.disabled ? null : toAriaBoolean(this.selected)}
306306
class={{ [CSS.handle]: true, [CSS.handleSelected]: !this.disabled && this.selected }}
307307
onBlur={this.handleBlur}
308308
onKeyDown={this.handleKeyDown}
309-
role="button"
309+
// role of radio is being applied to allow space key to select in screen readers
310+
role="radio"
310311
tabIndex={this.disabled ? null : 0}
311312
title={this.getTooltip()}
312313
// eslint-disable-next-line react/jsx-sort-props -- ref should be last so node attrs/props are in sync (see https://github.com/Esri/calcite-design-system/pull/6530)

0 commit comments

Comments
 (0)