A simple and customizable React dropdown select component supporting single, multi, and grouped options.
Checkout Demo of react-select
name property so that if the ReactSelect is inside a form, it can be accessed.
value as the value of the selected optionraw, containing JSON.stringify-ed of the full data of the selected optioncontrolled to uncontrolled input problem by using state. Not new state, already used statename in form# using npm
npm install @theprojectsx/react-select
# using yarn
yarn add @theprojectsx/react-select
import React, { useState } from "react";
import ReactSelect, { Option, GroupedOption } from "@theprojectsx/react-select";
const options: Option[] = [
{ label: "Apple", value: "apple" },
{ label: "Banana", value: "banana" },
];
export default function App() {
const [selected, setSelected] = useState<Option | Option[] | null>(null);
return (
<ReactSelect
options={options}
placeholder="Select an option"
isClearable
onChange={setSelected}
/>
);
}
| Prop | Type | Default | Description |
|---|---|---|---|
options |
Option[] \| GroupedOption[] |
- | Items to display in the dropdown |
defaultValue? |
Option \| Option[] \| null |
null |
Initial selected value |
placeholder? |
string |
"Select..." |
Placeholder text |
name? |
string |
select |
Input name attribute to use in form |
isClearable? |
boolean |
false |
Whether selection can be cleared |
isSearchable? |
boolean |
true |
Enable search in the dropdown |
isDisabled? |
boolean |
false |
Disable the select |
isGrouped? |
boolean |
false |
Enable grouped options |
isMulti? |
boolean |
false |
Enable multi-select |
parentStyle? |
React.CSSProperties |
- | Inline style for parent container |
menuStyle? |
React.CSSProperties |
- | Inline style for dropdown menu |
onChange? |
(item: Option \| Option[] \| null) => void |
- | Callback triggered on value change |
onMenuStatusChange? |
(status: boolean) => void |
- | Callback when menu opens/closes |
onSearch? |
(value: string) => void |
- | Callback for search input |
MIT License @TheProjectsX