• Stars
    star
    667
  • Rank 67,625 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 10 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🔽 A dead simple dropdown component for React

react-dropdown

NPM version Downloads

Simple Dropdown component for React, inspired by react-select

Why

  • The default HTML select element is hard to style
  • And sometime we also want grouped menus
  • if you want more advanced select, check react-select

Installation

// with npm
$ npm install react-dropdown  --save

// with yarn
$ yarn add react-dropdown

Changelog

If you want to support React version under v0.13, use [email protected]

Usage

This is the basic usage of react-dropdown

import Dropdown from 'react-dropdown';
import 'react-dropdown/style.css';

const options = [
  'one', 'two', 'three'
];
const defaultOption = options[0];
<Dropdown options={options} onChange={this._onSelect} value={defaultOption} placeholder="Select an option" />;

Options

Flat Array options

const options = [
  'one', 'two', 'three'
];

Object Array options

const options = [
  { value: 'one', label: 'One' },
  { value: 'two', label: 'Two', className: 'myOptionClassName' },
  {
   type: 'group', name: 'group1', items: [
     { value: 'three', label: 'Three', className: 'myOptionClassName' },
     { value: 'four', label: 'Four' }
   ]
  },
  {
   type: 'group', name: 'group2', items: [
     { value: 'five', label: 'Five' },
     { value: 'six', label: 'Six' }
   ]
  }
];

When using Object options you can add to each option a className string to further customize the dropdown, e.g. adding icons to options

Disabling the Dropdown

Just pass a disabled boolean value to the Dropdown to disable it. This will also give you a .Dropdown-disabled class on the element, so you can style it yourself.

<Dropdown disabled onChange={this._onSelect} value={defaultOption} placeholder="Select an option" />;

Customizing the dropdown

className

The className prop is passed down to the wrapper div, which also has the Dropdown-root class.

<Dropdown className='myClassName' />;

controlClassName

The controlClassName prop is passed down to the control div, which also has the Dropdown-control class.

<Dropdown controlClassName='myControlClassName' />;

placeholderClassName

The placeholderClassName prop is passed down to the placeholder div, which also has the Dropdown-placeholder class.

<Dropdown placeholderClassName='myPlaceholderClassName' />;

menuClassName

The menuClassName prop is passed down to the menu div (the one that opens and closes and holds the options), which also has the Dropdown-menu class.

<Dropdown menuClassName='myMenuClassName' />;

arrowClassName

The arrowClassName prop is passed down to the arrow span , which also has the Dropdown-arrow class.

<Dropdown arrowClassName='myArrowClassName' />;

arrowClosed, arrowOpen

The arrowClosed & arrowOpen props enable passing in custom elements for the open/closed state arrows.

<Dropdown
  arrowClosed={<span className="arrow-closed" />}
  arrowOpen={<span className="arrow-open" />}
/>;

Check more examples in the example folder.

Run example

$ npm start

License

MIT | Build for CSViz project @Wiredcraft

More Repositories

1

electron-pdf

📄 A command line tool to generate PDF from URL, HTML or Markdown files.
JavaScript
1,235
star
2

soundredux-native

📱 In an effort to try react-native along with redux
JavaScript
781
star
3

react-chartist

⚛ React component for Chartist.js
JavaScript
528
star
4

book-gpt

Drop a book, start asking question.
TypeScript
432
star
5

diagram-gpt

Draw flowchart, sequence diagram, class diagram, user journey, gantt, C4C diagram with nature language.
TypeScript
264
star
6

ionic-rating

An angularjs directive that take care of visualising a star rating bar
CoffeeScript
144
star
7

react-testing-recipes

📝 A list of recipes to testing your React code
JavaScript
78
star
8

intro-to-react

react入门教程
JavaScript
53
star
9

gulp-html2js

Gulp plugin for converting AngularJS templates to JavaScript
JavaScript
38
star
10

ng-textcomplete

An angularjs directive for github-like autocomplete
JavaScript
38
star
11

gifme

A tool to make a gif in the browser for sharing
JavaScript
38
star
12

music163-cli

mucis163 client
JavaScript
37
star
13

jingfm-cli

start playing music from your awesome command line with jingfm-cli
JavaScript
33
star
14

node-auth-weibo

A complete oauth flow example for Sina weibo
JavaScript
30
star
15

shenjs

The shenjs iOS app build with react-native
JavaScript
29
star
16

node-registration

Simple and robust user registraion process with expressjs + mongoose + nodemailer + more...
JavaScript
24
star
17

stream-handbook-cn

A translation for stream handbook from @substack
24
star
18

babel-jsxgettext

A tool like jsxgettext, but works for es6 + jsx that babel support
JavaScript
22
star
19

slack-pokemon-emoji

A tool to upload all the pokemon to slack emoji.
JavaScript
21
star
20

swift-github-demo

swift-github-demo
Swift
21
star
21

geo-cn

China GeoJSON data
19
star
22

jsconf-china-2016-talk

jsconf-china-2016-talk
JavaScript
18
star
23

webpack-bourbon-test

A repo to test use webpack sass-loader with node-bourbon
JavaScript
17
star
24

