Select
A customizable select/dropdown component with multiple style variants for choosing from a list of options.
Select
The Select component provides a user-friendly way to select an option from a list of choices. It supports multiple style variants with platform-native ActionSheet integration.
Import
Props
Prop | Type | Default | Description |
---|---|---|---|
label | string | — | Text label for the select field |
placeholder | string | '' | Placeholder text when no option is selected |
options | Array<{ label: string, value: string | number }> | Required | Array of options to select from |
value | string | number | — | Currently selected value |
onChange | (value: string | number) => void | Required | Function called when selection changes |
variant | 'animated' | 'classic' | 'underlined' | 'animated' | Style variant of the select |
error | string | — | Error message to display below the select |
className | string | '' | Additional Tailwind classes for the container |
style | ViewStyle | — | React Native style object for the container |
Variants
Select supports three style variants to match your form design:
Animated (Default)
Classic
Underlined
Usage Examples
Basic Select with Options
Select with Error
Custom Styled Select
Form Integration Example
Filterable Options Example
Best Practices
- Use clear, concise labels that describe what the user is selecting
- Choose the appropriate variant for your form design:
animated
: For forms where you want to save space while maintaining clarityclassic
: For traditional forms with simple, predictable behaviorunderlined
: For a modern, minimal aesthetic or when you want to reduce visual noise
- Provide meaningful placeholder text when no option is selected
- Include descriptive error messages when validation fails
- Use the same variant consistently across related form components
Implementation Details
The Select component uses React Native's TouchableOpacity
for the selection trigger and ActionSheet
for displaying the options on iOS. On Android, it uses a custom modal with a similar appearance.
The component features a floating label implementation using Animated
, which transitions based on focus state and selection state. The label moves from inside the input (as a placeholder) to above the input when an option is selected.
When the user taps on the component, an action sheet or modal appears showing all available options. Upon selection, the chosen option's label is displayed in the field.
The component uses the useThemeColors
hook to apply appropriate color schemes for both light and dark modes.
Notes
- The component automatically adapts to the platform (iOS or Android)
- The floating label animation occurs when the select is focused or has a selected option
- The select border color changes based on focus state and error state
- The component integrates with form validation patterns similar to the Input component
- For extremely long lists of options, consider implementing a searchable select with filtering capability