-
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
New NumberControl component #13863
New NumberControl component #13863
Conversation
…spinners." This reverts commit d26c659.
Not sure if I should update existing components in the same PR or if they should be done individually after the NumberControl component is merged. |
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.
Thank you for your contribution @m-e-h, I think it may make sense to expose a very simple component that just renders a number input field.
Using it as the basis for other components may make the work of creating reactive native components simpler as it reduces direct dom usage.
But I would like more thoughts about creating a new component cc: @youknowriad
value={ this.fractionToPercentage( percentages.x ) } | ||
/> | ||
|
||
<NumberControl |
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 looks like here we have a NumberControl inside a BaseControl. NumberControl renders its own BaseControl component so I think the existing BaseControl can also be removed.
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 looking @jorgefilipecosta! I'm open to any tips or ideas here. I'm pretty new to the components code.
Yeah, we could do away with the BaseControl around each input here with the focal-point-picker. Will have to restyle though to handle the <span>%</span>
appended to each.
Might even be worth adding a numericUnit
prop in the NumberControl to handle it.
display: inline-block; | ||
font-weight: 500; | ||
height: 30px; | ||
width: 54px; |
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.
Love the idea of a dedicated NumberControl but nervous about defining the width here. This makes it tougher to use as a full-width control. Maybe there could be a modifier class (.components-number-control__input--narrow
or something like that) which applies the width constraint?
Noting that the |
Whoa. I hadn't even thought of that @youknowriad. I think there are enough blocks ignoring that and using their own number input that it warrants it's own component. Better to repeat the TextControl once as a new component than to repeat similar code each time a number input is used. Wondering though if a NumberControl component should just import the |
I like the idea of a dedicated |
One challenge I ran into when trying to use the It's likely that I'm missing something. Is there a different way I should be doing it? |
That doesn't change anything for me. If the value is not changing, it simply means the |
A generic component shouldn't assume an
Never do both together. Some controls in the codebase are misleading, for example the |
I updated this to better handle id and aria-label per @afercia I'm sticking with wrapping this in it's own I also added an optional I also updated the spacer block to see how the |
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.
Hi @m-e-h,
Thank you for iterating on this PR.
I did a set of tests, and this PR seems almost ready, I just left some minor suggestions.
Besides the suggestions, I think this PR needs a "New Features" changelog entry in https://github.com/WordPress/gutenberg/blob/master/packages/components/CHANGELOG.md#720-unreleased, and a rebase.
{ ...props } | ||
/> | ||
|
||
{ numberUnit && ( |
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.
Maybe we can update the Number control, to pass children to base control. It would allow us to remove the need for a numbeUnit prop making the component simpler. Current usages would only need to pass span prop with the unit like they do now.
@@ -89,10 +89,9 @@ function RangeControl( { | |||
max={ max } | |||
{ ...props } /> | |||
{ afterIcon && <Dashicon icon={ afterIcon } /> } | |||
<input | |||
<NumberControl |
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.
Range control is a complex control in itself with validation logic that was recently added. The component already uses a BaseControl so using a NumberControl here would result in a BaseControl nested inside another BaseControl. I would prefer if we did not use NumberControl inside RangeControl at least for now.
numberUnit, | ||
...props | ||
} ) { | ||
const onChangeValue = ( event ) => onChange( Number( event.target.value ) ); |
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.
Maybe we can change this line to:
const onChangeValue = ( event ) => onChange(
event.target.value === '' ? undefined : Number( event.target.value )
);
The current version causes a bug -- it becomes impossible to have the field empty. It is possible to reproduce the bug testing the spacer.
The bug happens because Number('') === 0;
What is the status of this PR? |
This can probably be closed. The goal here was mostly to clean up the UI style variations across the different number inputs. |
Description
Adds a
<NumberControl>
component for use in other components and blocks.Would reduce duplicate code and create a consistent style across existing components that are creating their own number inputs. Currently, this would be font-size-picker, focal-point-picker, and range-control that I know of. Probably others.
Types of changes
New feature (non-breaking change which adds functionality)
Checklist:
Inspired by #13709 and #11555