<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 |
onSelect function | A handler called when a new option is selected, takes the newly selected option value as its only parameter |
inputProps object | 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.onChange function | A onChange handler for the input |
inputProps.onBlur function | An onBlur handler for the input |
openOnFocus boolean | Controls whether the dropdown opens on focus of the input |
buttonLabel string | Accessible label for the dropdown button |
invalidInputValue boolean | Declaratively mark the input as invalid, useful for form inputs (validation) |
renderOption function | 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>