From eaef1c029f4a9a49ba2ff0cd868fe39f576b56d6 Mon Sep 17 00:00:00 2001 From: kanakkholwal Date: Thu, 19 Nov 2026 16:45:25 +0530 Subject: [PATCH] feat(Card): expose selected state via data-selected --- .changeset/feat-card-data-selected.md | 5 +++++ .../CardHorizontal/CardHorizontal.test.tsx | 12 ++++++++++++ src/components/CardHorizontal/CardHorizontal.tsx | 1 + src/components/CardPrimary/CardPrimary.test.tsx | 8 ++++++++ src/components/CardPrimary/CardPrimary.tsx | 1 + 5 files changed, 27 insertions(+) create mode 100644 .changeset/feat-card-data-selected.md diff --git a/.changeset/feat-card-data-selected.md b/.changeset/feat-card-data-selected.md new file mode 100644 index 000000000..a1700344b --- /dev/null +++ b/.changeset/feat-card-data-selected.md @@ -0,0 +1,5 @@ +--- +'@clickhouse/click-ui': minor +--- + +`CardPrimary` and `CardHorizontal` now set `data-selected="true"` when `isSelected` is on, so tests can tell a selected card without relying on class names. diff --git a/src/components/CardHorizontal/CardHorizontal.test.tsx b/src/components/CardHorizontal/CardHorizontal.test.tsx index 1a6d8e4f1..3b62fb4aa 100644 --- a/src/components/CardHorizontal/CardHorizontal.test.tsx +++ b/src/components/CardHorizontal/CardHorizontal.test.tsx @@ -11,6 +11,18 @@ describe('CardHorizontal Component', () => { vitest.restoreAllMocks(); }); + it('should expose selection through data-selected', () => { + const { container, rerender } = renderCard({ + title: 'Card', + isSelectable: true, + isSelected: true, + }); + expect(container.querySelector('[data-selected="true"]')).not.toBeNull(); + + rerender(); + expect(container.querySelector('[data-selected]')).toBeNull(); + }); + it('should render the title', () => { const title = 'Test card component'; renderCard({ diff --git a/src/components/CardHorizontal/CardHorizontal.tsx b/src/components/CardHorizontal/CardHorizontal.tsx index d6693ac86..f66c5488d 100644 --- a/src/components/CardHorizontal/CardHorizontal.tsx +++ b/src/components/CardHorizontal/CardHorizontal.tsx @@ -130,6 +130,7 @@ export const CardHorizontal = ({
{ vitest.restoreAllMocks(); }); + it('should expose selection through data-selected', () => { + const { container, rerender } = renderCard({ title: 'Card', isSelected: true }); + expect(container.querySelector('[data-selected="true"]')).not.toBeNull(); + + rerender(); + expect(container.querySelector('[data-selected]')).toBeNull(); + }); + it('should render the title', () => { const title = 'Test card component'; renderCard({ diff --git a/src/components/CardPrimary/CardPrimary.tsx b/src/components/CardPrimary/CardPrimary.tsx index 942a5387e..aa22c02e4 100644 --- a/src/components/CardPrimary/CardPrimary.tsx +++ b/src/components/CardPrimary/CardPrimary.tsx @@ -111,6 +111,7 @@ const Card = ({ return (