2016-07-04 10:48:21 +08:00
---
category: Components
2022-11-09 12:28:04 +08:00
group: Navigation
2016-09-21 11:28:38 +08:00
title: Dropdown
2024-03-22 14:22:42 +08:00
description: A dropdown list.
2024-01-29 14:50:36 +08:00
cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*gTBySYX11WcAAAAAAAAAAAAADrJ8AQ/original
coverDark: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*k619RJ_7bKEAAAAAAAAAAAAADrJ8AQ/original
2022-11-09 12:28:04 +08:00
demo:
cols: 2
2016-07-04 10:48:21 +08:00
---
## When To Use
2019-10-28 09:09:22 +08:00
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.
2016-07-04 10:48:21 +08:00
2022-11-09 12:28:04 +08:00
## Examples
2022-11-17 17:31:26 +08:00
<!-- prettier - ignore -->
2022-11-09 12:28:04 +08:00
< code src = "./demo/basic.tsx" > Basic< / code >
2024-09-03 07:15:18 +08:00
< code src = "./demo/extra.tsx" version = "5.21.0" > Extra node< / code >
2022-11-09 12:28:04 +08:00
< code src = "./demo/placement.tsx" > Placement< / code >
< code src = "./demo/arrow.tsx" > Arrow< / code >
< code src = "./demo/item.tsx" > Other elements< / code >
< code src = "./demo/arrow-center.tsx" > Arrow pointing at the center< / code >
< code src = "./demo/trigger.tsx" > Trigger mode< / code >
< code src = "./demo/event.tsx" > Click event< / code >
< code src = "./demo/dropdown-button.tsx" > Button with dropdown menu< / code >
< code src = "./demo/custom-dropdown.tsx" > Custom dropdown< / code >
< code src = "./demo/sub-menu.tsx" > Cascading menu< / code >
2024-01-10 11:57:38 +08:00
< code src = "./demo/sub-menu-debug.tsx" debug > Cascading menu< / code >
2022-11-09 12:28:04 +08:00
< code src = "./demo/overlay-open.tsx" > The way of hiding menu.< / code >
< code src = "./demo/context-menu.tsx" > Context Menu< / code >
< code src = "./demo/loading.tsx" > Loading< / code >
< code src = "./demo/selectable.tsx" > Selectable Menu< / code >
< code src = "./demo/menu-full.tsx" debug > Menu full styles< / code >
< code src = "./demo/render-panel.tsx" debug > \_InternalPanelDoNotUseOrYouWillBeFired</ code >
2023-05-22 13:37:41 +08:00
< code src = "./demo/icon-debug.tsx" debug > Icon debug< / code >
2022-11-09 12:28:04 +08:00
2016-07-04 10:48:21 +08:00
## API
2023-08-08 18:27:48 +08:00
Common props ref: [Common props](/docs/react/common-props)
2016-07-04 10:48:21 +08:00
### Dropdown
2022-11-17 17:31:26 +08:00
| Property | Description | Type | Default | Version |
2023-11-03 18:59:59 +08:00
| --- | --- | --- | --- | --- |
2022-11-17 17:31:26 +08:00
| arrow | Whether the dropdown arrow should be visible | boolean \| { pointAtCenter: boolean } | false | |
2022-12-22 17:56:02 +08:00
| autoAdjustOverflow | Whether to adjust dropdown placement automatically when dropdown is off screen | boolean | true | 5.2.0 |
2022-11-17 17:31:26 +08:00
| autoFocus | Focus element in `overlay` when opened | boolean | false | 4.21.0 |
| disabled | Whether the dropdown menu is disabled | boolean | - | |
| destroyPopupOnHide | Whether destroy dropdown when hidden | boolean | false | |
| dropdownRender | Customize dropdown content | (menus: ReactNode) => ReactNode | - | 4.24.0 |
| 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 ](https://codepen.io/afc163/pen/zEjNOy?editors=0010 ) | (triggerNode: HTMLElement) => HTMLElement | () => document.body | |
2022-12-22 14:12:26 +08:00
| menu | The menu props | [MenuProps ](/components/menu/#api ) | - | 4.24.0 |
2022-11-17 17:31:26 +08:00
| overlayClassName | The class name of the dropdown root element | string | - | |
| overlayStyle | The style of the dropdown root element | CSSProperties | - | |
| placement | Placement of popup menu: `bottom` `bottomLeft` `bottomRight` `top` `topLeft` `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` ] | |
| open | Whether the dropdown menu is currently open. Use `visible` under 4.23.0 ([why?](/docs/react/faq#why-open)) | boolean | - | 4.23.0 |
2023-11-03 18:59:59 +08:00
| onOpenChange | Called when the open state is changed. Not trigger when hidden by click item. Use `onVisibleChange` under 4.23.0 ([why?](/docs/react/faq#why-open)) | (open: boolean, info: { source: 'trigger' \| 'menu' }) => void | - | `info.source` : 5.11.0 |
2016-07-04 10:48:21 +08:00
2016-09-15 01:21:48 +08:00
### Dropdown.Button
2016-07-04 10:48:21 +08:00
2022-10-23 00:33:45 +08:00
Same props from Dropdown. And includes additional props:
2022-11-17 17:31:26 +08:00
| Property | Description | Type | Default | Version |
| --- | --- | --- | --- | --- |
| buttonsRender | Custom buttons inside Dropdown.Button | (buttons: ReactNode\[]) => ReactNode\[] | - | |
| loading | Set the loading status of button | boolean \| { delay: number } | false | |
| danger | Set the danger status of button | boolean | - | 4.23.0 |
| icon | Icon (appears on the right) | ReactNode | - | |
2022-12-22 14:12:26 +08:00
| size | Size of the button, the same as [Button ](/components/button/#api ) | string | `default` | |
| type | Type of the button, the same as [Button ](/components/button/#api ) | string | `default` | |
| onClick | The same as [Button ](/components/button/#api ): called when you click the button on the left | (event) => void | - | |
2023-02-24 14:19:40 +08:00
## Note
Please ensure that the child node of `Dropdown` accepts `onMouseEnter` , `onMouseLeave` , `onFocus` , `onClick` events.
2023-03-27 15:33:22 +08:00
## Design Token
< ComponentTokenTable component = "Dropdown" > < / ComponentTokenTable >
2023-07-06 16:14:11 +08:00
## FAQ
### How to prevent Dropdown from being squeezed when it exceeds the screen horizontally?
You can use `width: max-content` style to handle this. ref [#43025 ](https://github.com/ant-design/ant-design/issues/43025#issuecomment-1594394135 ).