Skip to content

Add support for important in v4#14448

Merged
RobinMalfait merged 16 commits into
nextfrom
feat/v4-important-compat
Oct 3, 2024
Merged

Add support for important in v4#14448
RobinMalfait merged 16 commits into
nextfrom
feat/v4-important-compat

Conversation

@thecrypticace

@thecrypticace thecrypticace commented Sep 17, 2024

Copy link
Copy Markdown
Contributor

This PR allows modifying utility output by wrapping all utility declarations in a custom selector or marking all utility declarations as !important. This is the v4 equivalent to the important option in the tailwind.config.js file.

Mark all utility declarations as !important

To add !important to all utility declarations, you add an important flag after the @import statement for tailwindcss or tailwindcss/utilities:

/** Importing `tailwindcss` */
@import "tailwindcss" important;

/** Importing the utilities directly */
@import "tailwindcss/utilities" important;

Example utility output:

.mx-auto {
  margin-left: auto !important;
  margin-right: auto !important;
}

.text-center {
  text-align: center !important;
}

This is equivalent to adding important: true to the tailwind.config.js file — which is still supported for backwards compatibility.

Wrap all utility declarations in a custom selector

For backwards compatibility, if you need to nest all utilities in an #app selector you add important: "#app" to your config file:

export default {
  important: "#app",
  // …
}

This does not bring back support for the respectImportant flag in addUtilities / matchUtilities.

@thecrypticace thecrypticace force-pushed the feat/v4-important-compat branch from f8780bf to ca56bde Compare September 23, 2024 22:26
@thecrypticace thecrypticace changed the base branch from next to feat/v4-prefix-compat September 23, 2024 22:29
@thecrypticace thecrypticace force-pushed the feat/v4-prefix-compat branch 3 times, most recently from 6ffec7e to ed8a056 Compare September 24, 2024 14:11
Comment thread packages/tailwindcss/src/index.ts Outdated
Comment thread packages/tailwindcss/src/intellisense.test.ts
Comment thread packages/tailwindcss/src/compile.ts Outdated
@thecrypticace thecrypticace force-pushed the feat/v4-prefix-compat branch 3 times, most recently from a33fd23 to f06bb16 Compare September 24, 2024 18:52
@thecrypticace thecrypticace force-pushed the feat/v4-important-compat branch 2 times, most recently from e59d8a9 to 1971422 Compare September 24, 2024 20:50
@thecrypticace thecrypticace marked this pull request as ready for review September 24, 2024 21:14
Base automatically changed from feat/v4-prefix-compat to next September 25, 2024 14:06
@thecrypticace thecrypticace force-pushed the feat/v4-important-compat branch from 75f505f to 3871ea1 Compare September 25, 2024 14:22

@philipp-spiess philipp-spiess left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This all seems easy enough, just one question inline. Happy to stamp it but I feel like this could benefit from someone else's 👀 too!

Comment thread packages/tailwindcss/src/design-system.ts Outdated
Comment thread packages/tailwindcss/src/design-system.ts Outdated
Comment thread packages/tailwindcss/src/important.test.ts Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants