Dropdown

Dropdown provides a list of actions to the user. A brief, introductory couple of sentences about the component. This is a second sentence just so that there’s a second line in this document. Think of this a teaser for the When/How to Use section.

Examples #

Dropdown #

Basic dropdown. Text to explain what’s special about this example. Text to explain what’s special about this example. Text to explain what’s special about this example.

<Dropdown data={data}>
	<Button>Menu</Button>
</Dropdown>

Data-Driven #

Dropdown items are defined by an array of data, with the structure below. Object properties in the items array(s) will be passed on to the MenuItem. Text to explain what’s special about this example. Text to explain what’s special about this example. Text to explain what’s special about this example.

() => {
	const data = [
		{
			items: [
				{
					text: 'Menu item with onClick',
					onClick: event => { console.log(event); }
				},
				{
					text: 'Menu item',
					secondaryText: 'Secondary text'
				}
			]
		},
		{
			title: 'Group Title',
			items: [
				{
					text: 'Icon at start',
					iconStart: <IconCloud />
				},
				{
					text: 'Icon at end',
					iconEnd: <IconCloud />
				},
				{
					divider: true
				},
				{
					text: 'Danger variant',
					variant: 'danger' // 'danger' | 'success' | 'warning'
				},
				{
					text: 'Disabled menu item',
					onClick: event => { console.log(event); },
					disabled: true
				},
				{
					text: 'Custom render',
					avatar: 'http://www.fillmurray.com/102/100',
					href: '/components/menu-item#custom-render', // <-- Details here
					render: CustomRender
				}
			]
		}
	];

	return (
		<Dropdown data={data}>
			<Button>Menu</Button>
		</Dropdown>
	);
}

Wide #

Dropdown can display a wider menu. Text to explain what’s special about this example. Text to explain what’s special about this example. Text to explain what’s special about this example.

<DemoLayout>
	<Dropdown wide data={data}>
		<Button disabled>Menu</Button>
	</Dropdown>
</DemoLayout>

Placement #

The placement prop determines the placement of the Dropdown menu relative to the trigger. Text to explain what’s special about this example. Text to explain what’s special about this example. Text to explain what’s special about this example.

<DemoLayout>
	<Dropdown placement="bottom-start" data={data}>
		<Button size="jumbo" disabled>Menu</Button>
	</Dropdown>
</DemoLayout>

Scrolling container #

Behavior inside of a scrolling container. Text to explain what’s special about this example. Text to explain what’s special about this example. Text to explain what’s special about this example.

<ScrollParent height="430">
	<Dropdown
		data={data}
		isOpen
		placement="bottom-start"
		restoreFocus={false}>
		<Button>Menu</Button>
	</Dropdown>
</ScrollParent>

Disabled #

Disabled Dropdown. Remember to disable the trigger as well. Text to explain what’s special about this example. Text to explain what’s special about this example. Text to explain what’s special about this example.

<Dropdown data={data} disabled>
	<Button disabled>Menu</Button>
</Dropdown>

Controlled #

State can be managed by the application rather than the component. Slightly longer text to explain what’s so special about this particular example.

class App extends Component {
	constructor(props) {
		super(props);

		this.state = {
			isOpen: false
		};

		this.onOpen = this.onOpen.bind(this);
		this.onClose = this.onClose.bind(this);
		this.toggleDropdown = this.toggleDropdown.bind(this);
	}

	onOpen(event) {
		this.setState({ isOpen: true });
	}

	onClose(event) {
		// Prevent extra call to toggleDropdown when clicking the controlling button.
		// Also avoid interactions with other dropdowns.
		const demoLayoutNode = findDOMNode(this.demoLayout);
		if (
			!event.nativeEvent &&
			demoLayoutNode &&
			demoLayoutNode.contains(event.target)
		) {
			event.stopImmediatePropagation();
		}

		this.setState({ isOpen: false });
	}


	toggleDropdown(event) {
		if (this.state.isOpen) {
			this.onClose(event);
		} else {
			this.onOpen(event);
		}
	}

	render() {
		const label = this.state.isOpen ? 'Close Dropdown' : 'Open Dropdown';
		return (
			<DemoLayout ref={node => { this.demoLayout = node }}>
				<Dropdown
					data={data}
					isOpen={this.state.isOpen}
					onOpen={this.onOpen}
					onClose={this.onClose}>
					<Button>{label}</Button>
				</Dropdown>
				<Button onClick={this.toggleDropdown}>{label}</Button>
			</DemoLayout>
		);
	}
}

Dropdown Props #

NameTypeDefaultDescription
childrenMnrlReactNoderequired

Trigger for the Dropdown

dataArrayrequired

Data from which the Menu will be constructed

defaultIsOpenboolean

Open the Dropdown immediately upon initialization

disabledboolean

Disable the Dropdown

isOpenboolean

For use with controlled components, in which the app manages Dropdown state

modifiersObject

Plugins that are used to alter behavior. See PopperJS docs for options.

onClose(event: Object) => void

Called when Dropdown is closed

onOpen(event: Object) => void

Called when Dropdown is opened

placement| 'bottom-end' | 'bottom-start' | 'left-end' | 'left-start' | 'right-end' | 'right-start' | 'top-end' | 'top-start''bottom-start'

Placement of the Dropdown menu

restoreFocusbooleantrue

Focus trigger after selecting an item

wideboolean

Display a wider Dropdown menu

Undocumented properties will be applied to the root element.

Dropdown Theme Variables #

These variables can be used as hooks to override this component’s style at either a global or local level. The theme referenced below is whatever theme is available from props to the instance of this component.

VariableValue
DropdownContent_backgroundColortheme.color_white
DropdownContent_borderColortheme.color_gray_20
DropdownContent_borderRadiustheme.borderRadius_1
DropdownContent_boxShadowtheme.shadow_2
DropdownContent_margin5px
DropdownContent_paddingVerticaltheme.spacing_single
DropdownContent_zIndextheme.zIndex_100

When/How to Use #

An explanation of when to use this component and basics about how to use it. Could also include when not to use this component, and which component should be used instead. More detailed how-to-use info is under Best Practices, below. It might be a couple of short sentences, or it could be a full paragraph or two.

Best Practices #

DO this practice

Some text to explain why you should do this and when.

DON’T do this other practice

Some text to explain why you should not do this.

DO this other practice

Some text to explain why you should do this and when.

DO this third practice

Some text to explain why you should do this and when.

Copyright © 2017 CA
We welcome feedback and contributions on GitHub