Skip to content

Commit 91fca13

Browse files
authored
Don't rely on existence of --default-transition-* variables in transition utilities (#13219)
* Don't rely on existence of --default-transition-* variables in transition utilities * Update changelog * Add test with no default transition values defined * Inline value for --default-transition-timing-function This is more consistent with how things worked in v3 and ensures things will still work if the user suppresses the output of all CSS variables. --------- Co-authored-by: Adam Wathan <[email protected]>
1 parent 7452425 commit 91fca13

File tree

7 files changed

+45
-22
lines changed

7 files changed

+45
-22
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515

1616
- Support `@theme reference { … }` for defining theme values without emitting variables ([#13222](https://github.com/tailwindlabs/tailwindcss/pull/13222))
1717

18+
### Fixed
19+
20+
- Don't rely on existence of `--default-transition-*` variables in `transition-*` utilities ([#13219](https://github.com/tailwindlabs/tailwindcss/pull/13219))
21+
1822
## [4.0.0-alpha.8] - 2024-03-11
1923

2024
### Fixed

packages/@tailwindcss-postcss/src/__snapshots__/index.test.ts.snap

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ exports[`\`@import 'tailwindcss'\` is replaced with the generated CSS 1`] = `
44
"@layer theme {
55
:root {
66
--default-transition-duration: .15s;
7-
--default-transition-timing-function: var(--transition-timing-function-in-out);
7+
--default-transition-timing-function: cubic-bezier(.4, 0, .2, 1);
88
--default-font-family: var(--font-family-sans);
99
--default-font-feature-settings: var(--font-family-sans--font-feature-settings);
1010
--default-font-variation-settings: var(--font-family-sans--font-variation-settings);
@@ -393,7 +393,6 @@ exports[`\`@import 'tailwindcss'\` is replaced with the generated CSS 1`] = `
393393
--line-height-8: 2rem;
394394
--line-height-9: 2.25rem;
395395
--line-height-10: 2.5rem;
396-
--transition-timing-function: cubic-bezier(.4, 0, .2, 1);
397396
--transition-timing-function-linear: linear;
398397
--transition-timing-function-in: cubic-bezier(.4, 0, 1, 1);
399398
--transition-timing-function-out: cubic-bezier(0, 0, .2, 1);

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
exports[`compiling CSS > \`@tailwind utilities\` is replaced by utilities using the default theme 1`] = `
44
":root {
55
--default-transition-duration: .15s;
6-
--default-transition-timing-function: var(--transition-timing-function-in-out);
6+
--default-transition-timing-function: cubic-bezier(.4, 0, .2, 1);
77
--default-font-family: var(--font-family-sans);
88
--default-font-feature-settings: var(--font-family-sans--font-feature-settings);
99
--default-font-variation-settings: var(--font-family-sans--font-variation-settings);
@@ -392,7 +392,6 @@ exports[`compiling CSS > \`@tailwind utilities\` is replaced by utilities using
392392
--line-height-8: 2rem;
393393
--line-height-9: 2.25rem;
394394
--line-height-10: 2.5rem;
395-
--transition-timing-function: cubic-bezier(.4, 0, .2, 1);
396395
--transition-timing-function-linear: linear;
397396
--transition-timing-function-in: cubic-bezier(.4, 0, 1, 1);
398397
--transition-timing-function-out: cubic-bezier(0, 0, .2, 1);

packages/tailwindcss/src/theme.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ export type ThemeKey =
151151
| '--default-border-width'
152152
| '--default-ring-color'
153153
| '--default-ring-width'
154+
| '--default-transition-timing-function'
155+
| '--default-transition-duration'
154156
| '--divide-width'
155157
| '--divide-color'
156158
| '--drop-shadow'

packages/tailwindcss/src/utilities.test.ts

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9713,6 +9713,8 @@ test('transition', () => {
97139713
compileCss(
97149714
css`
97159715
@theme {
9716+
--default-transition-timing-function: ease;
9717+
--default-transition-duration: 100ms;
97169718
--transition-property: color, background-color, border-color, text-decoration-color, fill,
97179719
stroke, opacity, box-shadow, transform, filter, backdrop-filter;
97189720
--transition-property-opacity: opacity;
@@ -9732,56 +9734,74 @@ test('transition', () => {
97329734
),
97339735
).toMatchInlineSnapshot(`
97349736
":root {
9737+
--default-transition-timing-function: ease;
9738+
--default-transition-duration: .1s;
97359739
--transition-property: color, background-color, border-color, text-decoration-color, fill, stroke, opacity, box-shadow, transform, filter, backdrop-filter;
97369740
--transition-property-opacity: opacity;
97379741
}
97389742
97399743
.transition {
97409744
transition-property: color, background-color, border-color, text-decoration-color, fill, stroke, opacity, box-shadow, transform, translate, scale, rotate, filter, -webkit-backdrop-filter, -webkit-backdrop-filter, backdrop-filter;
9741-
transition-timing-function: var(--default-transition-timing-function);
9742-
transition-duration: var(--default-transition-duration);
9745+
transition-duration: .1s;
9746+
transition-timing-function: ease;
97439747
}
97449748
97459749
.transition-\\[--value\\] {
97469750
transition-property: var(--value);
9747-
transition-timing-function: var(--default-transition-timing-function);
9748-
transition-duration: var(--default-transition-duration);
9751+
transition-duration: .1s;
9752+
transition-timing-function: ease;
97499753
}
97509754
97519755
.transition-all {
97529756
transition-property: all;
9753-
transition-timing-function: var(--default-transition-timing-function);
9754-
transition-duration: var(--default-transition-duration);
9757+
transition-duration: .1s;
9758+
transition-timing-function: ease;
97559759
}
97569760
97579761
.transition-colors {
97589762
transition-property: color, background-color, border-color, text-decoration-color, fill, stroke;
9759-
transition-timing-function: var(--default-transition-timing-function);
9760-
transition-duration: var(--default-transition-duration);
9763+
transition-duration: .1s;
9764+
transition-timing-function: ease;
97619765
}
97629766
97639767
.transition-opacity {
97649768
transition-property: opacity;
9765-
transition-timing-function: var(--default-transition-timing-function);
9766-
transition-duration: var(--default-transition-duration);
9769+
transition-duration: .1s;
9770+
transition-timing-function: ease;
97679771
}
97689772
97699773
.transition-shadow {
97709774
transition-property: box-shadow;
9771-
transition-timing-function: var(--default-transition-timing-function);
9772-
transition-duration: var(--default-transition-duration);
9775+
transition-duration: .1s;
9776+
transition-timing-function: ease;
97739777
}
97749778
97759779
.transition-transform {
97769780
transition-property: transform, translate, scale, rotate;
9777-
transition-timing-function: var(--default-transition-timing-function);
9778-
transition-duration: var(--default-transition-duration);
9781+
transition-duration: .1s;
9782+
transition-timing-function: ease;
97799783
}
97809784
97819785
.transition-none {
97829786
transition-property: none;
97839787
}"
97849788
`)
9789+
9790+
expect(
9791+
compileCss(
9792+
css`
9793+
@tailwind utilities;
9794+
`,
9795+
['transition-all'],
9796+
),
9797+
).toMatchInlineSnapshot(`
9798+
".transition-all {
9799+
transition-property: all;
9800+
transition-duration: 0s;
9801+
transition-timing-function: ease;
9802+
}"
9803+
`)
9804+
97859805
expect(
97869806
run([
97879807
'-transition',

packages/tailwindcss/src/utilities.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3322,8 +3322,8 @@ export function createUtilities(theme: Theme) {
33223322
}
33233323

33243324
{
3325-
let defaultTimingFunction = 'var(--default-transition-timing-function)'
3326-
let defaultDuration = 'var(--default-transition-duration)'
3325+
let defaultTimingFunction = theme.get(['--default-transition-timing-function']) ?? 'ease'
3326+
let defaultDuration = theme.get(['--default-transition-duration']) ?? '0s'
33273327

33283328
staticUtility('transition-none', [['transition-property', 'none']])
33293329
staticUtility('transition-all', [

packages/tailwindcss/theme.css

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@theme {
22
/* Defaults */
33
--default-transition-duration: 150ms;
4-
--default-transition-timing-function: var(--transition-timing-function-in-out);
4+
--default-transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
55
--default-font-family: var(--font-family-sans);
66
--default-font-feature-settings: var(--font-family-sans--font-feature-settings);
77
--default-font-variation-settings: var(--font-family-sans--font-variation-settings);
@@ -422,7 +422,6 @@
422422
--line-height-10: 2.5rem;
423423

424424
/* Transition timing functions */
425-
--transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
426425
--transition-timing-function-linear: linear;
427426
--transition-timing-function-in: cubic-bezier(0.4, 0, 1, 1);
428427
--transition-timing-function-out: cubic-bezier(0, 0, 0.2, 1);

0 commit comments

Comments
 (0)