--- title: Popover description: "`Popover` is a component that floats around an element to display information." links: - style: https://github.com/yamada-ui/yamada-ui/tree/main/packages/react/src/components/popover/popover.style.ts - source: https://github.com/yamada-ui/yamada-ui/tree/main/packages/react/src/components/popover - storybook: https://yamada-ui.github.io/yamada-ui?path=/story/components-popover--basic --- ```tsx 空条承太郎 やれやれだぜ ``` ## Usage ```tsx import { Popover } from "@yamada-ui/react" ``` ```tsx import { Popover } from "@/components/ui" ``` ```tsx import { Popover } from "@workspaces/ui" ``` ```tsx ``` ### Change Size ```tsx {(size) => ( 花京院典明 レロレロレロレロレロレロ )} ``` ### Add Footer ```tsx ジョルノ・ジョバァーナ 僕には夢がある 黄金の風 ``` ### Display Popover on Different Element To display a popover on a different element, use `Popover.Anchor`. ```tsx
Here Display Popover
ジョセフ・ジョースター お前の次のセリフは…「そんなバカな!」と言う
``` ### Change Animation To change the animation, set `animationScheme` to `"block-start"`, `"inline-end"`, etc. By default, `"scale"` is set. ```tsx {(animationScheme) => ( ブローノ・ブチャラティ アリーヴェデルチ(さよならだ) )} ``` ### Change Placement To change the placement, set `placement` to `"start"`, `"end-end"`, etc. By default, `"end"` is set. ```tsx {(placement) => ( ディアボロ これが…レクイエム…だ )} ``` ### Change Duration To change the duration, set `duration` to a number (seconds). ```tsx 吉良吉影 僕は平穏に暮らしたいだけなんだ ``` ### Change Offset To change the offset, set `gutter` or `offset` to a value. ```tsx 東方仗助 グレートだぜ 東方仗助 グレートだぜ ``` ### Use Modal To use modal, set `modal` to `true`. This enables scroll blocking and focus trapping. ```tsx フーゴ・パンナコッタ ``` ### Disable To disable the popover, set `disabled` to `true`. ```tsx 虹村億泰 おい、仗助! ``` ### Disable Close on Outside Click To disable closing when clicking outside, set `closeOnBlur` to `false`. ```tsx イギー んがくく(犬の鳴き声) ``` ### Disable Close on ESC Key To disable closing when pressing the ESC key, set `closeOnEsc` to `false`. ```tsx ディオ・ブランドー 無駄無駄無駄! ``` ### Disable Auto Focus To disable automatic focus when the popover opens, set `autoFocus` to `false`. ```tsx 岸辺露伴 ``` ### Set Initial Focus To set the initial focus, pass a `Ref` to `initialFocusRef`. ```tsx const inputRef = useRef(null) return ( ナランチャ・ギルガ ) ``` ### Block Scroll To block scrolling while the popover is open, set `blockScrollOnMount` to `true`. ```tsx 岸辺露伴 だが断る ``` ### Close on Scroll To automatically close the popover when scrolling, set `closeOnScroll` to `true`. ```tsx ギアッチョ 根掘り葉掘り聞きやがって! ``` ### Nest Popovers ```tsx 花京院典明 やはりエジプトか……いつ出発する? 空条承太郎 花京院 ``` ### Control ```tsx const { open, onClose, onOpen } = useDisclosure() return ( スピードワゴン こいつはくせえッー! ゲロ以下のにおいがプンプンするぜッーーーーッ!! ) ``` ## Props ### Popover.Root | Prop | Default | Type | Description | | -------------------- | --------- | -------------------------------------- | --------------------------------------------------------------------------------------------- | | `size` | `"md"` | `"lg" \| "md" \| "sm" \| "xs"` | The size of the component. | | `animationScheme` | `"scale"` | `"none" \| "scale" \| SimplePlacement` | The animation of the element. | | `autoFocus` | `true` | `boolean` | If `true`, focus will be transferred to the first interactive element when the popover opens. | | `autoUpdate` | `true` | `boolean` | If `true`, automatically updates the position of the floating element when necessary. | | `blockScrollOnMount` | `false` | `boolean` | If `true`, scrolling will be disabled on the `body` when the modal opens. | | `children` | - | `ReactNodeOrFunction<{ | open: boolean onClose: () => void }>`| The children of the popover. | |`closeOnBlur`|`true`|`boolean`| If`true`, the popover will close when you blur out it by clicking outside or tabbing out. | | `closeOnEsc`|`true`|`boolean`| If`true`, the popover will hide on pressing Esc key. | | `closeOnScroll`|`false`|`boolean`| If`true`, the popover will hide on scroll. | | `defaultOpen`| - |`boolean`| If`true`, the element will be initially opened. | | `disabled`|`false`|`boolean`| If`true`, the popover will be disabled. | | `duration`|`0.2`|`PopupAnimationProps["duration"]`| The animation duration. | |`elements`| - |`{ floating?: HTMLElement \| null reference?: null \| Reference }`| Object containing the reference and floating elements. | |`flip`|`true`|`boolean`| If`true`, the popper will change its placement and flip when it's about to overflow its boundary area. | | `gutter`|`8`|`number`| The distance or margin between the reference and popper. It is used internally to create an`offset`modifier. | |`initialFocusRef`| - |`RefObject`| The`ref`of the element that should receive focus when the popover opens. | |`matchWidth`|`false`|`boolean`| If`true`, the popper will match the width of the reference at all times. It's useful for `autocomplete`, `date-picker`and`select`patterns. | |`middleware`| - |`(false \| Middleware \| null \| undefined)[]`| Array of middleware objects to modify the positioning or provide data for rendering. | |`modal`|`false`|`boolean`| If`true`, the popover will be modal. - scrolling is blocked. - focus is trapped within the popover. | | `offset`| - |`[number, number]`| The main and cross-axis offset to displace popper element from its reference element. | |`onClose`| - |`() => void \| Promise`| Callback invoked to close the element. | |`onOpen`| - |`() => void \| Promise`| Callback invoked to open the element. | |`open`| - |`boolean`| If`true`, the element will be opened. | | `openOnClick`|`true`|`boolean`| If`true`, the popover will be opened when click on the field. | | `placement`|`"end"`|`Direction`| The placement of the popper relative to its reference. | |`platform`| - |`Platform`| Custom or extended platform object. | |`preventOverflow`|`true`|`boolean`| If`true`, will prevent the popper from being cut off and ensure it's visible within the boundary area. | | `strategy`|`"absolute"`|`Strategy`| The CSS positioning strategy to use. | |`transferFocus`|`true`|`boolean`| If`true`, the focus will be transferred to the popover content when the tab key is pressed. | | `transform`|`true`|`boolean`| Whether to use`transform`for positioning instead of`top`and`left`(layout) in the`floatingStyles`object. | |`updateRef`| - |`RefObject<() => void>`| Update the position of the floating element, re-rendering the component if required. | |`whileElementsMounted`| - |`(reference: Reference, floating: HTMLElement, update: () => void) => () => void`| A callback invoked when both the reference and floating elements are mounted, and cleaned up when either is unmounted. This is useful for setting up event listeners (e.g. pass`autoUpdate`). | | `withCloseButton`|`true`|`boolean`| If`true`, display the popover close button. | ### Popover.Anchor | Prop | Default | Type | Description | | ------------- | ------- | ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ | | `as` | - | `As` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | ### Popover.Body | Prop | Default | Type | Description | | ------------- | ------- | ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ | | `as` | - | `As` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | ### Popover.Content | Prop | Default | Type | Description | | ------------- | ------- | ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ | | `as` | - | `keyof IntrinsicElements` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | | `portalProps` | - | `Omit` | Props for portal component. | ### Popover.Footer | Prop | Default | Type | Description | | ------------- | ------- | ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ | | `as` | - | `As` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | ### Popover.Header | Prop | Default | Type | Description | | ------------- | ------- | ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ | | `as` | - | `As` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | ### Popover.Trigger | Prop | Default | Type | Description | | ------------- | ------- | ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ | | `as` | - | `As` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | ## Accessibility Currently, this section is being updated due to the migration of v2.