Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(list, list-item): support keyboard sorting in screen readers #9038

Merged
merged 4 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/calcite-components/src/components/handle/handle.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,14 @@ describe("calcite-handle", () => {
describe("translation support", () => {
t9n("calcite-handle");
});

it("sets application role on handle", async () => {
driskull marked this conversation as resolved.
Show resolved Hide resolved
const page = await newE2EPage();
const label = "Hello World";
await page.setContent(`<calcite-handle lang="en" label="${label}"></calcite-handle>`);
await page.waitForChanges();

const handle = await page.find("calcite-handle");
expect(handle.getAttribute("role")).toBe("application");
});
});
39 changes: 21 additions & 18 deletions packages/calcite-components/src/components/handle/handle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Event,
EventEmitter,
h,
Host,
Method,
Prop,
State,
Expand Down Expand Up @@ -298,24 +299,26 @@ export class Handle implements LoadableComponent, T9nComponent, InteractiveCompo

render(): VNode {
return (
// Needs to be a span because of https://github.com/SortableJS/Sortable/issues/1486
<span
aria-disabled={this.disabled ? toAriaBoolean(this.disabled) : null}
aria-label={this.disabled ? null : this.getAriaText("label")}
aria-pressed={this.disabled ? null : toAriaBoolean(this.selected)}
class={{ [CSS.handle]: true, [CSS.handleSelected]: !this.disabled && this.selected }}
onBlur={this.handleBlur}
onKeyDown={this.handleKeyDown}
role="button"
tabIndex={this.disabled ? null : 0}
title={this.getTooltip()}
// 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)
ref={(el): void => {
this.handleButton = el;
}}
>
<calcite-icon icon={ICONS.drag} scale="s" />
</span>
<Host role="application">
driskull marked this conversation as resolved.
Show resolved Hide resolved
<span
// Needs to be a span because of https://github.com/SortableJS/Sortable/issues/1486
aria-disabled={this.disabled ? toAriaBoolean(this.disabled) : null}
aria-label={this.disabled ? null : this.getAriaText("label")}
aria-pressed={this.disabled ? null : toAriaBoolean(this.selected)}
class={{ [CSS.handle]: true, [CSS.handleSelected]: !this.disabled && this.selected }}
onBlur={this.handleBlur}
onKeyDown={this.handleKeyDown}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on nvaccess/nvda#7898 (comment), I'm curious if screen readers are triggering a click vs keydown event here. Could you team up w/ @geospatialem to test this out? If it works, it could help avoid the host role.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@geospatialem could you review this one?

We don't want to add a click event to this element but we could change its role if we need to. Switching from "button" to "radio" or whatever as suggested by that article.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that's right. There's no click handling logic here. Ignore my suggestion then. Changing the inner element's role makes sense.

role="button"
tabIndex={this.disabled ? null : 0}
title={this.getTooltip()}
// 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)
ref={(el): void => {
this.handleButton = el;
}}
>
<calcite-icon icon={ICONS.drag} scale="s" />
</span>
</Host>
);
}
}
Loading