JGuang

Trigger

Trigger · Arco Design

Preview
npm install @arco-design/web-react@2.66.18

Trigger

Used to pop up a drop-down box by hovering, focusing, or clicking on a element.

Install

npm install @arco-design/web-react@2.66.18

Import @arco-design/web-react/dist/css/arco.css at the entry and set the locale with ConfigProvider. React 19 projects must also import @arco-design/web-react/es/_util/react-19-adapter first, or imperative APIs such as Message and Modal cannot render.

Examples

  • Basic: The basic usage. The popup layer has no style by default.
  • Controlled: Control the visibility of the popup.
  • nest: The popup can be nested.
  • multiple trigger: the trigger property can be an array.
  • algin mouse position: The popup will align mouse position. If you want to keep the pop-up layer displayed when you click in an area, and update the position of the pop-up layer align the mouse position, see the next example.
  • Update position
  • show arrow: Show arrow node. ## zh-US The popup layer has no style by default.
  • popupAlign: Specify moving a few pixels in some directions. For example, when position is 'top', set popupAlign to { top: 20}, the popup will move up by 20px, and set popupAlign to {top: [100, 20]}, the popup will move horizontally 100px right and 20px up.
  • updateOnScroll: Listen for container scrolling by setting updateOnScroll.
  • Adjust positioning when a specified distance from the viewport: The default pop-up layer position will be positioned and fine-tuned according to the viewport boundary. The boundaryDistance parameter can be set to adjust the positioning when it is a certain distance from the viewport boundary. Only takes effect when autoFitPosition=true and alignPoint=false.

Examples come from the official Arco Design repository (MIT) at the commit published as npm 2.66.18. Some use online images or upload endpoints; network requests are disabled in previews.

API

Trigger

PropertyDescriptionTypeDefaultValueVersion
alignPointThe popup will align mouse positionboolean--
autoAlignPopupMinWidthSet the minimum width of the popup by the width of the child elementboolean--
autoAlignPopupWidthSet the width of the popup by the width of the child elementboolean--
autoFitPositionWhether to automatically adjust the position of the popup according to the viewportbooleantrue-
autoFixPositionWhether to automatically reposition when the popup's size changes.booleantrue-
blurToHideWhether close the popup when the child node losing focus. Only work when the trigger containers focusbooleantrue-
clickToCloseWhether to allow close the popup by clicking the child node.When trigger contains click, contextMenu, the default is true. otherwise falseboolean--
containerScrollToCloseWhether to close the popup when the container is scrolledboolean-2.34.0
defaultPopupVisibleWhether the popup is visible by defaultboolean--
disabledWhether to disableboolean--
escToCloseWhether to allow close the popup by pressing ESC.boolean--
mouseLeaveToCloseWhether to allow close the popup by clicking the child node.booleantrue2.22.0
popupHoverStayWhether the popup is visible when the mouse hovers over the popup.booleantrue-
popupVisibleWhether the popup is visibleboolean--
showArrowWhether to display arrow nodeboolean--
unmountOnExitWhether to destroy the popup when hiddenbooleantrue-
updateOnScrollWhether to update the popover's position when the container is scrolledboolean-2.32.0
focusDelayDelay time to show when focus. unit: ms.number--
mouseEnterDelayDelay time to show when mouse enter. unit: ms.number100-
mouseLeaveDelayDelay time to show when mouse leave. unit: ms.number100-
childrenPrefixSet an additional class name(${childrenPrefix}-open) for the container of the popup.string--
classNamesAnimation class namestringfadeIn-
positionThe position of the popup relative to the child node.| 'top'| 'tl'| 'tr'| 'bottom'| 'bl'| 'br'| 'left'| 'lt'| 'lb'| 'right'| 'rt'| 'rb'bottom-
triggerTypes of events that cause the popup to show| 'hover'| 'click'| 'focus'| 'contextMenu'| Array<'hover' | 'click' | 'focus' | 'contextMenu'>hover-
arrowPropsThe html attributes of the arrow nodeHTMLAttributes<HTMLDivElement>--
boundaryDistanceThe default pop-up layer position will be positioned and fine-tuned according to the viewport boundary. This parameter can be set to adjust the positioning when it is a certain distance from the viewport boundary. Only takes effect when autoFitPosition=true and alignPoint=false.| { left?: number; bottom?: number }| { left?: number; top?: number }| { right?: number; bottom?: number }| { right?: number; top?: number }-2.59.0
classNameAdditional css classstring | string[]--
clickOutsideToCloseWhether to allow close the popup by clicking the area outside the child node and the popup box.By default, this logic is triggered in the bubbling phase. You can set { capture: true } to specify the triggering phase in the capture phase.boolean | { capture: boolean }true{ capture: boolean } in 2.55.0
durationAnimation transition timenumber | { exit?: number; enter?: number; appear?: number }200-
onClickOutsideCallback when click the area outside the child and the popupFunction--
popupAlignAdjust the position of the popup. Indicates moving a few pixels in one direction. example{left?: number | [number, number];right?: number | [number, number];top?: number | [number, number];bottom?: number | [number, number];}{}-
popupStyleThe css style of the content of the popupCSSProperties--
styleThe additional css classCSSProperties--
getDocumentReturn a element which will be attached click event to close trigger() => Element() => window.document-
getPopupContainerSet the parent node which the popup will be rendered to.(node: HTMLElement) => Element--
onClickCallback when click the child node. (Only work when trigger contains click)(e) => void--
onVisibleChangeCallback when the visibility of the popup is changed(visible: boolean) => void--
popupThe content of the popup() => ReactNode--

When to fired onVisibleChange

  • When trigger contains click

    1. Click on the area outside the child node and the popup will hide the popup. This behavior can be prevented if you set clickOutsideToClose=false.
    2. Click on the child node will show or hide the popup. If you set clickToClose=true, when the popup is displayed, clicking the child node will not hide the popup.
  • When trigger contains contextMenu

  1. Click on the area outside the child node and the popup will hide the popup. This behavior can be prevented if you set clickOutsideToClose=false.
  2. Right-click on the child node will show the popup.
  • When trigger contains hover

    1. The popup will be hidden when the mouse moved out of the popup, and did not move into the child node within ${mouseLeaveDelay}ms.
    2. The popup will be hidden when the mouse moved out of the child node, and did not move into the popup within ${mouseLeaveDelay}ms.

    If popupHoverStay=false is set, the mouse cannot be moved into the popup.

  • When trigger contains focus

    1. The popup will be hidden when the child node losing focus. This behavior can be prevented if you set blurToHide=false.
    2. Click on the area outside the child node and the popup will hide the popup if you set blurToHide=false.

Q&A

  1. When getPopupContainer is set, the popup layer is in the wrong position?

    The default autoFitPosition property of the component is true, which means that the component will automatically adjust the position of the popup layer according to the size of the popup layer, its position in the viewport and the mounted parent element. For example, set position=top , but the space above is insufficient, the pop-up layer will be covered, and the component will determine whether to display the pop-up layer below the trigger element according to the situation. If getPopupContainer is set, the style attribute left of the popup layer is at least 0, that is, the minimum distance from the left border of the parent element is 0, so as to avoid exceeding the parent element and causing it to be blocked. AutoFitPosition can be avoided by setting autoFitPosition=false.