Skip to content

Commit 967908b

Browse files
author
João Dias
committed
feat(useAutoId): removed colons from react generated id
1 parent 029a0ed commit 967908b

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

cypress/test/hooks/use-auto-id.cy.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ describe("useAutoId", () => {
8181

8282
cy.findByText("A paragraph")
8383
.invoke("attr", "id")
84-
.should("match", /^fdz-prefix--:?[a-z0-9:]+:?$/);
84+
.should("match", /^fdz-prefix--[a-z0-9]+$/);
8585
});
8686

8787
context("React <18 (no useId support)", () => {
@@ -123,18 +123,18 @@ describe("useAutoId", () => {
123123

124124
cy.findByText("A paragraph")
125125
.invoke("attr", "id")
126-
.should("match", /^:?[a-z0-9:]+:?$/);
126+
.should("match", /^[a-z0-9]+$/);
127127
cy.findByText("An inline span element")
128128
.invoke("attr", "id")
129-
.should("match", /^:?[a-z0-9:]+:?$/);
129+
.should("match", /^[a-z0-9]+$/);
130130
});
131131

132132
it("applies prefix to ID generated by React.useId", () => {
133133
cy.mount(<DemoComponent prefix="fdz-js-prefix" />);
134134

135135
cy.findByText("A paragraph")
136136
.invoke("attr", "id")
137-
.should("match", /^fdz-js-prefix--:?[a-z0-9:]+:?$/);
137+
.should("match", /^fdz-js-prefix--[a-z0-9]+$/);
138138
});
139139

140140
it("uses static fallback ID when explicitly provided", () => {

src/hooks/use-auto-id.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export function useAutoId(
8787
}
8888
});
8989

90-
const baseId = customId ?? reactId ?? generatedId;
90+
const baseId = customId ?? reactId?.replace(/:/g, "") ?? generatedId;
9191

9292
return useMemo(() => {
9393
return prefix ? makeId(prefix, baseId) : baseId;

0 commit comments

Comments
 (0)