Skip to content

Commit 86dd697

Browse files
authored
Remove percentage values for translate-z utilities (#13321)
* handle `translate-z` separately * do not support fractions for `translate-z` * update changelog
1 parent 8840019 commit 86dd697

File tree

4 files changed

+52
-44
lines changed

4 files changed

+52
-44
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10-
- Nothing yet!
10+
### Fixed
11+
12+
- Remove percentage values for `translate-z` utilities ([#13321](https://github.com/tailwindlabs/tailwindcss/pull/13321))
1113

1214
## [4.0.0-alpha.10] - 2024-03-19
1315

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1727,7 +1727,6 @@ exports[`getClassList 1`] = `
17271727
"translate-z-1",
17281728
"translate-z-3",
17291729
"translate-z-4",
1730-
"translate-z-full",
17311730
"translate-z-px",
17321731
"truncate",
17331732
"underline",

packages/tailwindcss/src/utilities.test.ts

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2582,47 +2582,38 @@ test('translate-y', () => {
25822582
})
25832583

25842584
test('translate-z', () => {
2585-
expect(run(['translate-z-full', '-translate-z-full', 'translate-y-px', '-translate-z-[--value]']))
2586-
.toMatchInlineSnapshot(`
2587-
".-translate-z-\\[--value\\] {
2588-
--tw-translate-z: calc(var(--value) * -1);
2589-
translate: var(--tw-translate-x) var(--tw-translate-y) var(--tw-translate-z);
2590-
}
2591-
2592-
.-translate-z-full {
2593-
--tw-translate-z: -100%;
2594-
translate: var(--tw-translate-x) var(--tw-translate-y) var(--tw-translate-z);
2595-
}
2596-
2597-
.translate-y-px {
2598-
--tw-translate-y: 1px;
2599-
translate: var(--tw-translate-x) var(--tw-translate-y);
2600-
}
2585+
expect(run(['translate-y-px', '-translate-z-[--value]'])).toMatchInlineSnapshot(`
2586+
".-translate-z-\\[--value\\] {
2587+
--tw-translate-z: calc(var(--value) * -1);
2588+
translate: var(--tw-translate-x) var(--tw-translate-y) var(--tw-translate-z);
2589+
}
26012590
2602-
.translate-z-full {
2603-
--tw-translate-z: 100%;
2604-
translate: var(--tw-translate-x) var(--tw-translate-y) var(--tw-translate-z);
2605-
}
2591+
.translate-y-px {
2592+
--tw-translate-y: 1px;
2593+
translate: var(--tw-translate-x) var(--tw-translate-y);
2594+
}
26062595
2607-
@property --tw-translate-x {
2608-
syntax: "<length-percentage>";
2609-
inherits: false;
2610-
initial-value: 0;
2611-
}
2596+
@property --tw-translate-x {
2597+
syntax: "<length-percentage>";
2598+
inherits: false;
2599+
initial-value: 0;
2600+
}
26122601
2613-
@property --tw-translate-y {
2614-
syntax: "<length-percentage>";
2615-
inherits: false;
2616-
initial-value: 0;
2617-
}
2602+
@property --tw-translate-y {
2603+
syntax: "<length-percentage>";
2604+
inherits: false;
2605+
initial-value: 0;
2606+
}
26182607
2619-
@property --tw-translate-z {
2620-
syntax: "<length-percentage>";
2621-
inherits: false;
2622-
initial-value: 0;
2623-
}"
2624-
`)
2625-
expect(run(['translate-z'])).toEqual('')
2608+
@property --tw-translate-z {
2609+
syntax: "<length-percentage>";
2610+
inherits: false;
2611+
initial-value: 0;
2612+
}"
2613+
`)
2614+
expect(run(['translate-z', 'translate-z-full', '-translate-z-full', 'translate-z-1/2'])).toEqual(
2615+
'',
2616+
)
26262617
})
26272618

26282619
test('translate-3d', () => {

packages/tailwindcss/src/utilities.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,14 +1239,11 @@ export function createUtilities(theme: Theme) {
12391239
],
12401240
})
12411241

1242-
for (let axis of ['x', 'y', 'z']) {
1242+
for (let axis of ['x', 'y']) {
12431243
let handle = (value: string) => [
12441244
translateProperties(),
12451245
decl(`--tw-translate-${axis}`, value),
1246-
decl(
1247-
'translate',
1248-
`var(--tw-translate-x) var(--tw-translate-y)${axis === 'z' ? ' var(--tw-translate-z)' : ''}`,
1249-
),
1246+
decl('translate', `var(--tw-translate-x) var(--tw-translate-y)`),
12501247
]
12511248

12521249
/**
@@ -1265,6 +1262,25 @@ export function createUtilities(theme: Theme) {
12651262
return handle(candidate.negative ? '-100%' : '100%')
12661263
})
12671264
}
1265+
functionalUtility(`translate-z`, {
1266+
supportsNegative: true,
1267+
supportsFractions: false,
1268+
themeKeys: ['--translate', '--spacing'],
1269+
handle: (value) => {
1270+
return [
1271+
translateProperties(),
1272+
decl(`--tw-translate-z`, value),
1273+
decl('translate', 'var(--tw-translate-x) var(--tw-translate-y) var(--tw-translate-z)'),
1274+
]
1275+
},
1276+
})
1277+
utilities.static(`translate-z-px`, (candidate) => {
1278+
return [
1279+
translateProperties(),
1280+
decl(`--tw-translate-z`, candidate.negative ? '-1px' : '1px'),
1281+
decl('translate', 'var(--tw-translate-x) var(--tw-translate-y) var(--tw-translate-z)'),
1282+
]
1283+
})
12681284

12691285
/**
12701286
* @css `translate`

0 commit comments

Comments
 (0)