dojo / widgets

:rocket: Dojo - UI widgets.
https://widgets.dojo.io
Other
89 stars 66 forks source link

Number input widget #790

Closed tomdye closed 4 years ago

tomdye commented 5 years ago

The number input widget will be a base text input with opinionated defaults and type: number. It will expose properties such as min and max and other number related properties.

These number specific properties should work well with native validation and our onValidate callback.

vansimke commented 5 years ago

@tomdye here are some thoughts that I had on how to attack this issue. Please let me know what you think:

Plan

The Number widget will present itself as a normal text input control with additional properties and behaviors that specialize it to work only with numerical data. The following features are planned:

Features

Implementation

tomdye commented 5 years ago

@vansimke I think that the scope of this task should be to implement a basic number input which simply restricts the currently large set of TextInputProperties and sets the input type to number. I believe that at this stage we would rely on default browser / mobile os interaction for increment / decrement and native html5 validation via the existing onValidate / valid properties.

Regarding formatting, I think that this could take some default properties for formatting, ie. commaSeparatedThousands: boolean, maxDecimals: number etc and this would be automatically done before calling the standard onValue callback. Any other custom formatting would be done by the parent widget via its onValue callback.

Regarding currency formatting and display, I believe this would be a further Currency input built on top of this one which would offer some currency defaults ie currency: 'us' perhaps which would use a leading renderer for the currency symbol and apply appropriate decimal / thousands separators.

vansimke commented 5 years ago

@tomdye If we use the native number input, I think that will prevent us from doing any of the formatting settings, yes? I'm okay with that, but if we want to go that way, I would probably eliminate the format-related properties (delimiter, decimals, prefix, and formatter). Do you agree?

vansimke commented 5 years ago

As I've thought about the conversation that I had with @agubler and based on the feedback from @tomdye, I think I'm going to start out by refactoring out a common Input widget from the current TextInput. The idea is that this widget will serve as a generic element that can morph into each of the various input types and, as a result, will probably end up with a ton of properties. The TextInput, and eventually the NumberInput widgets will then wrap this widget and narrow the interface to provide the specific functionality for each type (e.g. minLength and maxLength for TextInput and min, max, and step for NumberInput).

I'm going to start by factoring out the Input widget and get a draft PR started to allow feedback on what works and what doesn't.

tomdye commented 5 years ago

@vansimke I don't think that you need to refactor out the existing text input into anything more generic at this time. It should work fine as it is using the current TextInput.

re. formatting, i think it's ok to start with the simple number input for now.