Skip to main content
Version: 2.16.0

Dropdown

Single-select dropdown. The user taps the trigger, picks one item from a list, and the list closes.

Minimal example

import { useState } from 'react';
import { Dropdown } from '@carlos3g/element-dropdown';

const data = [
{ label: 'Apple', value: 'apple' },
{ label: 'Banana', value: 'banana' },
];

export function FruitPicker() {
const [value, setValue] = useState<string | null>(null);
return (
<Dropdown
data={data}
labelField="label"
valueField="value"
placeholder="Pick a fruit"
value={value}
onChange={(item) => setValue(item.value)}
/>
);
}

Props

Required

PropTypeDescription
dataT[]Flat array of items. Pass sections instead for grouped rendering.
labelFieldkeyof TField on each item to use as the visible label.
valueFieldkeyof TField on each item that identifies it uniquely.
onChange(item: T) => voidFires with the selected item when the user picks from the list.

Sections (optional — alternative to data)

PropTypeDescription
sections{ title: string; data: T[] }[]Groups of items rendered under section headers. When provided, data is ignored. See Sectioned lists.
renderSectionHeader(section) => ReactElement | nullFully custom header renderer.
sectionHeaderStyleViewStyleStyle for the default header container.
sectionHeaderTextStyleTextStyleStyle for the default header <Text>.

Value and display

PropTypeDefaultDescription
valueT | string | nullundefinedCurrently selected value. Can be the full item or just the valueField value.
placeholderstring'Select item'Shown when no value is selected.
placeholderStyleTextStyleStyle for the placeholder text.
selectedTextStyleTextStyleStyle for the label when an item is selected.
selectedTextPropsTextProps{}Extra props spread onto the selected-label <Text> (e.g. numberOfLines).

Container and layout

PropTypeDefaultDescription
styleViewStyleStyle for the outer wrapper.
containerStyleViewStyleStyle for the floating list container.
backgroundColorstringColor of the scrim behind the modal in full-screen modes.
maxHeightnumber340Max height of the list.
minHeightnumber0Min height of the list.
mode'default' | 'modal' | 'auto''default''modal' centers the list on screen; 'auto' measures trigger position.
dropdownPosition'auto' | 'top' | 'bottom''auto'Force the list to open above or below the trigger.
invertedbooleantrueReverses scroll direction when positioned above the trigger.
isInsideModalbooleanfalseSet to true when the Dropdown is rendered inside a React Native <Modal> so the status-bar offset isn't double-counted. See Nest inside a Modal.

Items

PropTypeDefaultDescription
itemContainerStyleViewStyleStyle merged on top of the built-in row style. Use this to change padding.
itemTextStyleTextStyleStyle for the default item label text.
activeItemTextStyleTextStyleExtra text style applied only to the currently-selected row.
activeColorstring'#F6F7F8'Background color of the currently selected row in the list.
renderItem(item: T, selected?: boolean) => ReactElementFully custom row renderer. Overrides the default label.
disabledFieldkeyof TWhen set, items whose value at this field is truthy are non-interactive.
hideSelectedFromListbooleanfalseWhen true, the currently selected item is removed from the rendered list.
PropTypeDefaultDescription
searchbooleanfalseShow the search input above the list.
searchFieldkeyof T | (keyof T)[]labelFieldWhich field(s) to match against. Pass an array to search several at once. See Custom search field.
searchQuery(keyword: string, labelValue: string) => booleanFully custom matcher. See Custom matcher.
searchKeyboardTypeKeyboardTypeOptionskeyboardType for the search input (e.g. 'numeric', 'email-address').
searchInputPropsTextInputPropsExtra props spread onto the underlying search <TextInput> (selectionColor, returnKeyType, autoCapitalize, etc.). See Search input passthrough.
persistSearchbooleanfalseKeep the search text across opens / selections instead of clearing it.
searchDebouncenumber0Debounce the filter pass by this many ms. The text input stays responsive; only the filter is throttled. Useful for lists in the thousands.
inputSearchStyleViewStyleStyle for the search input.
searchPlaceholderstringPlaceholder text for the search input.
searchPlaceholderTextColorstring'gray'Placeholder color for the search input.
renderInputSearch(onSearch: (text: string) => void) => ReactElementFully custom search input.
onChangeText(text: string) => voidFires whenever the search text changes (including when the dropdown closes).

