Skip to content

Commit

Permalink
Remove double translate-z-px values (#16718)
Browse files Browse the repository at this point in the history
This PR fixes an issue where if you used `translate-z-px` or
`-translate-z-px` that the utility was generated twice:
```css
.translate-z-px {
  --tw-translate-z: 1px;
  translate: var(--tw-translate-x) var(--tw-translate-y) var(--tw-translate-z);
}
.translate-z-px {
  --tw-translate-z: 1px;
  translate: var(--tw-translate-x) var(--tw-translate-y) var(--tw-translate-z);
}
@Property --tw-translate-x {
  syntax: "*";
  inherits: false;
  initial-value: 0;
}
@Property --tw-translate-y {
  syntax: "*";
  inherits: false;
  initial-value: 0;
}
@Property --tw-translate-z {
  syntax: "*";
  inherits: false;
  initial-value: 0;
}
```

With this PR, it will only generate once:
```css
.translate-z-px {
  --tw-translate-z: 1px;
  translate: var(--tw-translate-x) var(--tw-translate-y) var(--tw-translate-z);
}
@Property --tw-translate-x {
  syntax: "*";
  inherits: false;
  initial-value: 0;
}
@Property --tw-translate-y {
  syntax: "*";
  inherits: false;
  initial-value: 0;
}
@Property --tw-translate-z {
  syntax: "*";
  inherits: false;
  initial-value: 0;
}
```
  • Loading branch information
RobinMalfait authored Feb 21, 2025
1 parent 113142a commit b47b6d2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Vite: Ensure utility classes are read without escaping special characters ([#16631](https://github.com/tailwindlabs/tailwindcss/pull/16631))
- Allow `theme(…)` options when using `@import` ([#16514](https://github.com/tailwindlabs/tailwindcss/pull/16514))
- Use amount of properties when sorting ([#16715](https://github.com/tailwindlabs/tailwindcss/pull/16715))
- Remove double generated `translate-z-px` utilities ([#16718](https://github.com/tailwindlabs/tailwindcss/pull/16718))

## [4.0.7] - 2025-02-18

Expand Down
10 changes: 8 additions & 2 deletions packages/tailwindcss/src/utilities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4213,16 +4213,22 @@ test('translate-y', async () => {
})

test('translate-z', async () => {
expect(await run(['translate-z-px', '-translate-z-[var(--value)]'])).toMatchInlineSnapshot(`
expect(
await run(['-translate-z-px', 'translate-z-px', '-translate-z-[var(--value)]']),
).toMatchInlineSnapshot(`
".-translate-z-\\[var\\(--value\\)\\] {
--tw-translate-z: calc(var(--value) * -1);
translate: var(--tw-translate-x) var(--tw-translate-y) var(--tw-translate-z);
}
.-translate-z-px {
--tw-translate-z: -1px;
translate: var(--tw-translate-x) var(--tw-translate-y) var(--tw-translate-z);
}
.translate-z-px {
--tw-translate-z: 1px;
translate: var(--tw-translate-x) var(--tw-translate-y) var(--tw-translate-z);
translate: var(--tw-translate-x) var(--tw-translate-y) var(--tw-translate-z);
}
@property --tw-translate-x {
Expand Down
10 changes: 0 additions & 10 deletions packages/tailwindcss/src/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1230,16 +1230,6 @@ export function createUtilities(theme: Theme) {
supportsNegative: true,
},
)
staticUtility(`-translate-z-px`, [
translateProperties,
[`--tw-translate-z`, '-1px'],
['translate', 'var(--tw-translate-x) var(--tw-translate-y) var(--tw-translate-z)'],
])
staticUtility(`translate-z-px`, [
translateProperties,
[`--tw-translate-z`, '1px'],
['translate', 'var(--tw-translate-x) var(--tw-translate-y) var(--tw-translate-z)'],
])

staticUtility('translate-3d', [
translateProperties,
Expand Down

0 comments on commit b47b6d2

Please # to comment.