| name | groww-select |
| description | Select dropdown component for single selection from options. Use when user needs to choose one option from a list of predefined choices. |
Groww Select Component
Import Patterns
import Select from '@groww-tech/ui-toolkit/dist/esm/components/atoms/Select';
import { Select } from '@groww-tech/ui-toolkit';
Key APIs
Props
interface SelectData {
label: string;
value: string | number;
subContent?: React.ReactNode;
}
interface SelectProps {
data: SelectData[];
activeIndex?: number;
onSelect: (index: number, value: string | number) => void;
placeholder?: string;
disabled?: boolean;
showSearch?: boolean;
searchValue?: string;
onSearchChange?: (value: string) => void;
className?: string;
dataTestId?: string;
id?: string;
name?: string;
}
Usage Examples
Basic Select
const options = [
{ label: 'Option 1', value: '1' },
{ label: 'Option 2', value: '2' },
{ label: 'Option 3', value: '3' },
];
<Select
data={options}
activeIndex={selectedIndex}
onSelect={(index, value) => {
setSelectedIndex(index);
setValue(value);
}}
/>
With Placeholder
<Select
data={options}
activeIndex={selectedIndex}
onSelect={handleSelect}
placeholder="Select an option"
/>
With Search
<Select
data={options}
activeIndex={selectedIndex}
onSelect={handleSelect}
showSearch={true}
searchValue={searchQuery}
onSearchChange={setSearchQuery}
/>
Controlled Select
const [selectedIndex, setSelectedIndex] = useState(-1);
<Select
data={options}
activeIndex={selectedIndex}
onSelect={(index, value) => setSelectedIndex(index)}
/>
Anti-Patterns
- Don't forget onSelect handler: Always provide selection callback
- Don't use for large datasets: Consider virtualized select for 100+ items
- Don't forget to handle empty data: Show appropriate empty state
- Don't use -1 as valid selection: Typically means "no selection"
- Don't forget keyboard navigation: Users expect arrow key support
Accessibility
- Keyboard navigation (Arrow keys, Enter, Escape)
- Focus management
- Screen reader announcements for selection
- Proper label association
Keyboard Navigation
- Arrow Up/Down: Navigate options
- Enter: Select current option
- Escape: Close dropdown
- Home/End: Jump to first/last option