-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Remove need for transform
toggle
#4604
Conversation
What about browsers performance? Any benchmarks? |
@zensimilia Any recommendations on how to get those numbers? We actually already use this approach for shadows so we are already adding universal selectors for this sort of thing and no one has ever raised it as a performance issue in their projects. * {
--tw-shadow: 0 0 #0000
}
.shadow-sm {
--tw-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow)
} My guess is that since all we are doing is setting variables and not applying any styles that it wouldn't be an issue but I agree it would be nice to prove that. |
@adamwathan on my machine, when i add to * rule |
@zensimilia Yeah the big difference though is you are applying /* Bad */
* {
transform: scaleX(1)
}
/* I think this is okay */
* {
--tw-transform: scaleX(1)
} |
Hi 👋, I like this idea. I had a similar idea, but with a slightly different implementation. The biggest concern I had was the performance but I haven't explored that idea further. I'm just putting it here perhaps as inspiration for a different approach. |
How's that different from? :root {
--tw-transform: scaleX(1)
} |
The main difference is that it's re-applied on every element to prevent inheritance. If you put that on <div class="translate-x-1/2">
<div class="font-bold">
<div class="scale-50">
<!-- ... --> ...the |
Hey thanks for sharing, sorry I didn't notice that discussion thread before! Yeah this is a suggestion that has come up in the past and I know others have tried with some success too 👍 My main point of hesitation around that approach is potential false positives, like if someone is using Tailwind to layer utilities on top of some existing CSS and that pattern happens to match one of their existing styles that is doing something unrelated, it could cause problems. Like if someone has a custom class from years in the past in their project called |
Move fast and break things 😄 |
@adamwathan I have version '2.2.4' but the translate doesn't seem to work without the transform class. Also I'm trying to use a negative translate with a custom setting and doesn't work either I have this extended on my theme
So im trying to use
But
So I had to do a workaround and do this on my theme
and I have to use it like this
|
Hi @kevchcm 👋, you probably don't have Just-in-Time Mode mode enabled. This feature is currently enabled only in JIT mode, otherwise you still have to use the toggle. See: https://play.tailwindcss.com/OJ0LbfoE4f ( remove the |
@neupauer you're completely right, I don't have the jit mode, I'm sorry for that. Does that answer the question for the negative values on translate? Is it normal that I have to add a negative variant like this
I read the documentation and it doesn't say anything like that |
Hi @kevchcm, sorry I overlooked the second part of the question :). Yes it is perfectly valid to add custom values for the specific needs of your design. As you can see (the image below), the list of default values doesn't cover all possible values, so adding custom values is perfectly fine. You can add the module.exports = {
theme: {
extend: {
translate: {
"-screen": "-100vw"
}
},
},
} Tailwind will generate utilities If you have
|
This PR makes all of the individual transform classes like
scale-*
,translate-x/y-*
,skew-x/y-*
, androtate-*
work without the need for using thetransform
class to "enable" them. This introduces minor breaking changes depending on how you were authoring your HTML, so for now this only targets the JIT engine where it's okay for us to make these sorts of changes.It also adds a new
transform-cpu
class for explicitly using CPU rendering instead of GPU if you need to change that responsively:How it works
This works by adding a new rule targeting the universal (
*
) selector to thebase
layer that looks like this:Then each individual transform-related class looks something like this:
Breaking changes
The primary breaking change here is that the transform utilities are now dependent on the
@tailwind base
layer because of where we inject the universal rule. If you are only using@tailwind utilities
(probably because you don't want to use our reset styles), the transforms will stop working.The solution is to make sure you do include
@tailwind base
, but explicitly disable our preflight styles if you don't want those:/* Your custom existing CSS here... */ + @tailwind base; @tailwind utilities;
Aside from that, the main thing to understand is that there is no
transform
class anymore, so any authoring patterns that relied on being able to use that to enable transforms will break.For example, if you were conditionally adding the
transform
class using JS while leaving classes likescale-50
applied permanently, that will no longer work:Instead you would need to conditionally apply the actual transformations:
Another example is if you were using the
transform
class to manually switch from GPU rendering to CPU rendering at a specific breakpoint. I would be shocked if anyone is doing this in a real project in the wild:To do this now, you would write the HTML like this:
Notice that you don't need to re-specify
md:scale-50
like you would have historically.