Skip to main content

PickerButton

Dropdown trigger button that displays a selected value and opens a picker.

Basic Usage​

import { PickerButton } from '@multinaire/expo-ui';

<PickerButton
placeholder="Select option"
value={selectedLabel}
onPress={() => setPickerVisible(true)}
/>

Props​

PropTypeDefaultDescription
placeholderstring—Placeholder text shown when the field is empty
valuestring—Current value of the input
titlestring—Field label displayed above the input
requiredbooleanfalseMark the field as required. Displays a visual indicator
allowClearbooleanfalseShow a clear (×) button to reset the value
leadingIconName | ReactElement—Leading icon name or a custom React element rendered at the start of the input
trailingIconName | ReactElement—Trailing icon name or a custom React element rendered at the end of the input
extraReactElement—Extra element rendered at the trailing end of the label row (e.g. a "Forgot password?" link)
errorTextstring—Error message displayed below the input
flexnumber—Flex grow value
marginSpacingProps—Outer margin
testIDstring—Test identifier for UI automation
onPress() => void—Press handler that opens the picker
onClear() => void—Callback invoked when the user clears the current selection

Examples​

Basic Picker​

<PickerButton
title="Country"
placeholder="Select a country"
value={selectedCountry?.name}
onPress={() => setCountryPickerVisible(true)}
/>

With Clear Button​

<PickerButton
title="Category"
placeholder="Select category"
value={category}
allowClear
onPress={() => setCategoryPickerVisible(true)}
onClear={() => setCategory(null)}
/>

With Leading Icon​

<PickerButton
leading="Calendar"
placeholder="Select date"
value={formattedDate}
onPress={() => setDatePickerVisible(true)}
/>

With Error​

<PickerButton
title="Required Field"
required
placeholder="Please select"
value={value}
errorText={!value ? 'This field is required' : undefined}
onPress={openPicker}
/>

With ListPicker​

ListPicker has no visibility of its own — it renders inside a Popup, and the PickerButton is that popup's toggle. Spread the render-prop argument onto the button so pressing it opens the popup.

<Popup
title="Select country"
renderToggleButton={(props) => (
<PickerButton
title="Country"
placeholder="Select country"
trailing="ArrowDown2"
value={country?.name}
{...props}
/>
)}
>
<ListPicker
type="dropdown"
items={countries}
selectedItem={country}
onChange={setCountry}
/>
</Popup>