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: remove aria-disabled from components where necessary #10374

Merged
merged 8 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describe("calcite-button", () => {
hidden("calcite-button");
});

it("renders child element as disabled or aria-disabled", async () => {
it("renders child element as disabled", async () => {
const page = await newE2EPage();
await page.setContent(`<calcite-button disabled>Continue</calcite-button>`);

Expand All @@ -105,7 +105,6 @@ describe("calcite-button", () => {
expect(elementAsLink).toBeNull();

expect(await elementAsButton.getProperty("disabled")).toBe(true);
expect(await elementAsButton.getProperty("ariaDisabled")).toBe(null);

const element = await page.find("calcite-button");
element.setProperty("href", "#anchor");
Expand All @@ -118,7 +117,6 @@ describe("calcite-button", () => {
expect(elementAsLink).not.toBeNull();

expect(await elementAsLink.getProperty("disabled")).toBe(undefined);
expect(await elementAsLink.getProperty("ariaDisabled")).toBe("true");
});

it("renders as a button with default props", async () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/calcite-components/src/components/button/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ import {
updateMessages,
} from "../../utils/t9n";
import { Appearance, FlipContext, Kind, Scale, Width } from "../interfaces";
import { toAriaBoolean } from "../../utils/dom";
import { IconNameOrString } from "../icon/interfaces";
import { isBrowser } from "../../utils/browser";
import { toAriaBoolean } from "../../utils/dom";
import { ButtonMessages } from "./assets/button/t9n";
import { ButtonAlignment } from "./interfaces";
import { CSS } from "./resources";
Expand Down Expand Up @@ -266,7 +266,7 @@ export class Button
return (
<InteractiveContainer disabled={this.disabled}>
<Tag
aria-disabled={childElType === "a" ? toAriaBoolean(this.disabled || this.loading) : null}
driskull marked this conversation as resolved.
Show resolved Hide resolved
aria-busy={toAriaBoolean(this.loading)}
aria-expanded={this.el.ariaExpanded}
aria-label={!this.loading ? getLabelText(this) : this.messages.loading}
aria-live="polite"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
Watch,
Host,
} from "@stencil/core";
import { focusElement, focusElementInGroup, toAriaBoolean } from "../../utils/dom";
import { focusElement, focusElementInGroup } from "../../utils/dom";
import {
InteractiveComponent,
InteractiveContainer,
Expand Down Expand Up @@ -235,12 +235,7 @@ export class CardGroup implements InteractiveComponent, LoadableComponent {
return (
<Host>
<InteractiveContainer disabled={this.disabled}>
<div
aria-disabled={toAriaBoolean(this.disabled)}
Copy link
Member Author

Choose a reason for hiding this comment

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

Not needed because the InteractiveContainer will handle setting aria-disabled

aria-label={this.label}
class="container"
role={role}
>
<div aria-label={this.label} class="container" role={role}>
<slot
onSlotchange={this.updateItemsOnSlotChange}
ref={(el) => (this.slotRefEl = el as HTMLSlotElement)}
Expand Down
1 change: 0 additions & 1 deletion packages/calcite-components/src/components/card/card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,6 @@ export class Card
<InteractiveContainer disabled={this.disabled}>
<div
aria-checked={this.selectionMode !== "none" ? toAriaBoolean(this.selected) : undefined}
aria-disabled={this.disabled}
Copy link
Member Author

@driskull driskull Sep 23, 2024

Choose a reason for hiding this comment

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

This one wasn't using toAriaBoolean so it wasn't working. I think that means we can safely remove it.

aria-label={this.label}
class={{ [CSS.contentWrapper]: true, inline: thumbnailInline }}
onClick={this.cardBodyClickHandler}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
Method,
Watch,
} from "@stencil/core";
import { focusElementInGroup, slotChangeGetAssignedElements, toAriaBoolean } from "../../utils/dom";
import { focusElementInGroup, slotChangeGetAssignedElements } from "../../utils/dom";
import {
InteractiveComponent,
InteractiveContainer,
Expand Down Expand Up @@ -275,12 +275,7 @@ export class ChipGroup implements InteractiveComponent {

return (
<InteractiveContainer disabled={disabled}>
<div
aria-disabled={toAriaBoolean(disabled)}
Copy link
Member Author

Choose a reason for hiding this comment

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

Not needed because the InteractiveContainer will handle setting aria-disabled

aria-label={this.label}
class="container"
role={role}
>
<div aria-label={this.label} class="container" role={role}>
<slot
onSlotchange={this.updateItems}
ref={(el) => (this.slotRefEl = el as HTMLSlotElement)}
Expand Down
1 change: 0 additions & 1 deletion packages/calcite-components/src/components/chip/chip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,6 @@ export class Chip
? toAriaBoolean(this.selected)
: undefined
}
aria-disabled={disableInteraction ? toAriaBoolean(disabled) : undefined}
Copy link
Member Author

@driskull driskull Sep 24, 2024

Choose a reason for hiding this comment

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

This one was only setting aria-disabled when disabled was true anyway. Not sure why the disabledInteraction is being tested here unless we do this:

 aria-disabled={disableInteraction ? toAriaBoolean(disableInteraction) : undefined}

I think we can safely remove this and rely on InteractiveContainer to set aria-disabled.

aria-label={this.label}
class={{
[CSS.container]: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ export class DatePickerDay implements InteractiveComponent, LoadableComponent {

return (
<Host
aria-disabled={toAriaBoolean(this.disabled)}
Copy link
Member Author

Choose a reason for hiding this comment

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

Not needed because the InteractiveContainer will handle setting aria-disabled

aria-label={dayLabel}
aria-selected={toAriaBoolean(this.active)}
id={dayId}
Expand Down
44 changes: 25 additions & 19 deletions packages/calcite-components/src/components/handle/handle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ import {
T9nComponent,
updateMessages,
} from "../../utils/t9n";
import { InteractiveComponent, updateHostInteraction } from "../../utils/interactive";
import {
InteractiveComponent,
InteractiveContainer,
updateHostInteraction,
} from "../../utils/interactive";
import { HandleMessages } from "./assets/handle/t9n";
import { HandleChange, HandleNudge } from "./interfaces";
import { CSS, ICONS, SUBSTITUTIONS } from "./resources";
Expand Down Expand Up @@ -294,24 +298,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-checked={this.disabled ? null : toAriaBoolean(this.selected)}
aria-disabled={this.disabled ? toAriaBoolean(this.disabled) : null}
aria-label={this.disabled ? null : this.getAriaText("label")}
class={{ [CSS.handle]: true, [CSS.handleSelected]: !this.disabled && this.selected }}
onBlur={this.handleBlur}
onKeyDown={this.handleKeyDown}
ref={(el): void => {
this.handleButton = el;
}}
// role of radio is being applied to allow space key to select in screen readers
role="radio"
tabIndex={this.disabled ? null : 0}
title={this.getTooltip()}
>
<calcite-icon icon={ICONS.drag} scale="s" />
</span>
<InteractiveContainer disabled={this.disabled}>
<span
// Needs to be a span because of https://github.com/SortableJS/Sortable/issues/1486
aria-checked={this.disabled ? null : toAriaBoolean(this.selected)}
aria-disabled={this.disabled ? toAriaBoolean(this.disabled) : null}
aria-label={this.disabled ? null : this.getAriaText("label")}
class={{ [CSS.handle]: true, [CSS.handleSelected]: !this.disabled && this.selected }}
onBlur={this.handleBlur}
onKeyDown={this.handleKeyDown}
ref={(el): void => {
this.handleButton = el;
}}
// role of radio is being applied to allow space key to select in screen readers
role="radio"
tabIndex={this.disabled ? null : 0}
title={this.getTooltip()}
>
<calcite-icon icon={ICONS.drag} scale="s" />
</span>
</InteractiveContainer>
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,6 @@ export class Slider

return (
<div
aria-disabled={this.disabled}
Copy link
Member Author

@driskull driskull Sep 24, 2024

Choose a reason for hiding this comment

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

This one wasn't using toAriaBoolean so it wasn't working. I think that means we can safely remove it.

aria-label={ariaLabel}
aria-orientation="horizontal"
aria-valuemax={this.max}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ export class TableCell
<Host>
<InteractiveContainer disabled={this.disabled}>
<td
aria-disabled={this.disabled}
Copy link
Member Author

@driskull driskull Sep 24, 2024

Choose a reason for hiding this comment

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

This one wasn't using toAriaBoolean so it wasn't working. I think that means we can safely remove it.

class={{
[CSS.footerCell]: this.parentRowType === "foot",
[CSS.contentCell]: !this.numberCell && !this.selectionCell,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,6 @@ export class TableRow implements InteractiveComponent, LocalizedComponent {
<Host>
<InteractiveContainer disabled={this.disabled}>
<tr
aria-disabled={this.disabled}
Copy link
Member Author

@driskull driskull Sep 24, 2024

Choose a reason for hiding this comment

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

This one wasn't using toAriaBoolean so it wasn't working. I think that means we can safely remove it.

aria-rowindex={this.positionAll + 1}
aria-selected={this.selected}
class={{ [CSS.lastVisibleRow]: this.lastVisibleRow }}
Expand Down
Loading