docker-tape-run

A demo to setup a tape-run environment on linux with Docker
JavaScript
16
star
25

react-data-visualization

A repo to demonstration using react to do data-visualization
JavaScript
15
star
26

electron-video-stream

Use electron to capture video and stream it to the Internet
JavaScript
13
star
27

bkboard

A Buildkite build report dashboard in terminal and anywhere else.
JavaScript
12
star
28

music163

nodejs client for music163
JavaScript
9
star
29

gify-app

Convert videos to gifs as an OS X, Linux and Windows app
JavaScript
6
star
30

react-yaml-editor

A yaml editor with reactjs
JavaScript
6
star
31

bel-todomvc

A todomvc implemented in Bel
JavaScript
6
star
32

isomorphic-github

An example to test isomorphic application with react + flux + react-router + dispatcher + express
JavaScript
5
star
33

secured-static-land

🎉 Secured your static website with different oauth provider with ease.
HTML
5
star
34

react-send-action

A React binding for send-action
JavaScript
5
star
35

fraserxu.dev

My new personal sites
JavaScript
4
star
36

ionic-infobar

A ionic style angularjs directive to display a info bar in the page header
CSS
4
star
37

element-markdown

A yo-yo component for rendering Markdown with marked
JavaScript
4
star
38

hotdog

Learning tfjs examples
TypeScript
4
star
39

data-canvas

An app to display the data for the data-canvas project
JavaScript
4
star
40

videocat

webrtc video sharing electron app for mac os (Alpha)
CSS
4
star
41

china-population

A China population data visualization project
JavaScript
3
star
42

bel-video-element

A simple video element with bel
JavaScript
3
star
43

next-graphql-github-demo

next-graphql-github-demo
JavaScript
3
star
44

element-boilerplate

A boilerplate to create bel or yo-yo element component
JavaScript
3
star
45

react-barchart-envelope

React component for rendering simple barchart-envelope
JavaScript
3
star
46

aws.fraserxu.dev

aws.fraserxu.dev
TypeScript
3
star
47

is-color-bright

is-color-bright
JavaScript
3
star
48

file-converter

A client-side app that lets you convert between documents written in various markup languages.
JavaScript
3
star
49

array-duplicate

Find duplicate item from two array
JavaScript
3
star
50

taco_dev

🌮 A Rust command line tool that setup a local domain environment for development using nginx and dnsmasq
Rust
2
star
51

signalhub

A signalhub server hosted on heroku
JavaScript
2
star
52

buildkite-node-docker

A buildkite agent to run multiple version nodejs test
2
star
53

videos

https://videos.fraserxu.me
CSS
2
star
54

EDMGenerator

Simple EDM Generator
JavaScript
2
star
55

spy-react-component-lifecycle

spy-react-component-lifecycle
JavaScript
2
star
56

vite-playground

A vite based development playground
JavaScript
2
star
57

element-wrapper

A simple and safe way to set innerHTML for yo-yo or bel component
JavaScript
2
star
58

budget-hack

Budget Hack
JavaScript
2
star
59

go-music163

go client for music163
2
star
60

angular-backoff

exponential backoff for angularjs
CoffeeScript
2
star
61

react-weibo

Weibo client with react
JavaScript
2
star
62

buildkite-node

A buildkite nodejs sdk(WIP)
JavaScript
2
star
63

intro-to-graphql

A intro to graphql
JavaScript
2
star
64

usib

url-screenshot-imgur-browser
JavaScript
2
star
65

slack-translate

A simple node server use Slack slash command to do translation
JavaScript
2
star
66

aws-glossary-slack-bot

Send a message to your slack channel daily of one service definition from AWS
JavaScript
2
star
67

myanmar-numeral

A simple module to convert Arabic numerals to Myanmar numerals
JavaScript
2
star
68

github-voter

github-voter
Vue
1
star
69

resume

personal resume
HTML
1
star
70

campjs

JavaScript
1
star
71

aframe-ar-experiment

aframe-ar-experiment
1
star
72

gams

gams
JavaScript
1
star
73

fraserxu.github.io

Jekyll based blog
CSS
1
star
74

gatekeeper

Enables client-side applications to dance OAuth with GitHub.
Elixir
1
star
75

elm-counter

elm-counter
JavaScript
1
star
76

xnpm-client

The client code to play with the data generated by xnpm
JavaScript
1
star
77

isomorphic-webpack-dynamic-import-demo

isomorphic-webpack-dynamic-import-demo
JavaScript
1
star
78

ionic-resetfield

Angularjs ionic directive to enable reset-field on your form element
CoffeeScript
1
star
79

secured-static-land-next

Demo using secured-static-land with next.js
JavaScript
1
star
80

hands-on-react

Hands on react
JavaScript
1
star
81

es6-demo

Demo repo for the ES6 in today's project meetup
JavaScript
1
star
82

netlify.fraserxu.dev

netlify.fraserxu.dev
HTML
1
star
83

til

keep track of TIL
1
star
84

node-til

til from command line
JavaScript
1
star
85

d3-map

A repo to save my progress
1
star