-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Use inline
and block
for x/y utilities
#14805
Conversation
Not introduced in this PR, but it looks like we already use inline start/end on tailwindcss/packages/tailwindcss/src/utilities.ts Lines 2056 to 2068 in 5b2f6c7
I think this should be the equivalent: functionalUtility('space-x', {
supportsNegative: true,
themeKeys: ['--space', '--spacing'],
handle: (value) => [
atRoot([property('--tw-space-x-reverse', '0', '<number>')]),
rule(':where(& > :not(:last-child))', [
decl('--tw-sort', 'row-gap'),
- decl('margin-inline-start', `calc(${value} * var(--tw-space-x-reverse))`),
- decl('margin-inline-end', `calc(${value} * calc(1 - var(--tw-space-x-reverse)))`),
+ decl('margin-inline', `calc(${value} * calc(1 - var(--tw-space-x-reverse)))`),
]),
],
}) Even if we don't apply the tailwindcss/packages/tailwindcss/src/utilities.ts Lines 2070 to 2082 in 5b2f6c7
Updating this with functionalUtility('space-y', {
supportsNegative: true,
themeKeys: ['--space', '--spacing'],
handle: (value) => [
atRoot([property('--tw-space-y-reverse', '0', '<number>')]),
rule(':where(& > :not(:last-child))', [
decl('--tw-sort', 'column-gap'),
- decl('margin-top', `calc(${value} * var(--tw-space-y-reverse))`),
- decl('margin-bottom', `calc(${value} * calc(1 - var(--tw-space-y-reverse)))`),
+ decl('margin-block-start', `calc(${value} * var(--tw-space-y-reverse))`),
+ decl('margin-block-end', `calc(${value} * calc(1 - var(--tw-space-y-reverse)))`),
]),
],
}) Or, with a similar change I suggested for functionalUtility('space-y', {
supportsNegative: true,
themeKeys: ['--space', '--spacing'],
handle: (value) => [
atRoot([property('--tw-space-y-reverse', '0', '<number>')]),
rule(':where(& > :not(:last-child))', [
decl('--tw-sort', 'column-gap'),
- decl('margin-top', `calc(${value} * var(--tw-space-y-reverse))`),
- decl('margin-bottom', `calc(${value} * calc(1 - var(--tw-space-y-reverse)))`),
+ decl('margin-block', `calc(${value} * calc(1 - var(--tw-space-y-reverse)))`),
]),
],
}) |
Can't just use .space-x-4 {
/* Will be `0` without using `space-x-reverse` */
margin-inline-start: calc(1rem * var(--tw-space-x-reverse));
/* Will be `0` when you _do_ use `space-x-reverse` */
margin-inline-end: calc(1rem * calc(1 - var(--tw-space-x-reverse)));
}
Yeah I think we should do this, because |
This PR updates all of our x/y named utilities (like
px-*
,my-*
,inset-y-*
,scroll-px-*
, etc.) to use logical properties likepadding-inline
instead of separatepadding-left
andpadding-right
properties.We held off on this originally for a while because
inline
doesn't really mean horizontal like the "x" inpx-*
implies, but I think in practice this change is fine — I'm comfortable with "x" meaning "in the inline direction" and "y" meaning "in the block direction" in Tailwind.This is technically a breaking change if anyone was depending on the fact that
px-*
for instance was always explicitly settingpadding-left
andpadding-right
even when building something in a vertical writing mode, but I kinda doubt there's a single real project on the internet that will actually be affected, so not too worried about it.If someone really wants to set
padding-left
andpadding-right
they can always usepl-4 pr-4
instead ofpx-4
.Nice thing about this change is it produces quite a bit less CSS.
To test this change, I re-generated all of the snapshots and made sure none of the generated utilities changed position or anything in the output (initially they did before I updated
property-order.ts
to add some missing properties).I also created a little demo locally in the Vite playground to test things manually and make sure I didn't make any obvious typos or anything that could slip through the snapshots:
Show code for playground demo
I didn't manually test the scroll padding or scroll margin utilities because they are more annoying to set up, but I probably should.