Skip to main content
Version: Next

Dropdown

The Dropdown component provides a dropdown menu functionality. It allows users to select one or multiple items from a list of options displayed in a dropdown menu. The component is highly customizable with various props that can be passed to modify its appearance and behavior.

Import

import { Dropdown } from '@tra-tech/react-native-kitra';

Usage

import { Dropdown } from '@tra-tech/react-native-kitra';
import { useState } from 'react';
import { View } from 'react-native';

const data = [{ label: 'Item 1', value: 1 }, { label: 'Item 2', value: 2 }, { label: 'Item 3', value: 3 }, { label: 'Item 4', value: 4 }, { label: 'Item 5', value: 5 }];

const App = () => {
const [select, setSelect] = useState();
return (
<View style={{ rowGap: 100 }}>
<View style={{ zIndex: 101, flex: 1 }}>
<Dropdown
multiple
selectall
containerStyle={{ marginTop: 20 }}
buttonTitle="Please Select"
buttonTextStyle={{ color: 'black', marginLeft: 18 }}
rowTextStyle={{ color: '#8973CD' }}
buttonBackgrounColor={{ focusBackground: '#8973CD', defaultBackground: '#F9F8FD' }}
displayLength={4}
rowStyle={{ backgroundColor: '#F9F8FD' }}
buttonStyle={{ width: '100%', height: 51, borderRadius: 50 }}
listContainerStyle={{ backgroundColor: '#F9F8FD' }}
onSelect={x => setSelect(x.label)}
displayedButtonValue={x => x.label}
displayedRowValue={x => x.label}
data={data}
/>
</View>
<View style={{ flex: 1 }}>
<Dropdown
selectall
containerStyle={{ marginTop: 20 }}
buttonTitle="Please Select"
buttonTextStyle={{ color: 'black', marginLeft: 18 }}
rowTextStyle={{ color: '#8973CD' }}
buttonBackgrounColor={{ focusBackground: '#8973CD', defaultBackground: '#F9F8FD' }}
displayLength={4}
rowStyle={{ backgroundColor: '#F9F8FD' }}
buttonStyle={{ width: '100%', height: 51, borderRadius: 50 }}
listContainerStyle={{ backgroundColor: '#F9F8FD' }}
onSelect={x => setSelect(x.value)}
displayedButtonValue={x => x.label}
displayedRowValue={x => x.label}
data={data}
/>
</View>
</View>
);
};

export default App;

Props

Prop nameTypeRequiredDescription
multiplebooleanNoDetermines whether the dropdown should allow multiple selections. Default value: false
disabledbooleanNoDetermines whether the dropdown is disabled. Default value: false.
left(isVisible:boolean)=>React.ReactNodeNoA React node that will be created to the left of the dropdown button and return its visible.
right(isVisible:boolean)=>React.ReactNodeNoA React node that will be created to the right of the dropdown button and return its visible.
data Array<(string | object )> YesAn array of objects or strings to be used as options in the dropdown list.
displayedRowValue(item: string | object) => anyYesA function that takes an item from the data array and returns a value to be displayed in the dropdown list.
displayedButtonValue(item: string | object) => any YesA function that takes an item from the data array and returns a value to be displayed on the dropdown button.
listContainerStyleStyleProp<ViewStyle>NoAn object containing styles to be applied to the dropdown list container.
defaultValueArray<string | object>NoAn array of objects or strings to be pre-selected in the dropdown.
displayLengthnumberNoThe number of items to display in the button.
buttonTitlestringNoThe default text to be displayed on the dropdown button when no options are selected.
rowStyleStyleProp<ViewStyle>NoAn object containing styles to be applied to each item in the dropdown list.
buttonStyleStyleProp<ViewStyle>NoAn object containing styles to be applied to the dropdown button.
buttonTextStyleStyleProp<TextStyle>NoAn object containing styles to be applied to the text inside the dropdown button.
selectallbooleanNoWhether to include a "Select All" option in the dropdown.
onSelect(item: Array<string> | Array<object> | string | object) => voidNoA function to be called whenever an item is selected in the dropdown.
onComplete(item: object | string) => void NoA function to be called whenever submit button pressed.
rowTextStyleStyleProp<TextStyle>NoAn object containing styles to be applied to the text inside each item in the dropdown list.
containerStyleStyleProp<ViewStyle>NoAn object containing styles to be applied to the dropdown container.
buttonBackgrounColor{ focusBackground: string, defaultBackground: string }NoUsed to customize the background color of the dropdown.
iconStyle{ color: string,
container: StyleProp<ViewStyle> }
NoThe color property determines the icon's color, and the container property defines the style of the container that holds the icon.
autoPositionbooleanNoControls whether the dropdown component's dropdown menu is positioned automatically. Default value: true
themeUIThemeNoThe theme to use for the component.
typographyUITypographyNoThe typography to use for the component.