/* eslint react/no-multi-comp: 0, react/prop-types: 0 */ import React from 'react'; import { Link } from 'react-router'; import { PrismCode } from 'react-prism'; import Helmet from 'react-helmet'; import { Dropdown, DropdownToggle, DropdownItem, DropdownMenu } from 'reactstrap'; import DropdownExample from '../examples/Dropdown'; import DropdownSizingExample from '../examples/DropdownSizing'; import CustomDropdownExample from '../examples/CustomDropdown'; import DropdownUncontrolledExample from '../examples/DropdownUncontrolled'; const DropdownExampleSource = require('!!raw!../examples/Dropdown'); const CustomDropdownExampleSource = require('!!raw!../examples/CustomDropdown'); const DropdownUncontrolledExampleSource = require('!!raw!../examples/DropdownUncontrolled'); export default class DropdownPage extends React.Component { constructor(props) { super(props); this.toggleExample2 = this.toggle.bind(this); this.state = { example2: false }; } toggle() { this.setState({ example2: !this.state.example2 }); } render() { return (
The Dropdown component is used to pass the isOpen & toggle props via context to the following components: DropdownToggle, DropdownMenu. The DropdownToggle uses the Button component internally, meaning it also accepts all the props the Button component accepts.
{DropdownExampleSource}
{`Dropdown.propTypes = {
disabled: PropTypes.bool,
dropup: PropTypes.bool,
group: PropTypes.bool,
isOpen: PropTypes.bool,
tag: PropTypes.string, // default: 'div'
toggle: PropTypes.func
};
DropdownToggle.propTypes = {
caret: PropTypes.bool,
color: PropTypes.string,
className: PropTypes.string,
disabled: PropTypes.bool,
onClick: PropTypes.func,
'data-toggle': PropTypes.string,
'aria-haspopup': PropTypes.bool,
// For DropdownToggle usage inside a Nav
nav: PropTypes.bool,
// Defaults to Button component
tag: PropTypes.any
};
DropdownMenu.propTypes = {
tag: PropTypes.string,
children: PropTypes.node.isRequired,
right: PropTypes.bool,
flip: PropTypes.bool, // default: true,
className: PropTypes.string,
cssModule: PropTypes.object,
};`}
To align the DropdownMenu to the right, add a right prop to Dropdown.
{`
This dropdown's menu is right-aligned
Header
Action
Another Action
Another Action
`}
{'Header '}
{' '}
{'Action '}
{'Action '}
{`
Dropdown
...
Dropdown
...
Dropdown
...
`}
{CustomDropdownExampleSource}
For the most basic use-case an uncontrolled component can provide the functionality wanted without the need to manage/control the state of the component. UncontrolledDropdown does not require isOpen nor toggle props to work. For the other Dropdown flavors, ButtonDropdown, NavDropdown, uncontrolled components have been made as well; UncontrolledButtonDropdown, UncontrolledNavDropdown respectfully.
{DropdownUncontrolledExampleSource}