Skip to content
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

Overridable class strategy #162

Open
midnight-wonderer opened this issue Aug 22, 2024 · 7 comments
Open

Overridable class strategy #162

midnight-wonderer opened this issue Aug 22, 2024 · 7 comments

Comments

@midnight-wonderer
Copy link

midnight-wonderer commented Aug 22, 2024

What version of @tailwindcss/forms are you using?

v0.5.7

Describe your issue

I read the discussion #22. The thread has been closed by adding class strategy.

Sorry to bring this up again

However, the class strategy is not easily overridable because it was placed later in the CSS file (at the components layer).
No matter the strategy used, tailwindcss-forms should always be a base, ready to be overridden by other stylings.

Why the need for overrides?

I can't talk for others, as you'll see some of them on the discussion links above, but for me, tailwindcss-forms adds colors that almost always need overriding because they stand out like sore thumbs.

What should we do?

Can we move CSS declarations of class strategy from components layer to base layer?
Basically, modify the code here:

addComponents(getStrategyRules('class'))

from addComponents to addBase.

Why do I, or other similar people, use tailwindcss-forms at all?

tailwindcss has its ecosystem, and some 3rd-party components expect tailwindcss-forms to be there as the base. We still want to work with tailwindcss-forms and the people creating those components, even if we are not a fan of the approaches.

@adamwathan
Copy link
Member

Can you give a concrete example of something that doesn't work? Are you trying to override the form styles with custom styles that you are putting in the base layer?

@midnight-wonderer
Copy link
Author

Can you give a concrete example of something that doesn't work? Are you trying to override the form styles with custom styles that you are putting in the base layer?

Yep, that's pretty much it.
I am customizing the base style of tailwindcss-forms like this:

@layer base {
  .form-checkbox:focus, .form-radio:focus {
    --tw-ring-color: transparent;
  }
}

It needs to be at the base layer because, well, it is the base style.

@adamwathan
Copy link
Member

Those classes are in the components layer so why not use @layer components? When using the class strategy I don't consider them base styles because they aren't applied by default, you have to opt-in to them by adding a class.

@midnight-wonderer
Copy link
Author

I guess that's work, too; apology for the fuss.
I kind of want to leave some room because of the unseen (future), but this is probably YAGNI stuff.

Nevertheless, all strategies at the base layer have advantages in some aspects. Their consistency makes the overriding layer agnostic to the strategies used. This makes it easier to share snippets in certain situations.

That said, the advantage is likely marginal; thanks for the swift replies.

@ranseur92
Copy link

ranseur92 commented Nov 15, 2024

Those classes are in the components layer so why not use @layer components? When using the class strategy I don't consider them base styles because they aren't applied by default, you have to opt-in to them by adding a class.

Can you verify/check if this is the case in v4? as for me, they end up in the utilities layer. which makes changing the styles and allowing overrides not work.

@adamwathan

@chasegiunta
Copy link
Contributor

chasegiunta commented Jan 30, 2025

In v3, I was using the class strategy, and setting some other defaults to be applied to my form- classes by nesting in @layer components. This worked without problem, because the reset classes were also being applied in the components layer. I'd get the reset, and my overrides, when applying form-input, etc.

In v4, this behavior changed for the class strategy: resets are now set in the utilities layer. I'm not sure if this is a bug for where plugin classes are applied, or an intended change. When running my previous overrides through the migration CLI, they were all converted to using the @utility directive. This did not take precedence over the reset classes applied in the utilities layer (at least not in all cases, it was not guaranteed).

My fix was to nest overrides in @layer utilities and convert the @utility conversions back to their original normal class overrides. Unfortunately, this does not seem like a reliable method either. The tailwindcss/forms package will need to apply it's classes at the components layer, not utilities.

@dargmuesli
Copy link

Source of the new behavior is this PR: tailwindlabs/tailwindcss#14221, especially the alias of components to utilities. The PR's description state:

The component APIs are an alias for the utilities APIs because the sorting in V4 is different and emitting components in a custom @layer is not necessary.

@thecrypticace could you give us some insight into what exactly that means and how we're supposed to use utilities to override .form-input's properties?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants