From 8e049bc21ea87dbe0bb8bfabb63202b9ef67734e Mon Sep 17 00:00:00 2001 From: jbpenrath Date: Wed, 6 Aug 2025 17:01:30 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B(react)=20disable=20button=20link?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit According to its prop, the Button component can be rendered as a link but in this case, the prop `disabled` has no effect. So to fix that if the Button receives a `href` prop and is disabled, we apply a modifier class `.c__button--disabled`. --- .changeset/fresh-dots-happen.md | 5 +++++ packages/react/src/components/Button/_index.scss | 2 +- packages/react/src/components/Button/index.spec.tsx | 11 +++++++++++ .../react/src/components/Button/index.stories.tsx | 10 ++++++++++ packages/react/src/components/Button/index.tsx | 3 +++ 5 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 .changeset/fresh-dots-happen.md diff --git a/.changeset/fresh-dots-happen.md b/.changeset/fresh-dots-happen.md new file mode 100644 index 0000000..05ad483 --- /dev/null +++ b/.changeset/fresh-dots-happen.md @@ -0,0 +1,5 @@ +--- +"@openfun/cunningham-react": patch +--- + +Apply disable style to disabled button link diff --git a/packages/react/src/components/Button/_index.scss b/packages/react/src/components/Button/_index.scss index b26aa2a..bd0eed4 100644 --- a/packages/react/src/components/Button/_index.scss +++ b/packages/react/src/components/Button/_index.scss @@ -32,7 +32,7 @@ border-color: currentColor; } - &:disabled { + &:disabled, &.c__button--disabled { background-color: var(--c--theme--colors--greyscale-200); color: var(--c--theme--colors--greyscale-600); cursor: not-allowed; diff --git a/packages/react/src/components/Button/index.spec.tsx b/packages/react/src/components/Button/index.spec.tsx index 5f46e32..b715ea8 100644 --- a/packages/react/src/components/Button/index.spec.tsx +++ b/packages/react/src/components/Button/index.spec.tsx @@ -60,11 +60,22 @@ describe(", ); const button = screen.getByRole("button", { name: "Test button" }); + expect(button).toHaveAttribute("disabled"); expect(handleClick).not.toBeCalled(); await act(async () => user.click(button)); expect(handleClick).not.toHaveBeenCalled(); }); + it("renders disabled link", async () => { + render( + , + ); + const button = screen.getByRole("link", { name: "Test button link" }); + expect(button.classList).toContain("c__button--disabled"); + }); + it("renders as link when href is used", () => { render(