Closed tomdye closed 4 years ago
@tomdye here are some thoughts that I had on how to attack this issue. Please let me know what you think:
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:
onblur
$1,000,000.1234
step
text-input
widget and delegate most rendering responsibilities to ittext-input
, as appropriate, to provide above featurestext-input
but extend styling options to allow spinner arrows to be themed as well
text-input.m.css
module should be renamed input.m.css
and contain styles for all input-type controls?0.1
, then 3.1 would pass validation, but 3.14 would notformatter?: {
prefix?: string,
decimals?: number,
delimiter?: string
} |
(value: number): string
@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.
@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?
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.
@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.
The number input widget will be a base text input with opinionated defaults and
type: number
. It will expose properties such asmin
andmax
and other number related properties.These number specific properties should work well with native validation and our
onValidate
callback.