JGuang

Popover

Popover · Ant Design

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

Popover

The floating card pops up when clicking/mouse hovering over an element.

When To Use

A simple popup menu to provide extra information or operations.

Comparing with Tooltip, besides information Popover card can also provide action elements like links and buttons.

Examples

  • Basic · basic

  • Three ways to trigger · triggerType

  • Placement · placement

  • Arrow · arrow

  • Auto Shift · shift

  • Controlling the close of the dialog · control

  • Hover with click popover · hover-with-click

  • Custom semantic dom styling · style-class

API

Common props ref:Common props

PropertyDescriptionTypeDefault valueVersionGlobal Config
classNamesCustomize class for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string>-5.23.0
contentContent of the cardReactNode | () => ReactNode-×
titleTitle of the cardReactNode | () => ReactNode-×
stylesCustomize inline style for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties>-5.23.0

<Antd component="Alert" title="The following APIs are shared by Tooltip, Popconfirm, Popover." type="info" banner="true"></Antd>

PropertyDescriptionTypeDefaultVersionGlobal Config
alignPlease refer to the settings dom-alignobject-×
arrowChange arrow's visible state and change whether the arrow is pointed at the center of target.boolean | { pointAtCenter: boolean }true5.2.0Tooltip: 6.0.0, Popover: 6.0.0, Popconfirm: 6.0.0
autoAdjustOverflowWhether to adjust popup placement automatically when popup is off screenbooleantrue×
colorThe background colorstring-4.3.0×
classNamesCustomize class for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string>-5.23.0Tooltip: 5.23.0, Popover: 5.23.0, Popconfirm: 5.23.0
defaultOpenWhether the floating tooltip card is open by defaultbooleanfalse4.23.0×
destroyTooltipOnHideWhether destroy dom when closebooleanfalse×
destroyOnHiddenWhether destroy dom when closebooleanfalse5.25.0×
freshTooltip will cache content when it is closed by default. Setting this property will always keep updatingbooleanfalse5.10.0×
getPopupContainerThe DOM container of the tip, the default behavior is to create a div element in body(triggerNode: HTMLElement) => HTMLElement() => document.body×
mouseEnterDelayDelay in seconds, before tooltip is shown on mouse enternumber0.1Tooltip: 6.6.0, Popover: 6.6.0, Popconfirm: 6.6.0
mouseLeaveDelayDelay in seconds, before tooltip is hidden on mouse leavenumber0.1Tooltip: 6.6.0, Popover: 6.6.0, Popconfirm: 6.6.0
overlayClassNameClass name of the tooltip card, please use classNames.root insteadstring-×
overlayStyleStyle of the tooltip card, please use styles.rootReact.CSSProperties-×
overlayInnerStyleStyle of the tooltip inner content, please use styles.container insteadReact.CSSProperties-×
placementThe position of the tooltip relative to the target, which can be one of top left right bottom topLeft topRight bottomLeft bottomRight leftTop leftBottom rightTop rightBottomstringtop×
stylesCustomize inline style for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties>-5.23.0Tooltip: 5.23.0, Popover: 5.23.0, Popconfirm: 5.23.0
triggerTooltip trigger mode. Could be multiple by passing an arrayhover | focus | click | contextMenu | Array<string>hoverTooltip: 6.1.0, Popover: 6.1.0, Popconfirm: 6.1.0
openWhether the floating tooltip card is open or not. Use visible under 4.23.0 (why?)booleanfalse4.23.0×
zIndexConfig z-index of Tooltipnumber-×
onOpenChangeCallback executed when visibility of the tooltip card is changed(open: boolean) => void-4.23.0×

Note

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

Semantic DOM

Semantic nodeNative descriptionVersion
rootRoot element, set absolute positioning, z-index, transform origin, arrow direction and popover container styles—
containerContainer element, set background color, padding, border radius, shadow, border and content display styles—
titleTitle element, set title text styles and spacing—
contentContent element, set content text styles and layout—
arrowArrow element with width, height, position, color and border styles—

