Back to Ant Design

Dropdown

components/dropdown/index.en-US.md

6.3.74.5 KB
Original Source

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

<!-- prettier-ignore -->

<code src="./demo/basic.tsx">Basic</code> <code src="./demo/extra.tsx" version="5.21.0">Extra node</code> <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> <code src="./demo/sub-menu-debug.tsx" debug>Cascading menu</code> <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/style-class.tsx" version="6.0.0">Custom semantic dom styling</code> <code src="./demo/menu-full.tsx" debug>Menu full styles</code> <code src="./demo/render-panel.tsx" debug>_InternalPanelDoNotUseOrYouWillBeFired</code> <code src="./demo/icon-debug.tsx" debug>Icon debug</code>

API

Common props ref:Common props

PropertyDescriptionTypeDefaultVersion
arrowWhether the dropdown arrow should be visibleboolean | { pointAtCenter: boolean }false
autoAdjustOverflowWhether to adjust dropdown placement automatically when dropdown is off screenbooleantrue5.2.0
classNamesCustomize class for each semantic structure inside the Dropdown component. Supports object or function.Record<SemanticDOM, string> | (info: { props }) => Record<SemanticDOM, string>-
disabledWhether the dropdown menu is disabledboolean-
destroyPopupOnHideWhether destroy dropdown when hidden, use destroyOnHidden insteadbooleanfalse
destroyOnHiddenWhether destroy dropdown when hiddenbooleanfalse5.25.0
dropdownRenderCustomize dropdown content, use popupRender instead(menus: ReactNode) => ReactNode-4.24.0
popupRenderCustomize popup content(menus: ReactNode) => ReactNode-5.25.0
getPopupContainerTo 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(triggerNode: HTMLElement) => HTMLElement() => document.body
menuThe menu propsMenuProps-
overlayClassNameThe class name of the dropdown root element, please use classNames.root insteadstring-
overlayStyleThe style of the dropdown root element, please use styles.root insteadCSSProperties-
placementPlacement of popup menu: bottom bottomLeft bottomRight top topLeft topRightstringbottomLeft
stylesCustomize inline style for each semantic structure inside the Dropdown component. Supports object or function.Record<SemanticDOM, CSSProperties> | (info: { props }) => Record<SemanticDOM, CSSProperties>-
triggerThe trigger mode which executes the dropdown action. Note that hover can't be used on touchscreensArray<click|hover|contextMenu>[hover]
openWhether the dropdown menu is currently openboolean-
onOpenChangeCalled when the open state is changed. Not trigger when hidden by click item(open: boolean, info: { source: 'trigger' | 'menu' }) => void-info.source: 5.11.0

Note

Please ensure that the child node of Dropdown accepts onMouseEnter, onMouseLeave, onFocus, onClick events.

Semantic DOM

<code src="./demo/_semantic.tsx" simplify="true"></code>

Design Token

<ComponentTokenTable component="Dropdown"></ComponentTokenTable>

FAQ

How to prevent Dropdown from being squeezed when it exceeds the screen horizontally? {#faq-dropdown-squeezed}

You can use width: max-content style to handle this. ref #43025.