# Select A Dropdown control for selecting from a list of options. ## Import ```tsx import { Select } from '@coinbase/cds-web/controls/Select' ``` ## Examples ### Default Composition `Select` can take anything as a child, however, we strongly recommend that you use `SelectOption`. It has the same API as a `ListCell`, but with custom styles specific to usage within a `Select`. `SelectOption` also comes with a lot of baked in functionality, like keyboard navigation, accessibility properties, and focus behaviors. ```jsx live function DefaultSelect() { const [value, setValue] = useState(); const options = ['Option 1', 'Option 2', 'Option 3', 'Option 4', 'Option 5', 'Option 6']; return ( {options.map((option) => ( ))} ); } ``` ### Value/Label Object Model Sometimes you may want to surface a label instead of the select value. You can pass a `valueLabel` prop with the currently selected value's corresponding label, which will appear to be the value of the Select. ```jsx live function DefaultSelect() { const [value, setValue] = useState(); const options = [ { value: '1', label: 'Option 1' }, { value: '2', label: 'Option 2' }, { value: '3', label: 'Option 3' }, { value: '4', label: 'Option 4' }, ]; const selectedValueLabel = value && options.find((option) => option.value === value).label; return ( {options.map((option) => ( ))} ); } ``` ### Input Stack Options The `Select` trigger can be customized similar to `TextInput`. These options are also available for mobile implementations. #### Label and Helper Text When space is tight, this brings the label inside of the Input. Should be used with a `compact` `SelectOption`. ```jsx live function LabelHelperTextSelect() { const [value, setValue] = useState('Option 2'); const options = ['Option 1', 'Option 2', 'Option 3', 'Option 4', 'Option 5', 'Option 6']; return ( } > {options.map((option) => ( ))} ); } ``` ### Compact When space is tight, this brings the label inside of the Input. Should be used with a `compact` `SelectOption`. ```jsx live function CompactSelect() { const [value, setValue] = useState('Option 2'); const options = ['Option 1', 'Option 2', 'Option 3', 'Option 4', 'Option 5', 'Option 6']; return ( {options.map((option) => ( ))} ); } ``` ### Variants Variants can be used to surface positive or negative feedback. ```jsx live function Variant() { const [value, setValue] = useState('Positive'); const options = ['Positive', 'Negative', 'Primary', 'Secondary', 'Foreground']; return ( {options.map((option) => ( ))} ); } ``` ### Label Variants Select supports two label variants: `outside` (default) and `inside`. Note that the `compact` prop, when set to true, will override label variant preference. :::warning When using the `inside` label variant, you should always include a `placeholder` prop. ::: ```jsx live Outside label (default): Inside label: Inside label (with start content): } placeholder="Search and select" > ``` ## Props | Prop | Type | Required | Default | Description | | --- | --- | --- | --- | --- | | `name` | `string` | Yes | `-` | Field name of the multiple choice radio group. | | `options` | `Record` | Yes | `-` | Multiple choice options for the radio group. The object key represents the radio input value and the object value represents the radio option label. | | `controlColor` | `currentColor \| fg \| fgMuted \| fgInverse \| fgPrimary \| fgWarning \| fgPositive \| fgNegative \| bg \| bgAlternate \| bgInverse \| bgOverlay \| bgElevation1 \| bgElevation2 \| bgPrimary \| bgPrimaryWash \| bgSecondary \| bgTertiary \| bgSecondaryWash \| bgNegative \| bgNegativeWash \| bgPositive \| bgPositiveWash \| bgWarning \| bgWarningWash \| bgLine \| bgLineHeavy \| bgLineInverse \| bgLinePrimary \| bgLinePrimarySubtle \| accentSubtleRed \| accentBoldRed \| accentSubtleGreen \| accentBoldGreen \| accentSubtleBlue \| accentBoldBlue \| accentSubtlePurple \| accentBoldPurple \| accentSubtleYellow \| accentBoldYellow \| accentSubtleGray \| accentBoldGray \| transparent` | No | `bgPrimary` | Sets the checked/active color of each control in the group. | | `direction` | `horizontal \| vertical` | No | `vertical` | Direction a group of components should flow. | | `gap` | `0 \| 1 \| 2 \| 0.25 \| 0.5 \| 0.75 \| 1.5 \| 3 \| 4 \| 5 \| 6 \| 7 \| 8 \| 9 \| 10` | No | `-` | Gap to insert between siblings. | | `label` | `null \| string \| number \| false \| true \| ReactElement> \| Iterable \| ReactPortal` | No | `-` | Set a label summary for the group of radios. | | `onChange` | `((value: T) => void)` | No | `-` | Handle change event when pressing on a radio option. | | `ref` | `null \| (instance: HTMLInputElement \| null) => void \| RefObject` | No | `-` | - | | `testID` | `string` | No | `-` | Used to locate this element in unit and end-to-end tests. Under the hood, testID translates to data-testid on Web. On Mobile, testID stays the same - testID | | `value` | `string` | No | `-` | Currently selected value. |