Skip to content

Commit

Permalink
Add scripting variants (#11929)
Browse files Browse the repository at this point in the history
This adds two variants for the
[`scripting`](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/scripting)
media query. `noscript` for when JavaScript is disabled and `scripting`
for when it's enabled.

---------

Co-authored-by: Philipp Spiess <hello@philippspiess.com>
  • Loading branch information
lukewarlow and philipp-spiess authored Feb 26, 2025
1 parent e938c58 commit 5532d48
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- _Experimental_: Add `details-content` variant ([#15319](https://github.com/tailwindlabs/tailwindcss/pull/15319))
- _Experimental_: Add `inverted-colors` variant ([#11693](https://github.com/tailwindlabs/tailwindcss/pull/11693))
- _Experimental_: Add `scripting`, `scripting-none`, and `scripting-initial` variants ([#12128](https://github.com/tailwindlabs/tailwindcss/pull/12128))
- _Experimental_: Add `user-valid` and `user-invalid` variants ([#12370](https://github.com/tailwindlabs/tailwindcss/pull/12370))
- _Experimental_: Add `wrap-anywhere`, `wrap-break-word`, and `wrap-normal` utilities ([#12128](https://github.com/tailwindlabs/tailwindcss/pull/12128))

Expand Down
24 changes: 24 additions & 0 deletions packages/tailwindcss/src/__snapshots__/intellisense.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8449,6 +8449,9 @@ exports[`getVariants 1`] = `
"print",
"forced-colors",
"inverted-colors",
"scripting-initial",
"scripting-none",
"scripting",
],
},
{
Expand Down Expand Up @@ -9184,5 +9187,26 @@ exports[`getVariants 1`] = `
"selectors": [Function],
"values": [],
},
{
"hasDash": true,
"isArbitrary": false,
"name": "scripting-initial",
"selectors": [Function],
"values": [],
},
{
"hasDash": true,
"isArbitrary": false,
"name": "scripting-none",
"selectors": [Function],
"values": [],
},
{
"hasDash": true,
"isArbitrary": false,
"name": "scripting",
"selectors": [Function],
"values": [],
},
]
`;
1 change: 1 addition & 0 deletions packages/tailwindcss/src/feature-flags.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const enableDetailsContent = process.env.FEATURES_ENV !== 'stable'
export const enableInvertedColors = process.env.FEATURES_ENV !== 'stable'
export const enableScripting = process.env.FEATURES_ENV !== 'stable'
export const enableUserValid = process.env.FEATURES_ENV !== 'stable'
export const enableWrapAnywhere = process.env.FEATURES_ENV !== 'stable'
30 changes: 30 additions & 0 deletions packages/tailwindcss/src/variants.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1919,6 +1919,36 @@ test('inverted-colors', async () => {
`)
})

test('scripting-initial', async () => {
expect(await run(['scripting-initial:flex'])).toMatchInlineSnapshot(`
"@media (scripting: initial-only) {
.scripting-initial\\:flex {
display: flex;
}
}"
`)
})

test('scripting-none', async () => {
expect(await run(['scripting-none:flex'])).toMatchInlineSnapshot(`
"@media (scripting: none) {
.scripting-none\\:flex {
display: flex;
}
}"
`)
})

test('scripting', async () => {
expect(await run(['scripting:flex'])).toMatchInlineSnapshot(`
"@media (scripting: enabled) {
.scripting\\:flex {
display: flex;
}
}"
`)
})

test('nth', async () => {
expect(
await run([
Expand Down
13 changes: 12 additions & 1 deletion packages/tailwindcss/src/variants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ import {
type StyleRule,
} from './ast'
import { type Variant } from './candidate'
import { enableDetailsContent, enableInvertedColors, enableUserValid } from './feature-flags'
import {
enableDetailsContent,
enableInvertedColors,
enableScripting,
enableUserValid,
} from './feature-flags'
import type { Theme } from './theme'
import { compareBreakpoints } from './utils/compare-breakpoints'
import { DefaultMap } from './utils/default-map'
Expand Down Expand Up @@ -1145,6 +1150,12 @@ export function createVariants(theme: Theme): Variants {
staticVariant('inverted-colors', ['@media (inverted-colors: inverted)'])
}

if (enableScripting) {
staticVariant('scripting-initial', ['@media (scripting: initial-only)'])
staticVariant('scripting-none', ['@media (scripting: none)'])
staticVariant('scripting', ['@media (scripting: enabled)'])
}

return variants
}

Expand Down

0 comments on commit 5532d48

Please sign in to comment.