JGuang

Dropdown

Dropdown · Ant Design

Preview
npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23

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

  • Basic · basic

  • Extra node · extra

  • Placement · placement

  • Arrow · arrow

  • Other elements · item

  • Arrow pointing at the center · arrow-center

  • Trigger mode · trigger

  • Click event · event

  • Button with dropdown menu · dropdown-button

  • Custom dropdown · custom-dropdown

  • Cascading menu · sub-menu

  • The way of hiding menu. · overlay-open

  • Context Menu · context-menu

  • Loading · loading

  • Selectable Menu · selectable

  • Selection actions · selection

  • Custom semantic dom styling · style-class

API

Common props ref:Common props

PropertyDescriptionTypeDefaultVersionGlobal Config
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>-6.0.0
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: top topLeft topRight bottom bottomLeft bottomRight left leftTop leftBottom right rightTop rightBottomstringbottomLeftleft leftTop leftBottom right rightTop rightBottom: 6.5.0×
stylesCustomize inline style for each semantic structure inside the Dropdown component. Supports object or function.Record<SemanticDOM, CSSProperties> | (info: { props }) => Record<SemanticDOM, CSSProperties>-6.0.0
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

Semantic nodeNative descriptionVersion
rootRoot element of dropdown, sets positioning, z-index and container styles—
itemTitleTitle content area of dropdown option, sets layout and text styles—
itemIndividual dropdown option element, sets interaction states and background styles—
itemContentMain content area of dropdown option, sets content layout and link styles—
itemIconIcon area of dropdown option, sets icon size and spacing styles—

Semantic description source: vendor/components/dropdown/demo/_semantic.tsx

Design Token

Types, inheritance and declarations retain the pinned native source. Defaults are computed by the native theme and may be overridden by ConfigProvider; this table does not invent static defaults.

TokenTypeNative description
zIndexPopupnumberz-index of dropdown
paddingBlockCSSProperties['paddingBlock']Vertical padding of dropdown

Declaration source: vendor/components/dropdown/style/index.ts

import type { CSSProperties } from 'react';

import { unit } from '@ant-design/cssinjs';

import { genFocusStyle, resetComponent } from '../../style';

import {
  initMoveMotion,
  initSlideMotion,
  initZoomMotion,
  slideDownIn,
  slideDownOut,
  slideLeftIn,
  slideLeftOut,
  slideRightIn,
  slideRightOut,
  slideUpIn,
  slideUpOut,
} from '../../style/motion';

import type { ArrowOffsetToken } from '../../style/placementArrow';

import getArrowStyle, { getArrowOffsetToken } from '../../style/placementArrow';

import type { ArrowToken } from '../../style/roundedArrow';

import { getArrowToken } from '../../style/roundedArrow';

import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal';

import { genStyleHooks, mergeToken } from '../../theme/internal';

import genStatusStyle from './status';

export interface ComponentToken extends ArrowToken, ArrowOffsetToken {
  /**
   * @desc 下拉菜单 z-index
   * @descEN z-index of dropdown
   */
  zIndexPopup: number;
  /**
   * @desc 下拉菜单纵向内边距
   * @descEN Vertical padding of dropdown
   */
  paddingBlock: CSSProperties['paddingBlock'];
}

/**
 * @desc Dropdown 组件的 Token
 * @descEN Token for Dropdown component
 */
export interface DropdownToken extends FullToken<'Dropdown'> {
  /**
   * @desc 下拉箭头距离
   * @descEN Distance of dropdown arrow
   */
  dropdownArrowDistance: number | string;
  /**
   * @desc 下拉菜单边缘子项内边距
   * @descEN Padding of edge child in dropdown menu
   */
  dropdownEdgeChildPadding: number;
  /**
   * @desc 菜单类名
   * @descEN Menu class name
   */
  menuCls: string;
}

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.

Shared native props

Tips: The following generic properties apply to most antd components; those not supported are described separately.

PropertyDescriptionTypeDefault
styleThe additional styleCSSProperties-
classNameThe additional css classstring-
rootClassNameClassName on the root elementstring-
autoFocusAuto focus when component mounted, only effective for focusable elements like forms, links, etc.booleanfalse

Install and reproduce an example

npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23

Use ConfigProvider and native App; configure dayjs locale separately. Each example lists its complete source files and additional pinned dependencies in View code. Example names select demos, not universal component props. See the resource setup guide for theme, locale and SSR.

Native type references

The source viewer includes unchanged native implementations and the following source declarations. Inherited types remain in their native packages. English source comments are preserved as code reference.

  • vendor/components/dropdown/dropdown-button.tsx
  • vendor/components/dropdown/dropdown.tsx
  • vendor/components/dropdown/style/index.ts

Source and license

https://github.com/ant-design/ant-design/tree/4a39f54842eade4e565ab336ef6097cd7e723cdd

Original bilingual prose and executable examples are retained. Website-only embeds and token tables are expanded locally. Ant Design is MIT; separately listed dependency notices also apply. Upload previews block outbound requests and do not provide a backend.