<Combobox> Component<ComboboxonSelect={(e) => console.log(e)}options={['Apple','Orange','Banana','Pineapple','Kiwi']}/>
| Name | Description |
|---|---|
label*string | A label for the combobox, used directly for aria-label |
options*array | Array of string values for the dropdown options |
onSelectfunction | A handler called when a new option is selected, takes the newly selected option value as its only parameter |
inputPropsobject | Props passed to the combobox input, props listed below are not an exhaustive list, conforms to React's InputHTMLAttributes Object contains nested props, see below: |
inputProps.onChangefunction | A onChange handler for the input |
inputProps.onBlurfunction | An onBlur handler for the input |
openOnFocusboolean | Controls whether the dropdown opens on focus of the input |
buttonLabelstring | Accessible label for the dropdown button |
invalidInputValueboolean | Declaratively mark the input as invalid, useful for form inputs (validation) |
renderOptionfunction | Render function to customize the display of options |
<ComboboxonSelect={(e) => console.log(e)}renderOption={opt => <span style={{ color: 'var(--consul)'}}>{opt}</span>}options={['Apple','Orange','Banana','Pineapple','Kiwi']}/>
<ComboboxBase onSelect={() => console.log('foo')}><ComboboxInput aria-labelledby="demo" /><ComboboxPopover><ComboboxList aria-labelledby="demo"><ComboboxOption value="Apple" /><ComboboxOption value="Banana" /><ComboboxOption value="Orange" /><ComboboxOption value="Pineapple" /><ComboboxOption value="Kiwi" /></ComboboxList></ComboboxPopover></ComboboxBase>
<FormikinitialValues={{ favoriteFruit: '' }}onSubmit={(values) => alert(JSON.stringify(values))}validateOnBlurvalidate={values => {const errors = {};const fruits = ['Apple','Orange','Banana','Pineapple','Kiwi']if (!fruits.includes(values.favoriteFruit)) {errors.favoriteFruit = 'Please select a value from the list';}return errors;}}>{({ handleSubmit }) => (<Form><ComboboxFieldname="favoriteFruit"options={['Apple','Orange','Banana','Pineapple','Kiwi']}/><button onClick={handleSubmit}>Submit!</button><FormikStateViewer /></Form>)}</Formik>