Semantic description source: vendor/components/popover/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
width?number | stringWidth of Popover
minWidth?number | stringMin width of Popover
titleMinWidthnumber | stringMin width of Popover title
zIndexPopupnumberz-index of Popover
innerPaddingnumberSee native declaration and inherited types
titlePaddingnumber | stringSee native declaration and inherited types
titleMarginBottomnumberSee native declaration and inherited types
titleBorderBottomstringSee native declaration and inherited types
innerContentPaddingnumber | stringSee native declaration and inherited types

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

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

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

import { initZoomMotion } 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,
  PresetColorType,
} from '../../theme/internal';

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

import { genCssVar } from '../../theme/util/genStyleUtils';

export interface ComponentToken extends ArrowToken, ArrowOffsetToken {
  /**
   * @deprecated Please use `titleMinWidth` instead
   * @desc 气泡卡片宽度
   * @descEN Width of Popover
   */
  width?: number | string;
  /**
   * @deprecated Please use `titleMinWidth` instead
   * @desc 气泡卡片最小宽度
   * @descEN Min width of Popover
   */
  minWidth?: number | string;
  /**
   * @desc 气泡卡片标题最小宽度
   * @descEN Min width of Popover title
   */
  titleMinWidth: number | string;
  /**
   * @desc 气泡卡片 z-index
   * @descEN z-index of Popover
   */
  zIndexPopup: number;
  /** @internal */
  innerPadding: number;
  /** @internal */
  titlePadding: number | string;
  /** @internal */
  titleMarginBottom: number;
  /** @internal */
  titleBorderBottom: string;
  /** @internal */
  innerContentPadding: number | string;
}

/**
 * @desc Popover 组件的 Token
 * @descEN Token for Popover component
 */
export type PopoverToken = FullToken<'Popover'> & {
  /**
   * @desc 气泡卡片背景色
   * @descEN Background color of Popover
   */
  popoverBg: string;
  /**
   * @desc 气泡卡片文字颜色
   * @descEN Text color of Popover
   */
  popoverColor: string;
};

FAQ

<Antd component="Alert" title="The following FAQ applies to Tooltip, Popconfirm, Popover components." type="warning" banner="true"></Antd>

Why does the warning findDOMNode is deprecated sometimes appear in strict mode?

This is due to the implementation of @rc-component/trigger. @rc-component/trigger forces children to accept ref, otherwise it will fall back to findDOMNode, so children need to be native html tags. If not, you need to use React.forwardRef transparently passes ref to native html tags.

Why is the tooltip for my custom component not opening?

Similar issues: #15909, #12812.

Please ensure that the child node to accept onMouseEnter, onMouseLeave, onPointerEnter, onPointerLeave, onFocus, and onClick events, If you create your own component and do not explicitly add these mouse and pointer events as props, the tooltip will never appear. See Example.

What's the placement logic?

It will follow placement config when screen has enough space. And flip when space is not enough (Such as top to bottom or topLeft to bottomLeft). Single direction such as top bottom left right will auto shift on the view:

<img alt="shift" height="200" src="https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*sxaTTJjLtIMAAAAAAAAAAAAADrJ8AQ/original" />

When placement is set to edge align such as topLeft bottomRight, it will only do flip but not do shift.

How to support keyboard accessibility?

By default, Tooltip and similar components trigger on hover rather than focus, so they will not respond to keyboard focus events. If you want the component to support keyboard accessibility, you can enable it in the following ways:

  • Enable for a single component: Set the trigger property to include focus, for example trigger="focus" or trigger={['hover', 'focus']}.
  • Enable globally: Use ConfigProvider to set global configuration, so all relevant components across your application support keyboard focus trigger by default.
import { ConfigProvider, Tooltip, Button } from 'antd';

// Single component
<Tooltip trigger={['hover', 'focus']} title="Title">
  <Button>Button</Button>
</Tooltip>

// Global configuration
<ConfigProvider
  tooltip={{ trigger: ['hover', 'focus'] }}
  popover={{ trigger: ['hover', 'focus'] }}
  popconfirm={{ trigger: ['hover', 'focus'] }}
>
  <App />
</ConfigProvider>

For more questions, please refer to Tooltip FAQ.

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/popover/PurePanel.tsx
  • vendor/components/popover/index.tsx
  • vendor/components/popover/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.