-
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
UnitControl: Add support for unit step per unit type #30376
Conversation
@@ -22,6 +22,7 @@ import { Root, ValueInput } from './styles/unit-control-styles'; | |||
import UnitSelectControl from './unit-select-control'; | |||
import { CSS_UNITS, getParsedValue, getValidParsedUnit } from './utils'; | |||
import { useControlledState } from '../utils/hooks'; | |||
// import { active } from '@wp-g2/styles/types'; |
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 was causing my local build to fail, and it wasn't in use - so I've commented it for now
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.
Do we still need anything here?
add comments
@ItsJonQ - thought I would flag you on this as you've been working on the previous iterations and will have a sense if this is in the right direction. |
What are all the changes to |
Hmm there shouldn't have been, maybe a bad merge on my side, I'll double check later on today and see if I can get this tidied up. |
@rmorse: thanks for the PR. Ensuring that certain units, like
The component does accept @nosolosw: is the addition of units to If so, then @rmorse, we could go with your suggestion to provide let step = stepProp;
if ( ! step ) {
const activeUnit = units.find( ( option ) => option.value === unit );
step = activeUnit?.step ? activeUnit.step : 1;
} My last note is to treat the non-unit, |
Things that relate to this from the "theme.json" perspective are:
|
@mcsf - I've updated that. To confirm logic:
I've added your suggestion to the PR (and also added a condition to default to the first unit type, if somehow one wasn't found) |
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.
Thanks for cleaning up. Here's my review.
@@ -22,6 +22,7 @@ import { Root, ValueInput } from './styles/unit-control-styles'; | |||
import UnitSelectControl from './unit-select-control'; | |||
import { CSS_UNITS, getParsedValue, getValidParsedUnit } from './utils'; | |||
import { useControlledState } from '../utils/hooks'; | |||
// import { active } from '@wp-g2/styles/types'; |
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.
Do we still need anything here?
Co-authored-by: Miguel Fonseca <[email protected]>
remove setting default first unit tidy code + comments
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.
Hey, @rmorse, we're almost there! Please apply these last fixes, and we should be good to go.
Co-authored-by: Miguel Fonseca <[email protected]>
Thanks @mcsf , now done - I didn't understand those fails on |
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.
🚢
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.
LGTM. I tested the changes for native on an iPhone 11 simulator and Samsung Galaxy S20 to test for any regressions.
I also opened wordpress-mobile/gutenberg-mobile#3479 to allow additional native CI tests to run for this change. I'd recommend awaiting those to pass before merging.
The current failures in wordpress-mobile/gutenberg-mobile#3479 are unrelated to the changes in this PR and have been resolved in wordpress-mobile/gutenberg-mobile#3477. We should be good to go for merging this work. 👍🏻 |
Thanks for everyone’s help! |
Description
The UnitControl component does not support a "step" value. Therefor it always increments exactly by 1.
This is probably not desired for certain unit types (i.e., rem, em, etc) in certain situations.
This update, allows for adding a "step" property to the units argument - so it can be controlled on a per unit type basis:
So we can now do this:
It defaults to a value of 1, if the unit type does not contain a step (for backwards compatibility).
Personally, I wanted to use this as an improved "Line height" control, that also supports units, and the first unit is blank:
{ value: '', label: '', default: 1, step: 0.1 },
But I think there is a good argument for supporting different steps for different use cases on a per unit basis.
How has this been tested?
I've tested the component by following the example, by suppling a step, and without.
All incremements behave as expected.
I have not tested the React Native stuff - but I have updated the code. I checked, and it looks like
RangeCell
andStepperCell
both have astep
property so this should work - can someone test this? (I'm not sure how to)Screenshots
Don't worry about the value reset on unit change - this is not hooked up to state.
This example uses the following props for unit types (notice 0.1 step on
em
,rem
, and empty)Types of changes
Minor improvement - we check the unit types argument, for a
step
value and pass that into our number input, if it is not present, default to a step of1
Checklist:
*.native.js
files for terms that need renaming or removal).*Update - I guess this also builds on: #31314