UnitControl: Add support for unit step per unit type#30376
UnitControl: Add support for unit step per unit type#30376mcsf merged 13 commits intoWordPress:trunkfrom
Conversation
| 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.
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.
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) |
mcsf
left a comment
There was a problem hiding this comment.
Thanks for cleaning up. Here's my review.
| 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.
Do we still need anything here?
Co-authored-by: Miguel Fonseca <miguelcsf@gmail.com>
remove setting default first unit tidy code + comments
Co-authored-by: Miguel Fonseca <miguelcsf@gmail.com>
|
Thanks @mcsf , now done - I didn't understand those fails on |
dcalhoun
left a comment
There was a problem hiding this comment.
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
RangeCellandStepperCellboth have astepproperty 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
stepvalue and pass that into our number input, if it is not present, default to a step of1Checklist:
*.native.jsfiles for terms that need renaming or removal).*Update - I guess this also builds on: #31314