Skip to content

Commit b37dfc9

Browse files
authored
[core] Refactor data-state to individual attributes (#739)
1 parent e567deb commit b37dfc9

33 files changed

+93
-105
lines changed

docs/data/components/alert-dialog/alert-dialog.mdx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ Here is an example of how to apply a symmetric scale and fade transition with th
144144
Styles need to be applied in three states:
145145

146146
- The exiting styles, placed on the base element class
147-
- The open styles, placed on the base element class with `[data-state="open"]`
147+
- The open styles, placed on the base element class with `[data-open]`
148148
- The entering styles, placed on the base element class with `[data-entering]`
149149

150150
<Demo demo="AlertDialogWithTransitions" />
@@ -226,8 +226,7 @@ function App() {
226226

227227
Four states are available as data attributes to animate the dialog, which enables full control depending on whether the popup is being animated with CSS transitions or animations, JavaScript, or is using the `keepMounted` prop.
228228

229-
- `[data-state="open"]` - `open` state is `true`.
230-
- `[data-state="closed"]` - `open` state is `false`. Can still be mounted to the DOM if closing.
229+
- `[data-open]` - `open` state is `true`.
231230
- `[data-entering]` - the popup was just inserted to the DOM. The attribute is removed 1 animation frame later. Enables "starting styles" upon insertion for conditional rendering.
232231
- `[data-exiting]` - the popup is in the process of being removed from the DOM, but is still mounted.
233232

docs/data/components/collapsible/CssAnimatedCollapsible.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export function Styles() {
9797
transform-origin: center 45%;
9898
}
9999
100-
.CssAnimatedCollapsible-trigger[data-state="open"] svg {
100+
.CssAnimatedCollapsible-trigger[data-open] svg {
101101
transform: rotate(90deg);
102102
}
103103
@@ -110,10 +110,10 @@ export function Styles() {
110110
padding: 0 1rem;
111111
}
112112
113-
.CssAnimatedCollapsible-content[data-state='open'] {
113+
.CssAnimatedCollapsible-content[data-open] {
114114
animation: slideDown 300ms ease-out;
115115
}
116-
.CssAnimatedCollapsible-content[data-state='closed'] {
116+
.CssAnimatedCollapsible-content[data-closed] {
117117
animation: slideUp 300ms ease-out;
118118
}
119119

docs/data/components/collapsible/CssAnimatedCollapsible.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export function Styles() {
9797
transform-origin: center 45%;
9898
}
9999
100-
.CssAnimatedCollapsible-trigger[data-state="open"] svg {
100+
.CssAnimatedCollapsible-trigger[data-open] svg {
101101
transform: rotate(90deg);
102102
}
103103
@@ -110,10 +110,10 @@ export function Styles() {
110110
padding: 0 1rem;
111111
}
112112
113-
.CssAnimatedCollapsible-content[data-state='open'] {
113+
.CssAnimatedCollapsible-content[data-open] {
114114
animation: slideDown 300ms ease-out;
115115
}
116-
.CssAnimatedCollapsible-content[data-state='closed'] {
116+
.CssAnimatedCollapsible-content[data-closed] {
117117
animation: slideUp 300ms ease-out;
118118
}
119119

docs/data/components/collapsible/CssTransitionCollapsible.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export function Styles() {
9797
transform-origin: center 45%;
9898
}
9999
100-
.CssTransitionCollapsible-trigger[data-state="open"] svg {
100+
.CssTransitionCollapsible-trigger[data-open] svg {
101101
transform: rotate(90deg);
102102
}
103103
@@ -110,12 +110,12 @@ export function Styles() {
110110
padding: 0 1rem;
111111
}
112112
113-
.CssTransitionCollapsible-content[data-state='open'] {
113+
.CssTransitionCollapsible-content[data-open] {
114114
height: var(--collapsible-content-height);
115115
transition: height 200ms ease-out;
116116
}
117117
118-
.CssTransitionCollapsible-content[data-state='closed'] {
118+
.CssTransitionCollapsible-content[data-closed] {
119119
height: 0;
120120
transition: height 200ms ease-in;
121121
}

docs/data/components/collapsible/CssTransitionCollapsible.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export function Styles() {
9797
transform-origin: center 45%;
9898
}
9999
100-
.CssTransitionCollapsible-trigger[data-state="open"] svg {
100+
.CssTransitionCollapsible-trigger[data-open] svg {
101101
transform: rotate(90deg);
102102
}
103103
@@ -110,12 +110,12 @@ export function Styles() {
110110
padding: 0 1rem;
111111
}
112112
113-
.CssTransitionCollapsible-content[data-state='open'] {
113+
.CssTransitionCollapsible-content[data-open] {
114114
height: var(--collapsible-content-height);
115115
transition: height 200ms ease-out;
116116
}
117117
118-
.CssTransitionCollapsible-content[data-state='closed'] {
118+
.CssTransitionCollapsible-content[data-closed] {
119119
height: 0;
120120
transition: height 200ms ease-in;
121121
}

docs/data/components/collapsible/UnstyledCollapsibleIntroduction.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const CollapsibleTrigger = styled(BaseCollapsible.Trigger)`
1616
margin-top: 1px;
1717
}
1818
19-
&[data-state='open'] svg {
19+
&[data-open] svg {
2020
transform: rotate(180deg);
2121
}
2222
`;

docs/data/components/collapsible/UnstyledCollapsibleIntroduction.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const CollapsibleTrigger = styled(BaseCollapsible.Trigger)`
1616
margin-top: 1px;
1717
}
1818
19-
&[data-state='open'] svg {
19+
&[data-open] svg {
2020
transform: rotate(180deg);
2121
}
2222
`;

docs/data/components/collapsible/collapsible.mdx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ This relies on the HTML `hidden="until-found"` attribute which only has [partial
6363
6464
Four states are available as data attributes to animate the Collapsible:
6565
66-
- `[data-state="open"]` - `open` state is `true`.
67-
- `[data-state="closed"]` - `open` state is `false`. Can still be mounted to the DOM if closing.
66+
- `[data-open]` - `open` state is `true`.
67+
- `[data-closed]` - `open` state is `false`. Can still be mounted to the DOM if closing.
6868
- `[data-entering]` - the `hidden` attribute was just removed from the DOM and the content element participates in page layout. The `data-entering` attribute will be removed 1 animation frame later.
6969
- `[data-exiting]` - the content element is in the process of being hidden from the DOM, but is still mounted.
7070
@@ -85,11 +85,11 @@ CSS animations can be used with two declarations:
8585
overflow: hidden;
8686
}
8787
88-
.Collapsible-content[data-state='open'] {
88+
.Collapsible-content[data-open] {
8989
animation: slideDown 300ms ease-out;
9090
}
9191
92-
.Collapsible-content[data-state='closed'] {
92+
.Collapsible-content[data-closed] {
9393
animation: slideUp 300ms ease-in;
9494
}
9595
@@ -118,16 +118,16 @@ CSS animations can be used with two declarations:
118118
119119
When using CSS transitions, styles for the `Content` subcomponent must be applied to three states:
120120
121-
- The closed styles with `[data-state="closed"]`
122-
- The open styles with `[data-state="open"]`
121+
- The closed styles with `[data-closed]`
122+
- The open styles with `[data-open]`
123123
- The entering styles with `[data-entering]`
124124
125125
```css
126126
.Collapsible-content {
127127
overflow: hidden;
128128
}
129129
130-
.Collapsible2-content[data-state='open'] {
130+
.Collapsible2-content[data-open] {
131131
height: var(--collapsible-content-height);
132132
transition: height 300ms ease-out;
133133
}
@@ -136,7 +136,7 @@ When using CSS transitions, styles for the `Content` subcomponent must be applie
136136
height: 0;
137137
}
138138
139-
.Collapsible2-content[data-state='closed'] {
139+
.Collapsible2-content[data-closed] {
140140
height: 0;
141141
transition: height 300ms ease-in;
142142
}

docs/data/components/dialog/dialog.mdx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ Here is an example of how to apply a symmetric scale and fade transition with th
167167
Styles need to be applied in three states:
168168

169169
- The exiting styles, placed on the base element class
170-
- The open styles, placed on the base element class with `[data-state="open"]`
170+
- The open styles, placed on the base element class with `[data-open]`
171171
- The entering styles, placed on the base element class with `[data-entering]`
172172

173173
<Demo demo="DialogWithTransitions" />
@@ -249,8 +249,7 @@ function App() {
249249

250250
Four states are available as data attributes to animate the dialog, which enables full control depending on whether the popup is being animated with CSS transitions or animations, JavaScript, or is using the `keepMounted` prop.
251251

252-
- `[data-state="open"]` - `open` state is `true`.
253-
- `[data-state="closed"]` - `open` state is `false`. Can still be mounted to the DOM if closing.
252+
- `[data-open]` - `open` state is `true`.
254253
- `[data-entering]` - the popup was just inserted to the DOM. The attribute is removed 1 animation frame later. Enables "starting styles" upon insertion for conditional rendering.
255254
- `[data-exiting]` - the popup is in the process of being removed from the DOM, but is still mounted.
256255

docs/data/components/menu/MenuIntroduction/css-modules/Menu.module.css

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
&:focus-visible {
55
outline: 0;
66
}
7-
8-
&[data-state='closed'] {
9-
pointer-events: none;
10-
}
117
}
128

139
.popup {
@@ -25,6 +21,11 @@
2521
color: var(--gray-900);
2622
box-shadow: 0px 4px 30px var(--gray-200);
2723
transform-origin: var(--transform-origin);
24+
opacity: 0;
25+
transform: scale(0.95, 0.8);
26+
transition:
27+
opacity 200ms ease-in,
28+
transform 200ms ease-in;
2829

2930
:global(.dark) & {
3031
background: var(--gray-900);
@@ -33,14 +34,6 @@
3334
box-shadow: 0px 4px 30px var(--gray-900);
3435
}
3536

36-
&[data-state='closed'] {
37-
opacity: 0;
38-
transform: scale(0.95, 0.8);
39-
transition:
40-
opacity 200ms ease-in,
41-
transform 200ms ease-in;
42-
}
43-
4437
&[data-open] {
4538
opacity: 1;
4639
transform: scale(1, 1);

docs/data/components/menu/MenuIntroduction/system/index.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,6 @@ const MenuPositioner = styled(Menu.Positioner)`
152152
&:focus-visible {
153153
outline: 0;
154154
}
155-
156-
&[data-state='closed'] {
157-
pointer-events: none;
158-
}
159155
`;
160156

161157
export const MenuArrow = styled(Menu.Arrow)(

docs/data/components/menu/MenuIntroduction/system/index.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,6 @@ const MenuPositioner = styled(Menu.Positioner)`
152152
&:focus-visible {
153153
outline: 0;
154154
}
155-
156-
&[data-state='closed'] {
157-
pointer-events: none;
158-
}
159155
`;
160156

161157
export const MenuArrow = styled(Menu.Arrow)(

docs/data/components/menu/NestedMenu.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,6 @@ const MenuPositioner = styled(Menu.Positioner)`
157157
&:focus-visible {
158158
outline: 0;
159159
}
160-
161-
&[data-state='closed'] {
162-
pointer-events: none;
163-
}
164160
`;
165161

166162
const MenuItem = styled(Menu.Item)(

docs/data/components/menu/NestedMenu.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,6 @@ const MenuPositioner = styled(Menu.Positioner)`
157157
&:focus-visible {
158158
outline: 0;
159159
}
160-
161-
&[data-state='closed'] {
162-
pointer-events: none;
163-
}
164160
`;
165161

166162
const MenuItem = styled(Menu.Item)(

docs/data/components/menu/menu.mdx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ Here is an example of how to apply a symmetric scale and fade transition with th
323323
Styles need to be applied in three states:
324324

325325
- The exiting styles, placed on the base element class
326-
- The open styles, placed on the base element class with `[data-state="open"]`
326+
- The open styles, placed on the base element class with `[data-open]`
327327
- The entering styles, placed on the base element class with `[data-entering]`
328328

329329
In newer browsers, there is a feature called `@starting-style` which allows transitions to occur on open for conditionally-mounted components:
@@ -409,8 +409,7 @@ function App() {
409409

410410
Four states are available as data attributes to animate the popup, which enables full control depending on whether the popup is being animated with CSS transitions or animations, JavaScript, or is using the `keepMounted` prop.
411411

412-
- `[data-state="open"]` - `open` state is `true`.
413-
- `[data-state="closed"]` - `open` state is `false`. Can still be mounted to the DOM if closing.
412+
- `[data-open]` - `open` state is `true`.
414413
- `[data-entering]` - the popup was just inserted to the DOM. The attribute is removed 1 animation frame later. Enables "starting styles" upon insertion for conditional rendering.
415414
- `[data-exiting]` - the popup is in the process of being removed from the DOM, but is still mounted.
416415

docs/data/components/popover/popover.mdx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ Here is an example of how to apply a symmetric scale and fade transition with th
318318
Styles need to be applied in three states:
319319

320320
- The exiting styles, placed on the base element class
321-
- The open styles, placed on the base element class with `[data-state="open"]`
321+
- The open styles, placed on the base element class with `[data-open]`
322322
- The entering styles, placed on the base element class with `[data-entering]`
323323

324324
<Demo demo="UnstyledPopoverTransition" defaultCodeOpen={false} />
@@ -405,8 +405,7 @@ function App() {
405405

406406
Four states are available as data attributes to animate the popup, which enables full control depending on whether the popup is being animated with CSS transitions or animations, JavaScript, or is using the `keepMounted` prop.
407407

408-
- `[data-state="open"]` - `open` state is `true`.
409-
- `[data-state="closed"]` - `open` state is `false`. Can still be mounted to the DOM if closing.
408+
- `[data-open]` - `open` state is `true`.
410409
- `[data-entering]` - the popup was just inserted to the DOM. The attribute is removed 1 animation frame later. Enables "starting styles" upon insertion for conditional rendering.
411410
- `[data-exiting]` - the popup is in the process of being removed from the DOM, but is still mounted.
412411

docs/data/components/preview-card/preview-card.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ Here is an example of how to apply a symmetric scale and fade transition with th
268268
Styles need to be applied in three states:
269269

270270
- The exiting styles, placed on the base element class
271-
- The open styles, placed on the base element class with `[data-state="open"]`
271+
- The open styles, placed on the base element class with `[data-open]`
272272
- The entering styles, placed on the base element class with `[data-entering]`
273273

274274
<Demo demo="UnstyledPreviewCardTransition" defaultCodeOpen={false} />
@@ -355,8 +355,8 @@ function App() {
355355

356356
Four states are available as data attributes to animate the popup, which enables full control depending on whether the popup is being animated with CSS transitions or animations, JavaScript, or is using the `keepMounted` prop.
357357

358-
- `[data-state="open"]` - `open` state is `true`.
359-
- `[data-state="closed"]` - `open` state is `false`. Can still be mounted to the DOM if closing.
358+
- `[data-open]` - `open` state is `true`.
359+
- `[data-closed]` - `open` state is `false`. Can still be mounted to the DOM if closing.
360360
- `[data-entering]` - the popup was just inserted to the DOM. The attribute is removed 1 animation frame later. Enables "starting styles" upon insertion for conditional rendering.
361361
- `[data-exiting]` - the popup is in the process of being removed from the DOM, but is still mounted.
362362

docs/data/components/progress/IndeterminateProgress.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const ProgressIndicator = styled(BaseProgress.Indicator)(
5151
background-color: ${theme.palette.mode === 'dark' ? BLUE400 : BLUE500};
5252
border-radius: inherit;
5353
54-
&[data-state='indeterminate'] {
54+
&[data-indeterminate] {
5555
width: 25%;
5656
animation: ${indeterminateProgress} 1.5s infinite ease-in-out;
5757
will-change: transform;

docs/data/components/progress/IndeterminateProgress.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const ProgressIndicator = styled(BaseProgress.Indicator)(
5151
background-color: ${theme.palette.mode === 'dark' ? BLUE400 : BLUE500};
5252
border-radius: inherit;
5353
54-
&[data-state='indeterminate'] {
54+
&[data-indeterminate] {
5555
width: 25%;
5656
animation: ${indeterminateProgress} 1.5s infinite ease-in-out;
5757
will-change: transform;

docs/data/components/progress/progress.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Progress
4141

4242
### Determinate
4343

44-
The `value` prop represents the percentage value of the Progress component. The default minimum and maximum values are `0` and `100`, and can be changed with the `min` and `max` props. When progress is determinate the `data-state` attribute is initially `'progressing'`, changing to `'complete'` when `value` equals `max`.
44+
The `value` prop represents the percentage value of the Progress component. The default minimum and maximum values are `0` and `100`, and can be changed with the `min` and `max` props. When progress is determinate the `data-progressing` attribute exists, changing to `data-complete` when `value` equals `max`.
4545

4646
```tsx
4747
function App() {
@@ -58,7 +58,7 @@ function App() {
5858

5959
### Indeterminate
6060

61-
Set `value` to `null` to configure an indeterminate progress bar. The `data-state` attribute will be set to `indeterminate`.
61+
Set `value` to `null` to configure an indeterminate progress bar. The `data-indeterminate` attribute will exist.
6262

6363
```tsx
6464
<Progress.Root value={null}>

docs/data/components/tooltip/tooltip.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ Here is an example of how to apply a symmetric scale and fade transition with th
246246
Styles need to be applied in three states:
247247

248248
- The exiting styles, placed on the base element class
249-
- The open styles, placed on the base element class with `[data-state="open"]`
249+
- The open styles, placed on the base element class with `[data-open]`
250250
- The entering styles, placed on the base element class with `[data-entering]`
251251

252252
<Demo demo="UnstyledTooltipTransition" defaultCodeOpen={false} />
@@ -333,8 +333,8 @@ function App() {
333333

334334
Four states are available as data attributes to animate the popup, which enables full control depending on whether the popup is being animated with CSS transitions or animations, JavaScript, or is using the `keepMounted` prop.
335335

336-
- `[data-state="open"]` - `open` state is `true`.
337-
- `[data-state="closed"]` - `open` state is `false`. Can still be mounted to the DOM if closing.
336+
- `[data-open]` - `open` state is `true`.
337+
- `[data-closed]` - `open` state is `false`. Can still be mounted to the DOM if closing.
338338
- `[data-entering]` - the popup was just inserted to the DOM. The attribute is removed 1 animation frame later. Enables "starting styles" upon insertion for conditional rendering.
339339
- `[data-exiting]` - the popup is in the process of being removed from the DOM, but is still mounted.
340340

0 commit comments

Comments
 (0)