# Select

#### [View on MongoDB.design](https://www.mongodb.design/component/select/live-example/)
## Installation
### PNPM
```shell
pnpm add @leafygreen-ui/select
```
### Yarn
```shell
yarn add @leafygreen-ui/select
```
### NPM
```shell
npm install @leafygreen-ui/select
```
## Example
### Basic Usage
```js
import { Option, OptionGroup, Select, Size } from '@leafygreen-ui/select';
;
```
### Typed Values
`Select` accepts an optional type parameter (defaulting to `string`) to narrow the type of `value`, `defaultValue`, and the `onChange` callback value:
```tsx
type Pet = 'dog' | 'cat' | '';
const [value, setValue] = useState('');
;
```
Note: when `allowDeselect` is enabled (default), deselecting calls `onChange` with `''` — include `''` in the union (as above) or set `allowDeselect={false}`.
Note: the type parameter narrows `value`, `defaultValue`, and `onChange` only — `Option` values are not checked against it (`
` and `` elements. | |
| `className` | `string` | Adds a className to the outermost element. | |
| `darkMode` | `boolean` | Determines whether or not the component will appear in dark mode. | `false` |
| `size` | `'xsmall'` \| `'small'` \| `'default'` \| `'large'` | Sets the size of the component's elements. | `'default'` |
| `id` | `string` | id associated with the Select component. | |
| `name` | `string` | The name that will be used when submitted as part of a form. | |
| `label` | `string` | Text shown in bold above the input element. | |
| `aria-labelledby` | `string` | Must be provided if and only if neither `label` nor `aria-label` is not provided. |
| `aria-label` | `string` | Must be provided if and only if neither `label` nor `aria-labelledby` is not provided. | |
| `description` | `React.ReactNode` | Text that gives more detail about the requirements for the input. | |
| `placeholder` | `string` | The placeholder text shown in the input element when an option is not selected. | `'Select'` |
| `disabled` | `boolean` | Disables the component from being edited. | `false` |
| `value` | `T` (defaults to `string`) | Sets the `
` that will appear selected and makes the component a controlled component. See [Typed Values](#typed-values). | `''` |
| `defaultValue` | `T` (defaults to `string`) | Sets the `
` that will appear selected on page load when the component is uncontrolled. See [Typed Values](#typed-values). | `''` |
| `onChange` | `SelectOnChange` | A function that gets called when the selected value changes. Receives the value (type `T`) as the first argument and the event as the second. See [Typed Values](#typed-values). | `() => {}` |
| `allowDeselect` | `boolean` | Enables or disables the option for a user to select a null default value. | `true` |
| `open` | `boolean` | Controls whether the dropdown menu is open. When provided, the component becomes a controlled component for the open state. | |
| `setOpen` | `function` | Callback function that is called when the open state should change. Required when `open` prop is provided. Receives a boolean value as the first argument. | |
| `renderMode` | `'inline'` \| `'portal'` \| `'top-layer'` | Options to render the popover element \* [deprecated] `'inline'` will render the popover element inline in the DOM where it's written \* [deprecated] `'portal'` will render the popover element in a new div appended to the body. Alternatively, can be portaled into a provided `portalContainer` \* `'top-layer'` will render the popover element in the top layer | `'top-layer'` |
| `portalContainer` | `HTMLElement` \| `null` | Sets the container used for the popover's portal. NOTE: If using a `scrollContainer` make sure that the `portalContainer` is contained within the `scrollContainer`. E.g, passing the same refrence to `scrollContainer` and `portalContainer`. | |
| `scrollContainer` | `HTMLElement` \| `null` | If the popover portal has a scrollable ancestor other than the window, this prop allows passing a reference to that lement to allow the portal to position properly. | |
| `portalClassName` | `string` | Passes the given className to the popover's portal container if the default portal container is being used. | |
| `popoverZIndex` | `number` | Sets the z-index CSS property for the popover. | |
| `state` | `'error'` \| `'none'` \| `'valid'` | Determines the state of the `