Icons & trigger

PropTypeDefaultDescription
iconStyleImageStyleStyle for the default right-side chevron.
iconColorstring'gray'Tint for the default right-side chevron.
renderLeftIcon(visible?: boolean) => ReactElement | nullCustom left icon; receives whether the list is open.
renderRightIcon(visible?: boolean) => ReactElement | nullCustom right icon; receives whether the list is open. See Icons per state.
renderSelectedItem(visible?: boolean) => ReactElement | nullReplace the entire trigger body (left icon, label, right icon) with a custom layout. See Custom trigger.
renderModalHeader(close: () => void) => ReactElement | nullRenders a header view above the list inside the modal. Receives a close() to dismiss. See Modal header.

Behavior

PropTypeDefaultDescription
disablebooleanfalseWhen true, tapping the trigger does nothing.
autoScrollbooleantrueOn open, scroll the list to the currently-selected row. Ignored while the list is filtered.
keyboardAvoidingbooleantrueLift the list when the search input raises the keyboard.
confirmSelectItembooleanfalseWhen true, selecting an item calls onConfirmSelectItem instead of onChange.
onConfirmSelectItem(item: T) => voidCalled when confirmSelectItem is true.
closeModalWhenSelectedItembooleantrueWhen false, the list stays open after a selection.
showsVerticalScrollIndicatorbooleantrueShows the vertical scroll indicator on the list.
flatListPropsOmit<FlatListProps<T>, 'renderItem' | 'data'>Passthrough to the underlying FlatList.
onEndReached() => voidFires when the list scrolls within onEndReachedThreshold of the bottom. See Pagination.
onEndReachedThresholdnumber0.5Distance from the end (in viewport units) at which onEndReached fires.
excludeItemsT[][]Items to hide from the rendered list.
excludeSearchItemsT[][]Items that show in the list but are excluded from search matches.

Callbacks

PropTypeDescription
onFocus() => voidFires when the list opens.
onBlur() => voidFires when the list closes.

Text rendering

PropTypeDefaultDescription
fontFamilystringApplied to trigger label, item labels, and the search input.
allowFontScalingbooleanRN defaultPropagated to every Text and TextInput the component renders.

Accessibility

PropTypeDescription
accessibilityLabelstringLabel for the trigger. Propagated as {label} input to the search field and {label} flatlist to the list.
accessibilityHintstringHint for the trigger, announced after the label and role.
itemAccessibilityLabelFieldstringField on each item to use for per-item accessibilityLabel. Defaults to labelField.
testIDstringtestID for the trigger. Propagated as {testID} input / {testID} flatlist.
itemTestIDFieldstringField on each item to use as its testID. Defaults to labelField.
hitSlopInsets | numberExpand the trigger's tap target.

Triggers expose accessibilityRole="combobox" and accessibilityState.expanded / .disabled. Items expose accessibilityRole="button" plus accessibilityState.selected and .disabled. The open modal is scoped with accessibilityViewIsModal, and the OS-level "Reduce Motion" preference disables the modal animation automatically. See Accessibility.

Imperative ref

import { useRef } from 'react';
import { Dropdown } from '@carlos3g/element-dropdown';
import type { IDropdownRef } from '@carlos3g/element-dropdown';

const ref = useRef<IDropdownRef>(null);

<Dropdown ref={ref} {/* … */} />
<Button title="Open" onPress={() => ref.current?.open()} />
<Button title="Close" onPress={() => ref.current?.close()} />

See Open and close programmatically.