<Select />
Select dropdown without a Label or Feedback
Additional Resources
selectStyles(showError, styles)
- Extract styling of this component for cases when react-select is used directly.
- Returns style and theme object to be spread on Select
- Args
showError?: boolean
if error styling should be appliedstyles?: StylesConfig object
refer to react-select docs for info on styles
Example
import React from 'react';
import { Form } from '@availity/form';
import Select, { SelectField } from '@availity/select';
import { Button } from 'reactstrap';
import * as yup from 'yup';
import '@availity/yup';
const Example = () => (
<Form
initialValues={{
justTheInput: undefined,
}}
onSubmit={(values) => window.alert(JSON.stringify(values))}
validationSchema={yup.object().shape({
justTheInput: yup.string().required('This field is required.'),
})}
>
<Select
id="justTheInput"
name="justTheInput"
isMulti={false}
options={[
{ label: 'Option 1', value: 1 },
{ label: 'Option 2', value: 2 },
{ label: 'Option 3', value: 3 },
]}
/>
<Button className="mt-3" color="primary" type="submit">
Submit
</Button>
</Form>
);
Live example: Storybook
Props
See react-select and react-select-async-paginate for additional props.
name: string
The name of the field. Will be the key of the selected option(s) that come through in the values of the onSubmit
callback of the form.
options: object[]
Array of options that populate the select menu. Grouped options are also supported, but must include the property type: 'group'
.
const groupedOptions = [
{
label: 'options',
options: [
{ label: 'Option 1', value: 'value for option 1' },
{ label: 'Option 2', value: 'value for option 2' },
{ label: 'Option 3', value: 'value for option 3' },
{ label: 'Option 4', value: 'value for option 4' },
],
type: 'group',
},
];
raw?: boolean
If true
, the entire object of the selected value is returned as the value instead of the value for the valueKey
within the object.
valueKey?: string
The key of the value to return when selected. Default: "value"
labelKey?: string
The key of the label to render in the dropdown for the user to see. Default: "label"