Select
The select component allows users to make single or multiple selections from a pre-defined list of options.
Name | Type | Description | Default |
---|---|---|---|
defaultValue | string | string[] | Initial value of the select, only when it is uncontrolled. | - |
value | string | string[] | Value of the select. If undefined, the component will be uncontrolled and the value will be managed internally by the component. | - |
label | string | Text to be placed above the select. | - |
name | string | Name attribute of the input element. This attribute will allow users to find the component's value during the submit event. In this event, the component's value will always be a regular string, for both single and multiple selection modes, being a single option value in the first case and more than one value when multiple selection is available, separated by commas. | - |
Required | ({ label: string, value: string, icon: (string | React.ReactNode & React.SVGProps <SVGSVGElement>) })[] | ({ label: string, options: Option[] })[] | An array of objects representing the selectable options. Each object has the following properties depending on whether it is a regular option or a group: Option
| - |
helperText | string | Helper text to be placed above the select. | - |
placeholder | string | Text to be put as placeholder of the select. | - |
searchable | boolean | If true, enables search functionality. | false |
multiple | boolean | If true, the select component will support multiple selected options. In that case, value will be an array of strings with each selected option value. | false |
disabled | boolean | If true, the component will be disabled. | false |
optional | boolean | If true, the select will be optional, showing '(Optional)' next to the label and adding a default first option with an empty string as value and the placeholder (if defined) as its label. Otherwise, the field will be considered required and an error will be passed as a parameter to the onBlur and onChange functions if an option wasn't selected. | false |
onChange | (val: { value: string | string[]; error?: string }) => void | This function will be called when the user selects an option. An object including the new value (or values) and the error (if the value selected is not valid) will be passed to this function. If there is no error, error will not be defined. | - |
onBlur | (val: { value: string | string[]; error?: string }) => void | This function will be called when the select loses the focus. An object including the value (or values) and the error (if the value selected is not valid) will be passed to this function. If there is no error, error will not be defined. | - |
error | string | If it is a defined value and also a truthy string, the component will change its appearance, showing the error below the select component. If the defined value is an empty string, it will reserve a space below the component for a future error, but it would not change its look. In case of being undefined or null, both the appearance and the space for the error message would not be modified. | - |
margin | 'xxsmall' | 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge' | 'xxlarge' | Margin | Size of the margin to be applied to the component. You can pass an object with 'top', 'bottom', 'left' and 'right' properties in order to specify different margin sizes. | - |
size | 'small' | 'medium' | 'large' | 'fillParent' | Size of the component. | 'medium' |
tabIndex | number | Value of the tabindex attribute. | 0 |
ref | React.Ref <HTMLDivElement> | Reference to the component. | - |