-
-
Notifications
You must be signed in to change notification settings - Fork 70
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
Problem with applying outline utility classes in Tailwind CSS #387
Comments
Hey @Squiffles! 👋 tailwind-merge doesn't have access to the tailwind.config.js file and you need to configure it separately so it knows about your outline classes (you only need to configure outline width, outline color work without any config). Here is an example on how to configure tailwind-merge: https://github.com/dcastil/tailwind-merge/blob/v2.2.1/docs/recipes.md#adding-custom-scale-from-tailwind-config-to-tailwind-merge-config. And here is the documentation on how the tailwind-merge configuration works: https://github.com/dcastil/tailwind-merge/blob/v2.2.1/docs/configuration.md#usage-with-custom-tailwind-config. (For myself) Related: #368, #322, #321, #315, #302, #276, #275, #274, #250, #207 |
Hey @dcastil. Thanks for your answer. Actually, the issue comes with Using just a string adds both classes:
But using
This is my tailwind config again and why I think it should accept both classes: ...
theme: {
extend: {
outlineColor: {
focus: '#00A491'
},
outlineWidth: {
focus: '2.5px'
},
outlineOffset: {
focus: '1.7px'
},
... I've tried to use a custom tailwind merge as suggested. Ended up with this function: import { extendTailwindMerge } from 'tailwind-merge';
export default extendTailwindMerge({
extend: {
classGroups: {
"outline-color": ["focus"],
"outline-offset": ["focus"],
"outline-w": ["focus"]
}
}
}); Still doesn't accept both classes. |
Ah you need to use the full class name as value. Also no need to configure color classes, tailwind-merge detects any unknown classes that could be color classes as such. This would be the correct config for that: const twMerge = extendTailwindMerge({
extend: {
classGroups: {
"outline-offset": ["outline-offset-focus"],
"outline-w": ["outline-focus"]
}
}
}); |
Working like a fine wine ! Thanks. |
Awesome! Let me close this issue then. |
Description
I'm encountering an issue with applying outline utility classes in Tailwind CSS. When using the
twMerge
utility function, I'm unable to consistently applyoutline-focusedWidth
,outline-focusedColor
andoutline-offset-focusedOffset
classes to an element.Steps To Reproduce
tailwind.config.js
:Button.jsx
:Expected Behaviour
On the browser, I expect the bundler to apply the following classes to the element:
outline
:outline-focusedWidth
:outline-focusedColor
:outline-offset-focusedOffset
:And render the following HTML:
Actual behaviour
Only the last class is applied. For instance, if I have this:
The
outline-offset-focusedOffset
class is correctly applied, but theoutline-focusedWidth
andoutline-focusedColor
are not and this is rendered:However, if I change the order:
This is rendered:
The
outline
class is always added, no matter the order.Using the regular className prop:
works well and adds the four classes to the element in the final bundle. So, I suppose the issue is related to how twMerge manages the outline classes:
outline-<customClass>
andoutline-offset-<customClass>
.Workaround
Using arbitrary values for the outline when using twMerge:
Correctly applies the 4 classes:
Environment
Additional information
The same behaviour occurs when the classes are defined with the same name:
tailwind.config.js
:Then, using the regular className prop:
adds the 3 classes:
outline
:outline-focus
:outline-offset-focus
:But, using twMerge doesn't work:
And you have to choose which one to write last, whether
outline-focus
oroutline-offset-focus
.Note that in this case if you choose to write "outline-focus" as the last:
It will apply colour and width:
outline-focus
:However, this behaviour only occurs if the names for these custom properties are the same:
The text was updated successfully, but these errors were encountered: