Skip to content

Commit 28a5438

Browse files
authored
Add inert variant (#14129)
This PR adds a new `inert` variant. We use `:where([inert], [inert] *)`, because the element with the `inert` attribute and any of its descendants will be inert. For example, both these buttons will have `opacity-50`: ```html <button inert class="inert:opacity-50">I am inert</button> <div inert> <button class="inert:opacity-50">I am also inert</button> </div> ``` See: https://play.tailwindcss.com/Jqedv6phGn
1 parent 8f2aa3a commit 28a5438

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
- Add support for `inline` option when defining `@theme` values ([#14095](https://github.com/tailwindlabs/tailwindcss/pull/14095))
13+
- Add `inert` variant ([#14129](https://github.com/tailwindlabs/tailwindcss/pull/14129))
1314

1415
## [4.0.0-alpha.18] - 2024-07-25
1516

packages/tailwindcss/src/__snapshots__/intellisense.test.ts.snap

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,6 +1942,7 @@ exports[`getVariants 1`] = `
19421942
"active",
19431943
"enabled",
19441944
"disabled",
1945+
"inert",
19451946
"has",
19461947
"aria",
19471948
"data",
@@ -1993,6 +1994,7 @@ exports[`getVariants 1`] = `
19931994
"active",
19941995
"enabled",
19951996
"disabled",
1997+
"inert",
19961998
"has",
19971999
"aria",
19982000
"data",
@@ -2284,6 +2286,13 @@ exports[`getVariants 1`] = `
22842286
"selectors": [Function],
22852287
"values": [],
22862288
},
2289+
{
2290+
"hasDash": true,
2291+
"isArbitrary": false,
2292+
"name": "inert",
2293+
"selectors": [Function],
2294+
"values": [],
2295+
},
22872296
{
22882297
"hasDash": true,
22892298
"isArbitrary": true,
@@ -2324,6 +2333,7 @@ exports[`getVariants 1`] = `
23242333
"active",
23252334
"enabled",
23262335
"disabled",
2336+
"inert",
23272337
"has",
23282338
"aria",
23292339
"data",

packages/tailwindcss/src/variants.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,23 @@ test('disabled', () => {
695695
expect(run(['disabled/foo:flex'])).toEqual('')
696696
})
697697

698+
test('inert', () => {
699+
expect(run(['inert:flex', 'group-inert:flex', 'peer-inert:flex'])).toMatchInlineSnapshot(`
700+
".group-inert\\:flex:is(:where(.group):is([inert], [inert] *) *) {
701+
display: flex;
702+
}
703+
704+
.peer-inert\\:flex:is(:where(.peer):is([inert], [inert] *) ~ *) {
705+
display: flex;
706+
}
707+
708+
.inert\\:flex:is([inert], [inert] *) {
709+
display: flex;
710+
}"
711+
`)
712+
expect(run(['inert/foo:flex'])).toEqual('')
713+
})
714+
698715
test('group-[...]', () => {
699716
expect(
700717
run([

packages/tailwindcss/src/variants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,8 @@ export function createVariants(theme: Theme): Variants {
465465
staticVariant(key, [value])
466466
}
467467

468+
staticVariant('inert', ['&:is([inert], [inert] *)'])
469+
468470
variants.compound('has', (ruleNode, variant) => {
469471
if (variant.modifier) return null
470472

0 commit comments

Comments
 (0)