Select

import Select from 'frui/fields/Select';
Copy

Props

The following props are accepted by Select.

NameTypeRequiredNotes
classNamestringNoStandard HTML class names
defaultValuestringNoAlias to value
errorstring|booleanNoAny error message
namestringNoUsed for react server components.
onDropdownFunctionNoEvent handler when dropdown opens/closes
onSelectedFunctionNoEvent handler when an option has been selected
onUpdateFunctionNoUpdate event handler
optionsOption[]YesList of select options.
placeholderstringNoDisplay text when no value set
searchablebooleanNoAdd a search field
styleCSS ObjectNoStandard CSS object
valuestringNoSelected value from the options

Basics

The following is a basic example of a Select field.

Select Option
<Select className="w-full z-40 text-black" options={{ foo: 'Foo', bar: 'Bar' }} placeholder="Select Option" searchable />
Copy

You can also express options as an array of objects.

<Select 
  className="w-full z-20 text-black" 
  options={[
    { label: 'Foo', value: 'foo', keyword: 'foo' },
    { label: 'Bar', value: 'bar', keyword: 'bar' }
  ]}
/>
Copy

With array options, you can use React on labels.

Choose an Option
<Select 
  className="w-full z-30 text-black" 
  options={[
    { 
      label: (<strong className="font-bold">Foo</strong>), 
      value: 'foo', 
      keyword: 'foo' 
    },
    { 
      label: (<strong className="font-bold">Bar</strong>), 
      value: 'bar', 
      keyword: 'bar' 
    }
  ]}
/>
Copy

Events

The following example makes use of all the possible events for Select.

Choose an Option
<Select 
  className="w-full z-30 text-black" 
  options={{ foo: 'Foo', bar: 'Bar' }}
  onDropdown={open => console.log('dropdown', open)}
  onSelected={option => console.log('selected', option)}
  onUpdate={value => alert(JSON.stringify(value))}
/>
Copy

On Dropdown

The onDropdown event is triggered when the dropdown opens or closes. The following arguments are passed to the event handler:

NameTypeSample
openbooleantrue

On Selected

The onSelected event is triggered when an option has been selected. The following arguments are passed to the event handler:

NameTypeSample
optionSelectOption
{
  label: 'Foo',
  value: 'foo',
  keyword: 'foo'
}

On Update

The onUpdate event is triggered when the value has been updated. The following arguments are passed to the event handler:

NameTypeSample
valuestring`foo`

Errors

You can pass the error prop to highlight the Select field red.

Choose an Option
<Select options={{ foo: 'Foo', bar: 'Bar' }} className="w-full z-10 text-black" error={string|true} value="US" />
Copy

Custom Styles

You can add your own custom class to selects or use any of the respective frui-field-select, frui-field-select-control, frui-field-select-placeholder, frui-field-select-dropdown, frui-field-select-search, frui-field-select-search-control, frui-field-select-search-icon, frui-field-select-options, frui-field-select-option, and frui-field-select-label CSS classes.