Skip to content

Commit 48f29e1

Browse files
authored
Make order of tailwind variants match default (#5478)
1 parent 963e75f commit 48f29e1

File tree

2 files changed

+156
-143
lines changed

2 files changed

+156
-143
lines changed

packages/tailwindcss-react-aria-components/src/index.js

+42-29
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,45 @@
11
import plugin from 'tailwindcss/plugin';
22

3+
// Order of these is important because it determines which states win in a conflict.
4+
// We mostly follow Tailwind's defaults, adding our additional states following the categories they define.
5+
// https://github.com/tailwindlabs/tailwindcss/blob/304c2bad6cb5fcb62754a4580b1c8f4c16b946ea/src/corePlugins.js#L83
36
const attributes = {
47
boolean: [
5-
['hover', 'hovered'],
6-
['focus', 'focused'],
7-
'focus-visible',
8-
'focus-within',
9-
'pressed',
10-
'disabled',
11-
'drop-target',
12-
'dragging',
13-
'empty',
14-
'allows-dragging',
8+
// Conditions
159
'allows-removing',
1610
'allows-sorting',
17-
['placeholder-shown', 'placeholder'],
18-
'selected',
19-
'indeterminate',
20-
['read-only', 'readonly'],
21-
'required',
11+
'allows-dragging',
12+
13+
// States
14+
'open',
2215
'entering',
2316
'exiting',
24-
'open',
17+
'indeterminate',
18+
['placeholder-shown', 'placeholder'],
19+
'current',
20+
'required',
2521
'unavailable',
22+
'invalid',
23+
['read-only', 'readonly'],
2624
'outside-month',
2725
'outside-visible-range',
26+
27+
// Content
28+
'empty',
29+
30+
// Interactive states
31+
'focus-within',
32+
['hover', 'hovered'],
33+
['focus', 'focused'],
34+
'focus-visible',
35+
'pressed',
36+
'selected',
2837
'selection-start',
2938
'selection-end',
30-
'current',
31-
'invalid',
32-
'resizing'
39+
'dragging',
40+
'drop-target',
41+
'resizing',
42+
'disabled'
3343
],
3444
enum: {
3545
placement: ['left', 'right', 'top', 'bottom'],
@@ -100,21 +110,24 @@ let addVariants = (variantName, selectors, addVariant, matchVariant) => {
100110

101111
module.exports = plugin.withOptions((options) => (({addVariant, matchVariant}) => {
102112
let prefix = options?.prefix ? `${options.prefix}-` : '';
113+
114+
// Enum attributes go first because currently they are all non-interactive states.
115+
Object.keys(attributes.enum).forEach((attributeName) => {
116+
attributes.enum[attributeName].forEach(
117+
(attributeValue) => {
118+
let name = shortNames[attributeName] || attributeName;
119+
let variantName = `${prefix}${name}-${attributeValue}`;
120+
let selectors = getSelector(prefix, attributeName, attributeValue);
121+
addVariants(variantName, selectors, addVariant, matchVariant);
122+
}
123+
);
124+
});
125+
103126
attributes.boolean.forEach((attribute) => {
104127
let variantName = Array.isArray(attribute) ? attribute[0] : attribute;
105128
variantName = `${prefix}${variantName}`;
106129
let attributeName = Array.isArray(attribute) ? attribute[1] : attribute;
107130
let selectors = getSelector(prefix, attributeName);
108131
addVariants(variantName, selectors, addVariant, matchVariant);
109132
});
110-
Object.keys(attributes.enum).forEach((attributeName) => {
111-
attributes.enum[attributeName].forEach(
112-
(attributeValue) => {
113-
let name = shortNames[attributeName] || attributeName;
114-
let variantName = `${prefix}${name}-${attributeValue}`;
115-
let selectors = getSelector(prefix, attributeName, attributeValue);
116-
addVariants(variantName, selectors, addVariant, matchVariant);
117-
}
118-
);
119-
});
120133
}));

0 commit comments

Comments
 (0)