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 (