Skip to content

Commit

Permalink
fix(button): Sets aria-disabled instead of disabled on internal ancho…
Browse files Browse the repository at this point in the history
…r element. #8140
  • Loading branch information
driskull committed Nov 27, 2023
1 parent a7aeb37 commit b60728c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
27 changes: 27 additions & 0 deletions packages/calcite-components/src/components/button/button.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,33 @@ describe("calcite-button", () => {
hidden("calcite-button");
});

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

let elementAsButton = await page.find("calcite-button >>> button");
let elementAsLink = await page.find("calcite-button >>> a");

expect(elementAsButton).not.toBeNull();
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");
await page.waitForChanges();

elementAsButton = await page.find("calcite-button >>> button");
elementAsLink = await page.find("calcite-button >>> a");

expect(elementAsButton).toBeNull();
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 () => {
const page = await newE2EPage();
await page.setContent(`<calcite-button>Continue</calcite-button>`);
Expand Down
4 changes: 3 additions & 1 deletion packages/calcite-components/src/components/button/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
unwatchGlobalAttributes,
watchGlobalAttributes,
} from "../../utils/globalAttributes";
import { toAriaBoolean } from "../../utils/dom";

/** Passing a 'href' will render an anchor link, instead of a button. Role will be set to link, or button, depending on this. */
/** It is the consumers responsibility to add aria information, rel, target, for links, and any button attributes for form submission */
Expand Down Expand Up @@ -258,6 +259,7 @@ export class Button

return (
<Tag
aria-disabled={childElType === "a" ? toAriaBoolean(this.disabled || this.loading) : null}
aria-label={!this.loading ? getLabelText(this) : this.messages.loading}
aria-live="polite"
class={{
Expand All @@ -267,7 +269,7 @@ export class Button
[CSS.iconStartEmpty]: !this.iconStart,
[CSS.iconEndEmpty]: !this.iconEnd,
}}
disabled={this.disabled || this.loading}
disabled={childElType === "button" ? this.disabled || this.loading : null}
href={childElType === "a" && this.href}
name={childElType === "button" && this.name}
onClick={this.handleClick}
Expand Down

0 comments on commit b60728c

Please sign in to comment.