Select
Show a menu of items users can select from one of
Features
Comes with styling, yet completely customizable and themeable.
Accepts animations, themes, size props and more.
Accessible, keyboard navigable, full-featured.
Installation
Select is already installed in tamagui
, or you can install it independently:
npm install @tamagui/select
Anatomy
import { Select } from 'tamagui' // or '@tamagui/select'export default () => (<Select defaultValue=""><Select.Trigger><Select.Value placeholder="Search..." /></Select.Trigger><Select.Content><Select.ScrollUpButton /><Select.Viewport><Select.Group><Select.Label /><Select.Item><Select.ItemText /></Select.Item></Select.Group></Select.Viewport><Select.ScrollDownButton /></Select.Content></Select>)
Note that Select only works on Native using the Adapt component to adapt it to a Sheet. See below for docs.
API Reference
Select
Contains every component for the select:
Props
id
string
Optional for usage with Label
size
SizeTokens
Set the size of itself and pass to all inner elements
children
React.ReactNode
Select children API components
value
string
Controlled value
defaultValue
string
Default value
onValueChange
(value: string) => void
Callback on value change
open
boolean
Controlled open value
defaultOpen
boolean
Default open value
onOpenChange
(open: boolean) => void
Callback on open change
dir
Direction
Direction of text display
name
string
For use in forms
native
NativeValue
If passed, will render a native component instead of the custom one. Currently only `web` is supported.
Select.Trigger
Extends ListItem to give sizing, icons, and more.
Select.Value
Extends Paragraph, adding:
Props
placeholder
string
Optional placeholder to show when no value selected
SelectContent
Main container for Select content, used to contain the up/down arrows, no API beyond children.
Select.ScrollUpButton
Inside Content first, displays when you can scroll up, stuck to the top.
Extends YStack.
Select.ScrollDownButton
Inside Content last, displays when you can scroll down, stuck to the bottom.
Extends YStack.
Select.Viewport
Extends ThemeableStack. Contains scrollable content items as children.
Props
disableScroll
boolean
Removes ability to scroll and all style and functionality related to scrolling
unstyled
boolean
Removes all default styles
Make sure to not pass height
prop as that is managed internally because of UX reasons
and having a fixed height will break that behaviour
Select.Group
Extends YStack. Use only when grouping together items, alongside a Label as the first child.
Select.Label
Extends ListItem. Used to label Groups.
Select.Item
Extends ListItem. Used to add selectable values ot the list. Must provide an index as React Native doesn't give any escape hatch for us to configure that automatically.
Props
index (required)
number
Incrementally starting from 0, matching its appearance in the list.
value
string
Provide a value that will be passed on selection.
Select.ItemText
Extends Paragraph. Used inside Item to provide unselectable text that will show above once selected in the parent Select.
Select.Sheet
When used alongside <Adapt />
, Select will render as a sheet when that breakpoint is active.
This is the only way to render a Select on Native for now, as mobile apps tend to show Select very differently from web and Tamagui wants to present the right abstractions for each platform.
See Sheet for more props.
Must use Select.SheetContents
inside the Select.Sheet.Frame
to insert the contents given to Select.Content
import { Select } from 'tamagui' // or '@tamagui/select'export default () => (<Select defaultValue=""><Select.Trigger><Select.Value placeholder="Search..." /></Select.Trigger><Adapt when="sm" platform="touch">{/* or <Select.Sheet> */}<Sheet><Sheet.Frame><SheetContents /></Sheet.Frame><Sheet.Overlay /></Sheet></Adapt><Select.Content><Select.ScrollUpButton /><Select.Viewport><Select.Group><Select.Label /><Select.Item><Select.ItemText /></Select.Item></Select.Group></Select.Viewport><Select.ScrollDownButton /></Select.Content></Select>)
Previous
RadioGroup
Next
Slider