Make negative values a first-class feature, rather than theme-driven #5709
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR makes the negative prefix in Tailwind (like
-mt-4
) a true feature of Tailwind, rather than something that is generated because you have negative values in your config file.Using a negative prefix in a key in your config file will still work the way it always has and will take precedence over this new "automatic" negative value support, but this PR does remove all the explicit negative values from the default config.
With this change, you can now use negative versions of anything "negatable" automatically, whether or not it's defined in your config, and even including arbitrary values:
-mt-2
margin-top: -0.5rem
-mt-[5px]
margin-top: -5px
-mt-[-10px]
margin-top: 10px
-mt-[var(--whatever)]
margin-top: calc(var(--whatever) * -1)
-mt-0
margin-top: 0
-mt-auto
This adds a lot of new power to Tailwind, while also letting us really simplify the default config. It also fixes a common hang up people run into where they expect
-mt-[500px]
to work, and I've always had to tell them to writemt-[-500px]
instead.There is a tiny breaking change here, which is that the
negative
helper function passed in to theme callbacks no longer returns the untouched value for values that cannot be made negative, for example:The
getClassList
test is currently failing, because completions were relying on the config information to generate the negative values. We will need to fix this before merging, so going to leave this open until then.