JGuang

Popover

Popover · Ant Design Mobile

Preview
npm install antd-mobile@5.43.0

Popover

Click on the element to pop up a bubble menu.

Install

npm install antd-mobile@5.43.0

antd-mobile is for mobile web, not React Native or Mini Programs. React 19 projects must register createRoot with unstableSetRender at the entry, or imperative APIs such as Toast and Dialog cannot render. Switch dark mode with <html data-prefers-color-scheme="dark">.

Examples come from the official Ant Design Mobile repository (MIT) at the commit published as npm 5.43.0. Presentation helpers such as DemoBlock are JGuang rewrites, not antd-mobile APIs.

Click on the element to pop up a bubble menu.

When to Use

Navigation applicable to functions can only be evoked by the icons on the navigation bar, and is usually used to accommodate low-frequency functions.

Demos

Popover

Props

NameDescriptionTypeDefault
childrenThe element that triggered the PopoverReact.ReactElement-
contentThe content of the PopoverReact.ReactNode-
defaultVisibleWhether to show or hide by defaultbooleanfalse
destroyOnHideWhen hiding, whether to destroy the content of tooltipbooleanfalse
getContainerThe floating layer renders the parent node, which would be rendered on the body by default() => HTMLElement() => document.body
modeSet bright color mode or black mode'light' | 'dark''light'
onVisibleChangeCallback when the visible prop is changed(visible: boolean) => void-
placementThe position of the Popover'top' | 'top-start' | 'top-end' | 'right' | 'right-start' | 'right-end' | 'bottom' | 'bottom-start' | 'bottom-end' | 'left' | 'left-start' | 'left-end''top'
stopPropagationStop the propagation of some events.PropagationEvent[]['click']
triggerEvent to trigger'click'-
visibleWhether to display pop-up content in controlled modeboolean-

Prior to version 5.5.0, the optional values for placement were:

top left right bottom topLeft topRight bottomLeft bottomRight leftTop leftBottom rightTop rightBottom

In 5.5.0 and later versions, the writing of placement has undergone some adjustments, becoming:

top top-start top-end right right-start right-end bottom bottom-start bottom-end left left-start left-end

In order to maintain compatibility, we still support the use of the old version of the writing method, but if you see the prompt here, please try to use the new version of the writing method.

CSS Variables

NameDescriptionDefaultGlobal
--z-indexz-index of the popover element1030--adm-popover-z-index
--arrow-sizethe arrow size of the popover element8px-

Ref

NameDescriptionType
hideHide the Popover() => void
showShow the Popover() => void
visibleWhether the Popover is diplayingboolean

Popover.Menu

Props

Except for content, all other attributes are inherited from Popover, the unique attributes are as follows:

NameDescriptionTypeDefault
actionsMenu list, used when the pop-up content is a standard menuAction[]-
maxCountMaximum number of menu lists, if exceeded, hide for scrollingnumber-
onActionCallback of the selected menum, when the menu list is used(item: Action) => void-

Action

NameDescriptionTypeDefault
disabledWhether disabledbooleanfalse
iconThe icon of the menu itemReactNodenull
keyThe unique identifier of the menu, the default is indexstring | numberactions array's index
onClickTriggered on click() => void-
textMenu list, used when the pop-up content is a standard menuReactNode-

CSS Variables

Same as Popover.

Ref

Same as Popover.

FAQ

Why the Popover not show in some cases?

Click Popover will trigger two click events, one for label, one for input.

<label>
  <Popover content='hello' trigger='click'>
    <span>label</span>
  </Popover>
  <input />
</label>

Default behavior can be prevented with e.preventDefault().

<label>
  <Popover content='hello' trigger='click'>
    <span onClick={e => e.preventDefault()}>label</span>
  </Popover>
  <input />
</label>

What if the warning findDOMNode is deprecated in StrictMode. appears in the browser console?

If React StrictMode is enabled in your project, you may encounter the following warning:

Warning: findDOMNode is deprecated in StrictMode. findDOMNode was passed an instance of Wrapper which is inside StrictMode. Instead, add a ref directly to the element you want to reference. Learn more about using refs safely here: https://reactjs.org/ link/strict-mode-find-node

Don't panic, this is expected behavior, because we haven't found a better alternative, so we can only continue to use the deprecated findDOMNode API. Please just ignore this error.