Skip to content

Commit 69eb306

Browse files
authored
Fix id generation issue for snapshot testing (#37)
1 parent 111a51d commit 69eb306

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "0.2.23",
2+
"version": "0.2.24",
33
"license": "MIT",
44
"main": "dist/index.js",
55
"typings": "dist/index.d.ts",

src/card/Card.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ export type CardProps = {
3838
titleExtra?: ReactNode;
3939
collapsible?: boolean;
4040
defaultOpen?: boolean;
41+
onToggle?: (open: boolean) => void;
42+
id?: string;
4143
};
4244

4345
export function Card({
@@ -51,11 +53,12 @@ export function Card({
5153
titleExtra,
5254
collapsible,
5355
defaultOpen = true,
56+
id,
5457
}: CardProps) {
5558
const [isOpen, setIsOpen] = useState(defaultOpen);
56-
const id = useId();
57-
const contentId = `${id}-content`,
58-
headerId = `${id}-heading`;
59+
const idPrefix = useId(id);
60+
const contentId = `${idPrefix}-content`,
61+
headerId = `${idPrefix}-heading`;
5962
const defaultTitle = (
6063
<Text textSize="xlarge" elementType="h3" weight="heavy">
6164
{title}
@@ -105,7 +108,7 @@ export function Card({
105108
'is-open': isOpen,
106109
})}
107110
>
108-
<header css={headerCSS({ bordered: true })}>
111+
<header css={headerCSS({ bordered: true })} id={headerId}>
109112
{titleComponent}
110113
{extra}
111114
</header>

0 commit comments

Comments
 (0)