Skip to content

Migrate negative arbitrary values to negative bare values #18212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

- Upgrade: migrate arbitrary modifiers with values without percentage sign to bare values `/[0.16]` -> `/16` ([#18184](https://github.com/tailwindlabs/tailwindcss/pull/18184))
- Upgrade: migrate CSS variable shorthand if fallback value contains function call ([#18184](https://github.com/tailwindlabs/tailwindcss/pull/18184))
- Upgrade: Migrate negative arbitrary values to negative bare values, e.g.: `mb-[-32rem]` → `-mb-128` ([#18212](https://github.com/tailwindlabs/tailwindcss/pull/18212))

## [4.1.8] - 2025-05-27

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,21 @@ export function migrateArbitraryUtilities(
candidate.kind === 'arbitrary' ? candidate.value : (candidate.value?.value ?? null)
if (value === null) return

let spacingMultiplier = spacing.get(designSystem)?.get(value)
let spacingMultiplier = spacing.get(designSystem)?.get(value) ?? null
let rootPrefix = ''
if (spacingMultiplier !== null && spacingMultiplier < 0) {
rootPrefix = '-'
spacingMultiplier = Math.abs(spacingMultiplier)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also an option 🤔

Suggested change
spacingMultiplier = Math.abs(spacingMultiplier)
spacingMultiplier *= -1

}

for (let root of Array.from(designSystem.utilities.keys('functional')).sort(
// Sort negative roots after positive roots so that we can try
// `mt-*` before `-mt-*`. This is especially useful in situations where
// `-mt-[0px]` can be translated to `mt-[0px]`.
(a, z) => Number(a[0] === '-') - Number(z[0] === '-'),
)) {
if (rootPrefix) root = `${rootPrefix}${root}`

// Try as bare value
for (let replacementCandidate of parseCandidate(designSystem, `${root}-${value}`)) {
yield replacementCandidate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ describe.each([['default'], ['with-variant'], ['important'], ['prefix']])('%s',
// the fallback contains functions. The fallback should also be migrated to
// the newest syntax.
['bg-[--my-color,theme(colors.red.500)]', 'bg-(--my-color,var(--color-red-500))'],

// Both the positive and negative versions of arbitrary utilities should be
// converted to the bare value version.
['mb-[32rem]', 'mb-128'],
['mb-[-32rem]', '-mb-128'],
])(testName, async (candidate, result) => {
if (strategy === 'with-variant') {
candidate = `focus:${candidate}`
Expand Down