MCPcopy Create free account
hub / github.com/adobe/react-spectrum / getSelector

Function getSelector

packages/tailwindcss-react-aria-components/src/index.js:91–119  ·  view source on GitHub ↗
(prefix, attributeName, attributeValue)

Source from the content-addressed store, hash-verified

89
90// If no prefix is specified, we want to avoid overriding native variants on non-RAC components, so we only target elements with the data-rac attribute for those variants.
91let getSelector = (prefix, attributeName, attributeValue) => {
92 let baseSelector = attributeValue
93 ? `[data-${attributeName}="${attributeValue}"]`
94 : `[data-${attributeName}]`;
95 let nativeSelector = nativeVariantSelectors.get(attributeName);
96 if (prefix === '' && nativeSelector) {
97 // Collapse the RAC and native branches into a single `:is()` so `not-*`
98 // works — Tailwind's `not` walker bails on a dual-selector (array) shape.
99 // `:where()` keeps specificity at (0,1,0).
100 let unifiedSelector = `&:is(:where([data-rac])${baseSelector}, :where(:not([data-rac]))${nativeSelector})`;
101 // Hover needs `@media (hover: hover)` to avoid sticky styles on touch.
102 // Emitted as CSS-in-JS (not `@media ... { & }`) so Tailwind reports
103 // compounds as `StyleRules | AtRules`, keeping `group-hover:`/`peer-hover:`
104 // composable while still letting `not-hover:` invert cleanly.
105 if (nativeSelector === ':hover') {
106 return {
107 '@media (hover: hover)': {
108 [unifiedSelector]: '@slot'
109 }
110 };
111 }
112 return unifiedSelector;
113 } else if (prefix === '' && nativeMergeSelectors.has(attributeName)) {
114 // Same `:is()` collapse for merge selectors (e.g. placeholder).
115 return `&:is(${baseSelector}, ${nativeMergeSelectors.get(attributeName)})`;
116 } else {
117 return `&${baseSelector}`;
118 }
119};
120
121let addVariants = (variantName, selectors, addVariant) => {
122 addVariant(variantName, selectors);

Callers 1

index.jsFile · 0.85

Calls 1

hasMethod · 0.65

Tested by

no test coverage detected