DataInput.Select
DataInput.Select is a wrapper component for selecting between options using a dropdown or similar user experiences.
Demos
Empty
<DataInput.Select onChange={(value) => console.log('onChange', value)}><DataInput.Option value="foo" title="Foo!" /><DataInput.Option value="bar" title="Baar!" /></DataInput.Select>
Placeholder
<DataInput.Selectplaceholder="Select something...."onChange={(value) => console.log('onChange', value)}><DataInput.Option value="foo" title="Foo!" /><DataInput.Option value="bar" title="Baar!" /></DataInput.Select>
Label
<DataInput.Selectlabel="Label text"onChange={(value) => console.log('onChange', value)}/>
Option selected
<DataInput.Selectvalue="bar"onChange={(value) => console.log('onChange', value)}><DataInput.Option value="foo" title="Foo!" /><DataInput.Option value="bar" title="Baar!" /></DataInput.Select>
Label and option sleected
<DataInput.Selectvalue="bar"label="Label text"onChange={(value) => console.log('onChange', value)}><DataInput.Option value="foo" title="Foo!" /><DataInput.Option value="bar" title="Baar!" /></DataInput.Select>
Disabled
<DataInput.Selectvalue="bar"label="Label text"onChange={(value) => console.log('onChange', value)}disabled><DataInput.Option value="foo" title="Foo!" /><DataInput.Option value="bar" title="Baar!" /></DataInput.Select>
Error
<DataInput.Selectvalue="bar"label="Label text"onChange={(value) => console.log('onChange', value)}error={new FormError('This is what is wrong...')}><DataInput.Option value="foo" title="Foo!" /><DataInput.Option value="bar" title="Baar!" /></DataInput.Select>
High number of options
<DataInput.Selectvalue="option-15"label="Label text"onChange={(value) => console.log('onChange', value)}><DataInput.Option value="option-1" title="One" /><DataInput.Option value="option-2" title="Two" /><DataInput.Option value="option-3" title="Three" /><DataInput.Option value="option-4" title="Four" /><DataInput.Option value="option-5" title="Five" /><DataInput.Option value="option-6" title="Six" /><DataInput.Option value="option-7" title="Seven" /><DataInput.Option value="option-8" title="Eight" /><DataInput.Option value="option-9" title="Nine" /><DataInput.Option value="option-10" title="Ten" /><DataInput.Option value="option-11" title="Eleven" /><DataInput.Option value="option-12" title="Twelve" /><DataInput.Option value="option-13" title="Thirteen" /><DataInput.Option value="option-14" title="Fourteen" /><DataInput.Option value="option-15" title="Fifteen" /><DataInput.Option value="option-16" title="Sixteen" /><DataInput.Option value="option-17" title="Seventeen" /><DataInput.Option value="option-18" title="Eighteen" /><DataInput.Option value="option-19" title="Nineteen" /><DataInput.Option value="option-20" title="Twenty" /><DataInput.Option value="option-21" title="Twentyone" /><DataInput.Option value="option-22" title="Twentytwo" /><DataInput.Option value="option-23" title="Twentythree" /><DataInput.Option value="option-24" title="Twentyfour" /><DataInput.Option value="option-25" title="Twentyfive" /></DataInput.Select>
Validation - Required
<DataInput.Selectlabel="Label text"onChange={(value) => console.log('onChange', value)}requiredvalidateInitiallyvalidateUnchanged><DataInput.Option value="foo" title="Foo!" /><DataInput.Option value="bar" title="Baar!" /></DataInput.Select>
Properties
Standard input component props
Property | Type | Description |
---|---|---|
data-testid | string | (optional) Test ID |
className | string | (optional) Outer DOM element class name |
value | number | string | (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 discreent 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 |
---|---|---|
children | React.Node | (optional) For providing Option components |
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. |