Skip to content

Commit e4efa12

Browse files
committed
fix: headless ui classnames
1 parent fb446d0 commit e4efa12

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

components/react/__tests__/__snapshots__/ModalDialog.test.tsx.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ exports[`ModalDialog renders correctly: portal 1`] = `
88
class="modal modal-open fixed flex p-0 m-0 top-0 left-0 undefined"
99
data-headlessui-state="open"
1010
data-open=""
11-
id="headlessui-dialog-«r3m»"
11+
id="headlessui-dialog-«normalized»"
1212
role="dialog"
1313
style="background-color: transparent; align-items: center; justify-content: center; height: 100vh; width: 100vw;"
1414
tabindex="-1"
@@ -22,7 +22,7 @@ exports[`ModalDialog renders correctly: portal 1`] = `
2222
class="undefined modal-box mx-auto rounded-[24px] bg-[#F4F4FF] dark:bg-[#1D192D] shadow-lg relative"
2323
data-headlessui-state="open"
2424
data-open=""
25-
id="headlessui-dialog-panel-«r3t»"
25+
id="headlessui-dialog-panel-«normalized»"
2626
>
2727
bound HTMLFormElement {
2828
"0": <button

tests/format.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { format as prettyFormat, plugins as prettyFormatPlugins } from 'pretty-format';
22

33
export function formatComponent(value: any): string {
4-
return prettyFormat(value, {
4+
const formatted = prettyFormat(value, {
55
escapeRegex: true,
66
indent: 2,
77
plugins: [
@@ -14,4 +14,14 @@ export function formatComponent(value: any): string {
1414
],
1515
printFunctionName: false,
1616
});
17+
18+
// Normalize dynamic Headless UI IDs for consistent snapshots
19+
return formatted
20+
.replace(/headlessui-dialog-«r\w+»/g, 'headlessui-dialog-«normalized»')
21+
.replace(/headlessui-dialog-panel-«r\w+»/g, 'headlessui-dialog-panel-«normalized»')
22+
.replace(/headlessui-\w+-«r\w+»/g, match => {
23+
// Handle other headless UI components like headlessui-menu-«rXX», etc.
24+
const componentType = match.split('-')[1];
25+
return `headlessui-${componentType}-«normalized»`;
26+
});
1727
}

0 commit comments

Comments
 (0)