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

fix: doesn't work spaces inside calc #13529

Closed
wants to merge 2 commits into from

Conversation

bae-sh
Copy link

@bae-sh bae-sh commented Apr 16, 2024

This PR fix a uncomfortable thing that spaces inside calc doesn't work.

When i use arbitrary calc values with spaces <div class="w-[calc(100px + 200px)]></div>, tailwind extract separate words.
Finally, It doesn't work.

So I've added a function that remove spaces inside calc. It can remove spaces inside calc before using extractor.

before

w-[calc(100px + 200px)] -> w-[calc(100px , + , 200px)]

after

w-[calc(100px + 200px)] -> w-[calc(100px+200px)]

@RobinMalfait RobinMalfait self-assigned this Apr 16, 2024
@RobinMalfait
Copy link
Contributor

Hey!

Thanks for the PR, however the fact that spaces are not allowed in a class name is not a Tailwind UI issue but it is a side effect of how HTML itself works. Each class is separated by spaces, this means that if you use w-[calc(100px + 200px)] then you actually use 3 separate classes w-[calc(100px, + and 200px)].

Even with this fix, the class name will never match and the styles won't be applied.

That said, we know that spaces are required in calc, so we add them for you. This means that you should just be able to write <div class="w-[calc(100px+200px)]"></div>

This generates the following CSS:

.w-\[calc\(100px\+200px\)\] {
  width: calc(100px + 200px);
}

Hope this helps!

@bae-sh
Copy link
Author

bae-sh commented Apr 16, 2024

Thank you for the review!

The intent of this PR was not only to avoid spaces inside calc, but also to be recognized when spaces are used.
However, i was missing the fact that the html itself uses spaces to separate them.

Thanks for pointing that out! I hope I can contribute again in the future. 😀

@bae-sh bae-sh deleted the fix/spaces-inside-calc branch April 16, 2024 09:40
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

Successfully merging this pull request may close these issues.

None yet

2 participants