Skip to main content

Select Input

Allows a user to choose from a pre-defined list.

Examples

Basic Select Input

The SelectInput uses the browser's built-in <select> element under the hood to provide the best UX on mobile. Available in two sizes.

import { SelectInput } from '@curology/ui-components-web/react/SelectInput';
import { SelectOption } from '@curology/ui-components-web/react/SelectInput/SelectOption';

<SelectInput
required
label="Label"
placeholder="Placeholder"
id="default-input"
size="{sm|md(default)}"
>
<SelectOption value="a">Option A</SelectOption>
<SelectOption value="b">Option B</SelectOption>
<SelectOption value="c">Option C</SelectOption>
</SelectInput>

With Helper Text

More context, like an error message, can be provided via the helperText prop.

Helper Text
Helper Text
import { SelectInput } from '@curology/ui-components-web/react/SelectInput';
import { SelectOption } from '@curology/ui-components-web/react/SelectInput/SelectOption';

<SelectInput
...
helperText="Helper Text"
>
...
</SelectInput>

Critical, Warning, Success, and Disabled States

There are four additional states the SelectInput can be in, to indicate danger, warning, success or the inability to be controlled.

Some kind of error
Some kind of error
Some kind of warning
Some kind of warning
Some kind of success
Some kind of success
No touching!
No touching!
import { SelectInput } from '@curology/ui-components-web/react/SelectInput';
import { SelectOption } from '@curology/ui-components-web/react/SelectInput/SelectOption';

<SelectInput
...
state="{critical|warning|success}"
disabled
>
...
</SelectInput>

With Icon

An optional leading icon can be provided.

import { SelectInput } from '@curology/ui-components-web/react/SelectInput';
import { SelectOption } from '@curology/ui-components-web/react/SelectInput/SelectOption';

<SelectInput ... icon={<PlaceholderIcon />}>
...
</SelectInput>

Loading

When the loading prop is provided, the content of the SelectInput will be hidden, replaced by a spinning loader. The input will no longer be active. This is useful when loading the values of the select asynchronously.

import { SelectInput } from '@curology/ui-components-web/react/SelectInput';
import { SelectOption } from '@curology/ui-components-web/react/SelectInput/SelectOption';

<SelectInput
...
loading
>
...
</SelectInput>

Controlled Select Input

Like all form inputs, a SelectInput can either be uncontrolled, or controlled (by providing a value and onChange listener).

import { SelectInput } from '@curology/ui-components-web/react/SelectInput';
import { SelectOption } from '@curology/ui-components-web/react/SelectInput/SelectOption';

<SelectInput
...
value={someValue}
onChange={(evt, value) => ...}
>
...
</SelectInput>

Props

SelectInputProps

NameTypeDefault ValueRequiredDescription
All attributes of a <input />
fieldClassNamestringNoA className to apply to the field.
fieldPropsRecord<string, unknown>NoAny props to spread onto the field container.
helperTextReactNodeNoA string or component to display as helper text beneath the input
highlightReactNodeNoHighlighted helper text to display at the bottom of the multiline text input
highlightClassNamestringNoA className to apply to the highlight.
iconComponentClass<any, any> | FunctionComponent<any> | ReactElement<any, string | JSXElementConstructor<any>> | ForwardRefExoticComponent<any>NoAn icon to render at the front of the input.
labelReactNodeNoA string or component to display as a label above the input
loadingfalse | truefalseNoShould the input display a loading state? Useful when options are being loaded via a remote request.
onChangeFormControlChangeEventHandlerNoEmit a new value when the input's selected value changes.
placeholderstringNoText to display when there is no selected value.
requiredfalse | truefalseNoIs the field required?
size"md" | "sm"'md'NoThe size of the field
state"" | "critical" | "warning" | "success"''NoThe state of the field

SelectOptionProps

NameTypeDefault ValueRequiredDescription
All attributes of a <option />