Skip to content

Commit 99a1f0e

Browse files
committed
fix(button): omit href when disabled to avoid invalid <button href>
1 parent 44fcfef commit 99a1f0e

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

src/Button/Button.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@
152152
type: href && !disabled ? undefined : type,
153153
tabindex,
154154
disabled: disabled === true ? true : undefined,
155-
href,
155+
href: href && !disabled ? href : undefined,
156156
"aria-pressed":
157157
hasIconOnly && kind === "ghost" && !href ? isSelected : undefined,
158158
...$$restProps,

tests/Button/Button.test.svelte

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434

3535
<Button disabled>Disabled button</Button>
3636

37+
<Button data-testid="btn-disabled-href" href="#" disabled>
38+
Disabled link button
39+
</Button>
40+
3741
<Button icon={Add}>With icon</Button>
3842

3943
<Button

tests/Button/Button.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ describe("Button", () => {
8080
expect(disabledButton).toHaveClass("bx--btn--disabled");
8181
});
8282

83+
it("should strip href when disabled is also set", () => {
84+
render(Button);
85+
86+
const button = screen.getByTestId("btn-disabled-href");
87+
expect(button.tagName).toBe("BUTTON");
88+
expect(button).toBeDisabled();
89+
expect(button).not.toHaveAttribute("href");
90+
});
91+
8392
it("should render skeleton state", () => {
8493
render(Button);
8594

0 commit comments

Comments
 (0)