-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Adjust the custom range steps to match the units chosen #44959
Conversation
Size Change: +272 B (0%) Total Size: 1.27 MB
ℹ️ View Unchanged
|
8ad68cb
to
e0c71be
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works well 👍
I noticed a couple of things, but they're only partially related to this change (and happen in trunk, so outside the scope of this PR).
- Switching between em/rem to px can be a way to 'hack' a floating px value. When manually typing in 10.1px, as soon as I unfocus it resets to 10px. OTOH if I first set 10.1em, and then switch from em to px, the value stays at 10.1px. Very low priority issue, but it's a little bit of an inconsistency around how values are handled.
- The slider still has the same 300 max value for em/rm as it does for px, which makes adjusting to a precise decimal value difficult. The increment is really around 0.5 because of the size and scale of the slider. Because the ems/rems have a more pronounced effect, this makes it a little hard to use. It's more noticeable for border controls though, because only a very small portion of the slider is actually usable for setting a resonable em/rem border.
@@ -228,6 +228,9 @@ export default function SpacingInputControl( { | |||
value={ customRangeValue } | |||
min={ 0 } | |||
max={ 300 } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressing thje comment by @talldan above, we should probably change the max
value depending on the selectedUnit
. This sets max to 300 if using px
, and 10 for other units.
max={ 300 } | |
max={ | |
'px' === selectedUnit ? 300 : 10 | |
} |
Other than that, the PR looks good so I'll go ahead and pre-approve it pending this tweak 👍
Thanks @talldan, @aristath - looking a bit closer it seems like we need 3 different max values, 300 for px, 100 for %, vh, vw and 10 for rem,em, with only rem and em needing 0.1 increments. I have adjusted it to match the above, let me know if you see any problems with this breakdown of the max values. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works well.
Should those new max values also be applied to other controls like border? It can be a seperate PR/issue, but lets make sure it's tracked.
I left a few optional/opinionated comments about the code, but feel free to merge if you're happy.
maxCustomValues[ selectedUnit ] | ||
? maxCustomValues[ selectedUnit ] | ||
: 10 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could possibly change this to maxCustomValues[ selectedUnit ] ?? 10
, but I also wonder why em
and rem
are excluded from maxCustomValues
?
step={ | ||
[ 'px', '%', 'vh', 'vw' ].includes( selectedUnit ) | ||
? 1 | ||
: 0.1 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be good to do this the same way maxCustomValues
works, extract it out to a variable.
@@ -163,6 +163,8 @@ export default function SpacingInputControl( { | |||
! showCustomValueControl && | |||
currentValueHint !== undefined; | |||
|
|||
const maxCustomValues = { px: 300, '%': 100, vw: 100, vh: 100 }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be moved to file scope and named MAX_CUSTOM_VALUES
to avoid the little bit of overhead of redefining it on every render.
Thanks for the feedback @talldan. What do you think of this approach to tidy it all up? If you think this works it would probably make sense to extract |
Looks good 👍
I had that thought too. If there's somewhere that works well it could help with consistency across components. I would wait until the need arises though (i.e. if this same approach is used for border) |
What?
Aligns the spacing custom range control steps with the units chosen
Why?
Other custom ranges, like Border, use a
1
step forpx, %
and0.1
for others, so Spacing sizing should work the same.How?
Checks selected unit and sets step accordingly.
Testing Instructions
%
orpx
is set that range control has steps of1
, and0.1
for other unitsScreenshots or screencast
Before:
steps-before.mp4
After:
steps-after.mp4