🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

@gilbarbara/react-dropdown

Package Overview
Dependencies
Maintainers
0
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gilbarbara/react-dropdown

Customizable dropdown for React

0.2.2
latest
Source
npm
Version published
Weekly downloads
226
36.14%
Maintainers
0
Weekly downloads
 
Created
Source

@gilbarbara/react-dropdown

npm version CI Maintainability Test Coverage

Flexible dropdown component with search, create, and multi selection. It uses emotion for styling.

Check out the demo.

Highlights

  • 🏖 Easy to use: Just set the options prop.
  • 🛠 Flexible: Personalize the options to fit your needs.
  • 🚀 Customizable: You can use your own components to complete control the UI.
  • 🟦 Typescript: Nicely typed

Installation

npm i @gilbarbara/react-dropdown

Usage

import Dropdown from '@gilbarbara/react-dropdown';

function App() {
  const options = [
    {
      label: "Alister Chilles",
      value: "achilleso",
    },
    {
      label: "Alyosha Keerl",
      value: "akeerl6",
    },
  ];
  
  return <Dropdown options={options} />;
}

API

The only required props is options.

Base props

PropTypeDefaultDescription
autoFocusbooleantrueFocus the input when the menu opens.
(if searchable is true)
classNamestringA custom class name for the Dropdown root.
clearOnClosebooleantrueClear the input when the menu closes.
clearOnSelectbooleantrueClear the input when an item is selected.
closeOnScrollbooleanfalseClose the menu when the user scrolls.
closeOnSelectbooleanfalseClose the menu when an item is selected.
comparatorFn(previousValues: Option[], values: Option[]) => booleanOverrides the internal comparator function.
createbooleanfalseCreate an option from the search string if no results are found.
(Fires the onCreate callback)
directionDirection'ltr'The text direction of the component.
disabledbooleanfalseDisable the Dropdown.
hiddenInputHiddenInputAdd an input with type hidden to the component with the selected value(s).
hideHandlebooleanfalseHide the handle.
keepSelectedInListbooleantrueKeep the selected item(s) in the list.
labelsPartial<Labels>Component labels.
loadingbooleanfalseShow a spinner while loading data.
menuPositionPosition'bottom'The menu position.
multibooleanfalseSelect multiple options.
openbooleanControl the menu visibility.
options (required)Option[]The dropdown options.
placeholderstring'Select...'The placeholder of the input.
searchByOptionKeys'label'The field to search.
searchFn(props: ComponentProps) => Option[]Overrides the internal search function.
searchablebooleantrueSearch the options.
secondaryPlaceholderstringThe placeholder on the search field if a value is selected (if searchable is true).
showClearButtonbooleanfalseShow a button to clear the selection.
showSeparatorbooleanFalseShow a separator between the content and handle.
styleCSSPropertiesSet the style on the component root.
stylesPartial<Styles>The styling of the component. (color, background, border, etc.)
valuesOption[]The selected values.

Callback props

PropTypeDescription
onChange(value: Option[]) => voidValues change callback.
onClearAll() => voidClear all values callback (with custom components).
onClickSelector(isOpen: boolean) => voidClick selector callback.
onClose() => voidClose dropdown callback.
onCreate(search: string, close: () => void) => voidCreate option callback.
onOpen() => voidOpen dropdown callback.
onSelectAll() => voidSelect all values callback (with custom components).

Custom components

PropTypeDescription
clearComponent(props: ComponentProps) => JSX.ElementCustom Clear component.
contentComponent(props: ComponentProps) => JSX.ElementCustom Content component.
handleComponent(props: ComponentProps) => JSX.ElementCustom Handle component.
inputComponent(props: InputComponentProps) => JSX.ElementCustom Input component.
loaderComponent(props: Pick<ComponentProps, 'props'>) => JSX.ElementCustom Loader component.
menuComponent(props: ComponentProps) => JSX.ElementCustom Menu component.
menuItemComponent(props: ItemComponentProps) => JSX.ElementCustom MenuItem component.
noDataComponent(props: ComponentProps) => JSX.ElementCustom NoData component.
optionComponent(props: OptionComponentProps) => JSX.ElementCustom Option component.
separatorComponent(props: ComponentProps) => JSX.ElementCustom Separator component.

*All the types are available here.

Credits

Inspired by react-dropdown-select and react-select.

License

MIT

Keywords

react

FAQs

Package last updated on 14 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts