$ npm i jd-react-select --save
Import the component
import { Select } from 'jd-react-select';
import '@/../jd-react-select/dist/components/Select.css';
import { SelectOption } from '@/../jd-react-select/dist/components/Select';
Now, you can use it:
example:
const options = [
{ label: 'First', value: 1 },
{ label: 'Second', value: 2 },
{ label: 'Third', value: 3 },
{ label: 'Fourth', value: 4 },
{ label: 'Fifth', value: 5 },
];
example:
const [value2, setValue2] = useState<SelectOption | undefined>(options[0]);
If you want to have a default value be selected when you component initializes, you can set the default state to (options[0]) to have the initial value of the select component be the first value in the options array.
<Select options={options} value={value} onChange={(value) => setValue(value)} />
example:
const options = [
{ label: 'First', value: 1 },
{ label: 'Second', value: 2 },
{ label: 'Third', value: 3 },
{ label: 'Fourth', value: 4 },
{ label: 'Fifth', value: 5 },
];
example:
const [value, setValue] = useState<SelectOption[]>([options[0]]);
If you want to have a default value be selected when you component initializes, you can set the default state to (options[0]) to have the initial value of the select component be the first value in the options array.
<Select
multiple
options={options}
value={value}
onChange={(value) => setValue(value)}
/>
To let the component know you want to have multiple selected values, pass in the multiple parameter.
const options = [
{ label: 'First', value: 1, avatar: imageURL },
];
By default the key for the object will be its value, you can override this by including an id. The id can be either a string or number.
const options = [
{ label: 'First', value: 1, id: string | number },
];
Default: []
Description: An array of strings or objects to be used as dropdown items. If
you are using an array of objects, ensure you have a label
key. e.g
[{label: 'Label', value: 'Value'}])
.
Default: null
Description: Specifies the currently selected item. value
can be from
list
or manually set.
Default: false
Description: Specifies the if the select component can have multiple values selected at once.
Default: false
Description: Specifies the if the select component options can have avatars. For multi select components where this is true, an avatar will also be added to the option-badge for selected options.
Default: false
Description: Specifies the if the select component has a divider line to the left of the down arrow.
You can fully customize the styles for the select component by targeting the class names in your stylesheet.
example:
.container
// Overwrite the select container
Since there are a lot of classnames, instead of writing them all here, inspect the select component in your DevTools
to see all the classes!