Skip to content
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

Request: an alternative number control/input #9769

Closed
robincornett opened this issue Sep 10, 2018 · 4 comments
Closed

Request: an alternative number control/input #9769

robincornett opened this issue Sep 10, 2018 · 4 comments
Labels
[Feature] UI Components Impacts or related to the UI component system [Type] Help Request Help with setup, implementation, or "How do I?" questions.

Comments

@robincornett
Copy link

Is your feature request related to a problem? Please describe.
I am working on converting a widget to be a block. There are a handful of number fields in my widget, but some of them are optional, and some have very large ranges (small or no minimum, very large maximum). The two issues I have are:

  • the large range fields are very difficult to manage with the RangeControl slider. You can see the case a bit with the Text Settings font size slider on the paragraph block. A larger range of numbers makes the slider unusable.
  • on the RangeControl input, the number is required. If I do not want the number to be required and set the initial value as an empty string, the block won't load because of this error: Error loading block: Invalid parameter(s): attributes

Describe the solution you'd like
I would like to have a NumberControl control with no range slider, and ideally it could accept a blank value.

Describe alternatives you've considered
I've currently got a RangeControl input working with the type set to string instead of number, but the slider is still problematic, so I probably really have to convert it to a TextControl. Either way, I have to add in an extra validation step to cast the value, if given, to an integer. So as an alternative, I can probably work around this, but I still would like a number field that is just a plain number input.

If this is already an option that's available, I apologize--I looked through the handbook list and did not find it.

@chrisvanpatten
Copy link
Member

@robincornett TextControl has a type prop, so you can pass number and you'll get an <input type="number">. Then you should be able to pass min, max, and step as additional props, or any other HTML5 number input attributes. Let me know if this helps!

@chrisvanpatten chrisvanpatten added [Type] Help Request Help with setup, implementation, or "How do I?" questions. [Feature] UI Components Impacts or related to the UI component system labels Sep 10, 2018
@youknowriad
Copy link
Contributor

Also, you're free to use any React component or self-made React component. Gutenberg just happens to use some and offer them for plugin authors.

@robincornett
Copy link
Author

Thank you, I was able to get the TextControl set to a number input. Interestingly, the error about the attributes persists if the field is left empty unless I set it to be a string instead of a number for the attribute type, so it appears that setting the attribute type to number somehow makes it a required field.

@Tofandel
Copy link

Yes that's default behavior, an empty string is not considered to be a number, you can try handling 0 or -1 as empty or have a switch control before the input to enable or disable the input

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] UI Components Impacts or related to the UI component system [Type] Help Request Help with setup, implementation, or "How do I?" questions.
Projects
None yet
Development

No branches or pull requests

4 participants