File tree Expand file tree Collapse file tree 5 files changed +49
-1
lines changed Expand file tree Collapse file tree 5 files changed +49
-1
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
22
22
- Add ` forced-colors ` variant ([ #11694 ] ( https://github.com/tailwindlabs/tailwindcss/pull/11694 ) )
23
23
- Add ` appearance-auto ` utility ([ #12404 ] ( https://github.com/tailwindlabs/tailwindcss/pull/12404 ) )
24
24
- Add logical property values for ` float ` and ` clear ` utilities ([ #12480 ] ( https://github.com/tailwindlabs/tailwindcss/pull/12480 ) )
25
+ - Add ` * ` variant for targeting direct children ([ #12551 ] ( https://github.com/tailwindlabs/tailwindcss/pull/12551 ) )
25
26
26
27
### Changed
27
28
Original file line number Diff line number Diff line change @@ -278,7 +278,7 @@ impl<'a> Extractor<'a> {
278
278
}
279
279
280
280
// Allowed first characters.
281
- b'@' | b'!' | b'-' | b'<' | b'0' ..=b'9' | b'a' ..=b'z' | b'A' ..=b'Z' => {
281
+ b'@' | b'!' | b'-' | b'<' | b'0' ..=b'9' | b'a' ..=b'z' | b'A' ..=b'Z' | b'*' => {
282
282
// TODO: A bunch of characters that we currently support but maybe we only want it behind
283
283
// a flag. E.g.: '<sm'
284
284
// | '<' | '>' | '$' | '^' | '_'
@@ -329,6 +329,7 @@ impl<'a> Extractor<'a> {
329
329
| b'!'
330
330
| b'@'
331
331
| b'%'
332
+ | b'*'
332
333
if prev != b']' =>
333
334
{
334
335
/* TODO: The `b'@'` is necessary for custom separators like _@, maybe we can handle this in a better way... */
@@ -508,6 +509,15 @@ mod test {
508
509
assert_eq ! ( candidates, vec![ "hover:underline" ] ) ;
509
510
}
510
511
512
+ #[ test]
513
+ fn it_can_parse_start_variants ( ) {
514
+ let candidates = run ( "*:underline" , false ) ;
515
+ assert_eq ! ( candidates, vec![ "*:underline" ] ) ;
516
+
517
+ let candidates = run ( "hover:*:underline" , false ) ;
518
+ assert_eq ! ( candidates, vec![ "hover:*:underline" ] ) ;
519
+ }
520
+
511
521
#[ test]
512
522
fn it_can_parse_simple_candidates_with_stacked_variants ( ) {
513
523
let candidates = run ( "focus:hover:underline" , false ) ;
Original file line number Diff line number Diff line change @@ -25,6 +25,9 @@ import { normalize } from './util/dataTypes'
25
25
import { INTERNAL_FEATURES } from './lib/setupContextUtils'
26
26
27
27
export let variantPlugins = {
28
+ childVariant : ( { addVariant } ) => {
29
+ addVariant ( '*' , '& > *' )
30
+ } ,
28
31
pseudoElementVariants : ( { addVariant } ) => {
29
32
addVariant ( 'first-letter' , '&::first-letter' )
30
33
addVariant ( 'first-line' , '&::first-line' )
Original file line number Diff line number Diff line change @@ -756,6 +756,7 @@ function resolvePlugins(context, root) {
756
756
// TODO: This is a workaround for backwards compatibility, since custom variants
757
757
// were historically sorted before screen/stackable variants.
758
758
let beforeVariants = [
759
+ variantPlugins [ 'childVariant' ] ,
759
760
variantPlugins [ 'pseudoElementVariants' ] ,
760
761
variantPlugins [ 'pseudoClassVariants' ] ,
761
762
variantPlugins [ 'hasVariants' ] ,
Original file line number Diff line number Diff line change @@ -1201,4 +1201,37 @@ crosscheck(({ stable, oxide }) => {
1201
1201
}
1202
1202
` )
1203
1203
} )
1204
+
1205
+ test ( '* is matched by the parser as the children variant' , async ( ) => {
1206
+ let config = {
1207
+ content : [
1208
+ {
1209
+ raw : html `
1210
+ <div class= "*:italic" / >
1211
+ <div class= "*:hover:italic" / >
1212
+ <div class= "hover:*:italic" / >
1213
+ <div class= "data-[slot=label]:*:hover:italic" / >
1214
+ <div class= "[&_p]:*:hover:italic" / >
1215
+ ` ,
1216
+ } ,
1217
+ ] ,
1218
+ corePlugins : { preflight : false } ,
1219
+ }
1220
+
1221
+ let input = css `
1222
+ @tailwind utilities;
1223
+ `
1224
+
1225
+ let result = await run ( input , config )
1226
+
1227
+ expect ( result . css ) . toMatchFormattedCss ( css `
1228
+ .\*\:italic > * ,
1229
+ .\*\:hover\:italic : hover > * ,
1230
+ .hover\:\*\:italic > : hover,
1231
+ .data-\[slot\=label\]\:\*\:hover\:italic : hover > [data-slot = 'label' ],
1232
+ .\[\&_p\]\:\*\:hover\:italic : hover > * p {
1233
+ font-style : italic;
1234
+ }
1235
+ ` )
1236
+ } )
1204
1237
} )
You can’t perform that action at this time.
0 commit comments