2.3.1 • Published 11 months ago

react-native-paper-dropdown v2.3.1

Weekly downloads
295
License
MIT
Repository
github
Last release
11 months ago

react-native-paper-dropdown

npm version npm downloads npm npm

Material Design Dropdown Component using React Native Paper, now also with multiselect

Dependencies

react-native-paper

Installation

yarn add react-native-paper-dropdown

or

npm i react-native-paper-dropdown

Demo

Basic Example

Single Select

import React, { useState } from 'react';
import { View } from 'react-native';
import { Dropdown } from 'react-native-paper-dropdown';
import { Provider as PaperProvider } from 'react-native-paper';

const OPTIONS = [
  { label: 'Male', value: 'male' },
  { label: 'Female', value: 'female' },
  { label: 'Other', value: 'other' },
];

export default function App() {
  const [gender, setGender] = useState<string>();

  return (
    <PaperProvider>
      <View style={{ margin: 16 }}>
        <Dropdown
          label="Gender"
          placeholder="Select Gender"
          options={OPTIONS}
          value={gender}
          onSelect={setGender}
        />
      </View>
    </PaperProvider>
  );
}

Multi Select

import React, { useState } from 'react';
import { View } from 'react-native';
import { MultiSelectDropdown } from 'react-native-paper-dropdown';
import { Provider as PaperProvider } from 'react-native-paper';

const MULTI_SELECT_OPTIONS = [
  { label: 'White', value: 'white' },
  { label: 'Red', value: 'red' },
  { label: 'Blue', value: 'blue' },
  { label: 'Green', value: 'green' },
  { label: 'Orange', value: 'orange' },
];

export default function App() {
  const [colors, setColors] = useState<string[]>([]);

  return (
    <PaperProvider>
      <View style={{ margin: 16 }}>
        <MultiSelectDropdown
          label="Colors"
          placeholder="Select Colors"
          options={MULTI_SELECT_OPTIONS}
          value={colors}
          onSelect={setColors}
        />
      </View>
    </PaperProvider>
  );
}

Props

DropdownProps

PropTypeDescription
testIDstringTest ID for the dropdown component.
menuTestIDstringTest ID for the dropdown menu.
valuestringThe currently selected value.
onSelect(value: string) => voidCallback function to handle value selection.
optionsOption[]Array of options for the dropdown.
menuUpIconJSX.ElementCustom icon for menu up state.
menuDownIconJSX.ElementCustom icon for menu down state.
maxMenuHeightnumberMaximum height of the dropdown menu.
menuContentStyleViewStyleStyle for the dropdown menu content.
CustomDropdownItem(props: DropdownItemProps) => JSX.ElementCustom component for dropdown item.
CustomDropdownInput(props: DropdownInputProps) => JSX.ElementCustom component for dropdown input.
CustomMenuHeader(props: DropdownHeaderProps) => JSX.ElementCustom component for the dropdown menu header.
TouchableForwardRefExoticComponent<PressableProps & RefAttributes<View>>Custom touchable component for the dropdown.
placeholderstringPlaceholder text for the dropdown input.
labelTextInputLabelPropLabel for the dropdown input.
mode'flat' \| 'outlined'Mode for the dropdown input.
disabledbooleanWhether the dropdown is disabled.
errorbooleanWhether the dropdown has an error.
hideMenuHeaderbooleanHide menu header component (default: false).
statusBarHeightnumberAdditional top margin for the status bar on Android.

MultiSelectDropdownProps

PropTypeDescription
testIDstringTest ID for the dropdown component.
menuTestIDstringTest ID for the dropdown menu.
valuestring[]The currently selected values.
onSelect(value: string[]) => voidCallback function to handle value selection.
optionsOption[]Array of options for the dropdown.
menuUpIconJSX.ElementCustom icon for menu up state.
menuDownIconJSX.ElementCustom icon for menu down state.
TouchableForwardRefExoticComponent<PressableProps & RefAttributes<View>>Custom touchable component for the dropdown.
maxMenuHeightnumberMaximum height of the dropdown menu.
menuContentStyleViewStyleStyle for the dropdown menu content.
CustomMultiSelectDropdownItem(props: MultiSelectDropdownItemProps) => JSX.ElementCustom component for multi-select dropdown item.
CustomMultiSelectDropdownInput(props: DropdownInputProps) => JSX.ElementCustom component for multi-select dropdown input.
CustomMenuHeader(props: DropdownHeaderProps) => JSX.ElementCustom component for the dropdown menu header.
placeholderstringPlaceholder text for the dropdown input.
labelTextInputLabelPropLabel for the dropdown input.
mode'flat' \| 'outlined'Mode for the dropdown input.
disabledbooleanWhether the dropdown is disabled.
errorbooleanWhether the dropdown has an error.
hideMenuHeaderbooleanHide menu header component (default: false).
statusBarHeightnumberAdditional top margin for the status bar on Android.

Methods

MethodReturnDescription
focus()voidOpen the dropdown manually.
blur()voidClose the dropdown manually.

Latest Documentation

v1 Documentation

License

MIT

2.3.0

11 months ago

2.0.3

11 months ago

2.2.0

11 months ago

2.0.2

11 months ago

2.0.5

11 months ago

2.3.1

11 months ago

2.0.4

11 months ago

2.0.7

11 months ago

2.0.6

11 months ago

2.0.8

11 months ago

2.1.0

11 months ago

2.0.1

11 months ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago