Description
Field.Number
is the base component for receiving user input where the target data is of type number
.
Demos
Empty
<Field.Number onChange={(value) => console.log('onChange', value)} />
Placeholder
<Field.Numberplaceholder="Enter a number"onChange={(value) => console.log('onChange', value)}/>
Label
<Field.Numberlabel="Label text"onChange={(value) => console.log('onChange', value)}/>
Label and value
<Field.Numbervalue={420000.25}label="Label text"onChange={(value) => console.log('onChange', value)}/>
Horizontal layout
<Field.Numbervalue={420000}label="Label text"layout="horizontal"onChange={(value) => console.log('onChange', value)}/>
Widths
<Field.Numberlabel="Default width (property omitted)"value={123}onChange={(value) => console.log('onChange', value)}/><Field.Numberlabel="False (for browser default)"value={123}width={false}onChange={(value) => console.log('onChange', value)}/><Field.Numberlabel="Medium"value={123}width="medium"onChange={(value) => console.log('onChange', value)}/><Field.Numberlabel="Large"value={123}width="large"onChange={(value) => console.log('onChange', value)}/><Field.Numberlabel="Stretch"value={123}width="stretch"onChange={(value) => console.log('onChange', value)}/>
Disabled
<Field.Numbervalue={135}label="Label text"onChange={(value) => console.log('onChange', value)}disabled/>
Info
Useful information (?)
<Field.Numbervalue={135}label="Label text"onChange={(value) => console.log('onChange', value)}info="Useful information (?)"/>
Warning
I'm warning you...
<Field.Numbervalue={135}label="Label text"onChange={(value) => console.log('onChange', value)}warning={new FormError("I'm warning you...")}/>
Error
This is what is wrong...
<Field.Numbervalue={135}label="Label text"onChange={(value) => console.log('onChange', value)}error={new FormError('This is what is wrong...')}/>
Validation - Required
<Field.Numbervalue={123}label="Remove and blur field"onChange={(value) => console.log('onChange', value)}required/>
Validation - Minimum
<Field.Numbervalue={300}label="Enter a number below 250 and blur to trigger error"onChange={(value) => console.log('onChange', value)}minimum={250}/>
Validation - Maximum and custom error message
<Field.Numbervalue={200}label="Enter a number above 250 and blur to trigger error"onChange={(value) => console.log('onChange', value)}maximum={250}errorMessages={{maximum: "You can't enter a number THAR large.. Max 250!",}}/>
Properties
Standard input component props
Property | Type | Description |
---|---|---|
data-testid | string | (optional) Test ID |
className | string | (optional) Outer DOM element class name |
value | number | (optional) Source data value for the input |
layout | string | (optional) Layout for the label and input. Can be horizontal or vertical |
label | string | (optional) Field label to show above / before the input feature |
labelDescription | string | (optional) A more discreet text displayed beside the label (i.e for "(optional)") |
labelSecondary | string | (optional) Secondary information displayed at the end of the label line (i.e character counter) |
placeholder | string | (optional) Text showing in place of the value if no value is given |
path | string | (optional) JSON Pointer for where the data for this input is located in the source dataset (when using DataContext) |
info | Error or string | (optional) Info message shown below / after the input |
warning | Error or string | (optional) Warning message shown below / after the input |
error | Error | (optional) Error message shown below / after the input |
disabled | boolean | (optional) Set true to show the field but without the possibility of changing the value. |
emptyValue | any | (optional) The value to use (in onChange events etc) when emptying the field. Makes it possible for instance to provide undefined instead of an empty string when clearing the content of a text input. |
required | boolean | (optional) When set true , the input will give an error if the value cannot be empty. |
schema | object | (optional) Custom JSON Schema for validating the value. |
validateInitially | string | (optional) Set true to show validation based errors initially (from given value-prop or source data) before the user interacts with the field. |
validateUnchanged | string | (optional) Set true to show validation based errors when the field is touched (like focusing a field and blurring) without having changed the value. Since the user did not introduce a new error, this will apply when the value was initially invalid based on validation. |
continuousValidation | string | (optional) Set true to show validation based errors continuously while writing, not just when blurring the field. |
errorMessages | object | (optional) Custom error messages for each type of error, overriding default messages. |
validator | function | (optional) Custom validator function that will be called for every change done by the user. Can be asynchronous or synchronous. |
onBlurValidator | function | (optional) Custom validator function that will be called when the user leaves the field (blurring a text input, closing a dropdown etc). Can be asynchronous or synchronous. |
toInput | function | (optional) Derivate called when the received / active value is sent to the input. Can be used for casting, changing syntax etc. |
fromInput | function | (optional) Derivate called when changes is made by the user, to cast or change syntax back to the original (opposite of toInput ). |
Component-specific props
Property | Type | Description |
---|---|---|
thousandSeparator | string | (optional) Character to use for separating every three digits. |
decimalSymbol | string | (optional) What character to use for separating digits and decimals. Defaults to ','. |
decimals | number | (optional) Max number of decimals. Values with more decimals will be rounded. |
fixedDecimals | number | (optional) Fixed number of decimals. Will round numbers with more decimals, and add trailing zeros when less. |
prefix | string | (optional) Text added before the value input. |
suffix | string | (optional) Text added after the value input. |
minimum | number | (optional) Validation for inclusive minimum number value (greater than or equal). |
maximum | number | (optional) Validation for inclusive maximum number value (less than or equal). |
exclusiveMinimum | number | (optional) Validation for exclusive minimum number value (greater than). |
exclusiveMaximum | number | (optional) Validation for exclusive maximum number value (less than). |
multipleOf | number | (optional) Validation that requires the number to be a multiple of given value. |
width | string or false | (optional)false for no width (use browser default), medium or large for predefined standard widths, stretch for fill available width. |
space | object | (optional)Space object with keys: top , right , bottom and left |
Events
Event | Description |
---|---|
onChange | (optional) Will be called on value changes made by the user, with the new value as argument. |
onFocus | (optional) Will be called when the component gets into focus. Like clicking inside a text input or opening a dropdown. Called with active value as argument. |
onBlur | (optional) Will be called when the component stop being in focus. Like when going to next field, or closing a dropdown. Called with active value as argument. |