Dropdown
A dropdown list.
When To Use#
When there are more than a few options to choose from, you can wrap them in a Dropdown
. By hovering or clicking on the trigger, a dropdown menu will appear, which allows you to choose an option and execute the relevant action.
Examples
import { Menu, Dropdown, Icon } from 'antd';
const menu = (
<Menu>
<Menu.Item>
<a target="_blank" rel="noopener noreferrer" href="http://www.alipay.com/">
1st menu item
</a>
</Menu.Item>
<Menu.Item>
<a target="_blank" rel="noopener noreferrer" href="http://www.taobao.com/">
2nd menu item
</a>
</Menu.Item>
<Menu.Item>
<a target="_blank" rel="noopener noreferrer" href="http://www.tmall.com/">
3rd menu item
</a>
</Menu.Item>
</Menu>
);
ReactDOM.render(
<Dropdown overlay={menu}>
<a className="ant-dropdown-link" onClick={e => e.preventDefault()}>
Hover me <Icon type="down" />
</a>
</Dropdown>,
mountNode,
);
import { Menu, Dropdown, Icon } from 'antd';
const menu = (
<Menu>
<Menu.Item key="0">
<a target="_blank" rel="noopener noreferrer" href="http://www.alipay.com/">
1st menu item
</a>
</Menu.Item>
<Menu.Item key="1">
<a target="_blank" rel="noopener noreferrer" href="http://www.taobao.com/">
2nd menu item
</a>
</Menu.Item>
<Menu.Divider />
<Menu.Item key="3" disabled>
3rd menu item(disabled)
</Menu.Item>
</Menu>
);
ReactDOM.render(
<Dropdown overlay={menu}>
<a className="ant-dropdown-link" onClick={e => e.preventDefault()}>
Hover me <Icon type="down" />
</a>
</Dropdown>,
mountNode,
);
import { Menu, Dropdown, Icon, message } from 'antd';
const onClick = ({ key }) => {
message.info(`Click on item ${key}`);
};
const menu = (
<Menu onClick={onClick}>
<Menu.Item key="1">1st menu item</Menu.Item>
<Menu.Item key="2">2nd memu item</Menu.Item>
<Menu.Item key="3">3rd menu item</Menu.Item>
</Menu>
);
ReactDOM.render(
<Dropdown overlay={menu}>
<a className="ant-dropdown-link" onClick={e => e.preventDefault()}>
Hover me, Click menu item <Icon type="down" />
</a>
</Dropdown>,
mountNode,
);
import { Menu, Dropdown, Button } from 'antd';
const menu = (
<Menu>
<Menu.Item>
<a target="_blank" rel="noopener noreferrer" href="http://www.alipay.com/">
1st menu item
</a>
</Menu.Item>
<Menu.Item>
<a target="_blank" rel="noopener noreferrer" href="http://www.taobao.com/">
2nd menu item
</a>
</Menu.Item>
<Menu.Item>
<a target="_blank" rel="noopener noreferrer" href="http://www.tmall.com/">
3rd menu item
</a>
</Menu.Item>
</Menu>
);
ReactDOM.render(
<div>
<Dropdown overlay={menu} placement="bottomLeft">
<Button>bottomLeft</Button>
</Dropdown>
<Dropdown overlay={menu} placement="bottomCenter">
<Button>bottomCenter</Button>
</Dropdown>
<Dropdown overlay={menu} placement="bottomRight">
<Button>bottomRight</Button>
</Dropdown>
<br />
<Dropdown overlay={menu} placement="topLeft">
<Button>topLeft</Button>
</Dropdown>
<Dropdown overlay={menu} placement="topCenter">
<Button>topCenter</Button>
</Dropdown>
<Dropdown overlay={menu} placement="topRight">
<Button>topRight</Button>
</Dropdown>
</div>,
mountNode,
);
#components-dropdown-demo-placement .ant-btn {
margin-right: 8px;
margin-bottom: 8px;
}
import { Menu, Dropdown, Icon } from 'antd';
const menu = (
<Menu>
<Menu.Item key="0">
<a href="http://www.alipay.com/">1st menu item</a>
</Menu.Item>
<Menu.Item key="1">
<a href="http://www.taobao.com/">2nd menu item</a>
</Menu.Item>
<Menu.Divider />
<Menu.Item key="3">3rd menu item</Menu.Item>
</Menu>
);
ReactDOM.render(
<Dropdown overlay={menu} trigger={['click']}>
<a className="ant-dropdown-link" onClick={e => e.preventDefault()}>
Click me <Icon type="down" />
</a>
</Dropdown>,
mountNode,
);
import { Menu, Dropdown, Button, Icon, message } from 'antd';
function handleButtonClick(e) {
message.info('Click on left button.');
console.log('click left button', e);
}
function handleMenuClick(e) {
message.info('Click on menu item.');
console.log('click', e);
}
const menu = (
<Menu onClick={handleMenuClick}>
<Menu.Item key="1">
<Icon type="user" />
1st menu item
</Menu.Item>
<Menu.Item key="2">
<Icon type="user" />
2nd menu item
</Menu.Item>
<Menu.Item key="3">
<Icon type="user" />
3rd item
</Menu.Item>
</Menu>
);
ReactDOM.render(
<div id="components-dropdown-demo-dropdown-button">
<Dropdown.Button onClick={handleButtonClick} overlay={menu}>
Dropdown
</Dropdown.Button>
<Dropdown.Button overlay={menu} icon={<Icon type="user" />}>
Dropdown
</Dropdown.Button>
<Dropdown.Button onClick={handleButtonClick} overlay={menu} disabled>
Dropdown
</Dropdown.Button>
<Dropdown overlay={menu}>
<Button>
Button <Icon type="down" />
</Button>
</Dropdown>
</div>,
mountNode,
);
#components-dropdown-demo-dropdown-button .ant-dropdown-button {
margin: 0 8px 8px 0;
}
import { Menu, Dropdown, Icon } from 'antd';
class OverlayVisible extends React.Component {
state = {
visible: false,
};
handleMenuClick = e => {
if (e.key === '3') {
this.setState({ visible: false });
}
};
handleVisibleChange = flag => {
this.setState({ visible: flag });
};
render() {
const menu = (
<Menu onClick={this.handleMenuClick}>
<Menu.Item key="1">Clicking me will not close the menu.</Menu.Item>
<Menu.Item key="2">Clicking me will not close the menu also.</Menu.Item>
<Menu.Item key="3">Clicking me will close the menu</Menu.Item>
</Menu>
);
return (
<Dropdown
overlay={menu}
onVisibleChange={this.handleVisibleChange}
visible={this.state.visible}
>
<a className="ant-dropdown-link" onClick={e => e.preventDefault()}>
Hover me <Icon type="down" />
</a>
</Dropdown>
);
}
}
ReactDOM.render(<OverlayVisible />, mountNode);
API#
Dropdown#
Property | Description | Type | Default | Version |
---|---|---|---|---|
disabled | Whether the dropdown menu is disabled | boolean | - | |
getPopupContainer | To set the container of the dropdown menu. The default is to create a div element in body , but you can reset it to the scrolling area and make a relative reposition. Example on CodePen. | Function(triggerNode) | () => document.body | |
overlay | The dropdown menu | Menu | () => Menu | - | |
overlayClassName | Class name of the dropdown root element | string | - | 3.11.0 |
overlayStyle | Style of the dropdown root element | object | - | 3.11.0 |
placement | Placement of popup menu: bottomLeft , bottomCenter , bottomRight , topLeft , topCenter or topRight | String | bottomLeft | |
trigger | The trigger mode which executes the dropdown action. Note that hover can't be used on touchscreens. | Array<click |hover |contextMenu > | ['hover'] | |
visible | Whether the dropdown menu is currently visible | boolean | - | |
onVisibleChange | Called when the visible state is changed. | Function(visible) | - |
You should use Menu as overlay
. The menu items and dividers are also available by using Menu.Item
and Menu.Divider
.
Warning: You must set a unique
key
forMenu.Item
.Menu of Dropdown is unselectable by default, you can make it selectable via
<Menu selectable>
.
Dropdown.Button#
Property | Description | Type | Default | Version |
---|---|---|---|---|
disabled | Whether the dropdown menu is disabled | boolean | - | |
icon | Icon (appears on the right) | ReactNode | - | 3.17.0 |
overlay | The dropdown menu | Menu | - | |
placement | Placement of popup menu: bottomLeft bottomCenter bottomRight topLeft topCenter topRight | String | bottomLeft | |
size | Size of the button, the same as Button | string | default | |
trigger | The trigger mode which executes the dropdown action | Array<click |hover |contextMenu > | ['hover'] | |
type | Type of the button, the same as Button | string | default | |
visible | Whether the dropdown menu is currently visible | boolean | - | |
onClick | The same as Button: called when you click the button on the left | Function | - | |
onVisibleChange | Called when the visible state is changed | Function | - |