New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-16-dropdown

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-16-dropdown

A zero-dependency, lightweight and fully customizable dropdown (not select) for React.

  • 0.1.0-alpha.3
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

react-16-dropdown

A zero-dependency, lightweight and fully customizable dropdown (not select) for React. You can find examples here

Installation

npm install --save react-16-dropdown

Basic usage

import Dropdown from 'react-16-dropdown';

const options = [{
  label: 'Prestige 🎩',
  value: 'prestige',
}, {
  label: 'Inception 😴',
  value: 'inception',
}];

<Dropdown
  align='left'
  className='custom-classname'
  closeOnEscape={true}
  options={options}
  triggerLabel='Movies 🍿'
  onClick={val => console.log(val)}
/>

Supported props

You can pass the following props to the Dropdown component -

NameDefaultAllowed valuesDescription
alignleftleft, rightDecides the alignment of the menu w.r.t trigger
className''StringAdds the given class to the wrapper element
portalClassName''StringAdds the given class to portal component
options*undefinedArrayAn array of objects
openundefinedBooleanProp to control open/closed state of the menu
triggerLabelOpen menuStringText for the default trigger button
onClick*undefinedFunctionHandler for option click event
disabledfalseBooleanDisable the trigger
closeOnEscapetrueBooleanShould the dropdown menu close on pressing Escape
closeOnClickOutsidetrueBooleanShould the dropdown menu close on clicking outside the menu
closeOnOptionClicktrueBooleanShould the dropdown close when option is clicked
onOpenundefinedFunctionFunction to be called when menu opens
onCloseundefinedFunctionFunction to be called when menu closes
onTriggerClickundefinedFunctionFunction to be called when the trigger element is clicked
menuPortalTargetbodyStringSelector for the portal to be attached as a child to
menuRendererMenuRenderer⁽¹⁾ReactElementComponent to render the menu
triggerRendererTriggerRenderer⁽¹⁾ReactElementComponent to render the trigger
optionRendererOptionRenderer⁽¹⁾ReactElementComponent to render option
menuComponentMenu⁽¹⁾ ⁽²⁾ReactElementComponent to replace the default menu
optionComponentOption⁽¹⁾ ⁽²⁾ReactElementComponent to replace the default option
triggerComponentTrigger⁽¹⁾ ⁽²⁾ReactElementComponent to replace the default trigger

The options prop is an array of objects. Each object can have the following keys -

KeyValueDescription
value*StringUnique identifier for each option
label*<StringReactElement>
classNameStringCustom class name for the option

⁽¹⁾ Default internal component

⁽²⁾ If you replace the component (instead of using renderers), you will have to pass down all the handlers, refs and other props down to your components.

* Required props

Customization

You can customize any part of the dropdown to suit your needs. In most cases, modifying existing classes/adding your own classes should do the trick. For advanced use cases, you can use custom render components. If you want to take over individual components of the dropdown, you can replace the menu, option or trigger default components.

Using renderers -

<Dropdown
  options={colorOptions}
  triggerRenderer={() => <button className='btn btn-dark ml-2'>Option renderer</button>}
  optionRenderer={props => <div className={`option option--${props.value}`}>{props.label}</div>}
  onClick={e => console.log(e)}
/>

Using components -

function CustomButtonComponent(props) {
  return (
    <a
      className='btn btn-outline-info'
      ref={props.triggerRef}
      onClick={props.onClick}
      onKeyDown={props.onKeyDown}
    >
      Custom link component
    </a>
  );
}

<Dropdown
  options={options}
  triggerComponent={CustomButtonComponent}
  onClick={e => console.log(e)}
/>

Controlled Component

You can also use the dropdown as a controlled component if you pass the open prop.

<Dropdown
  open={true}
  options={options}
  onTriggerClick={() => { /* do something */ }}
  onClick={e => console.log(e)}
/>

Keywords

FAQs

Package last updated on 17 Jun 2018

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc