Skip to main content

Starwind UI v3.7 is here with stable Vue and Svelte, the new Chart component, and full RTL support. Read the release notes

Popover Primitive

Use Popover to show a small panel next to a trigger, such as filters. It positions the panel and handles dismissal when someone presses Escape or clicks outside.

Anatomy

Use the Astro primitive adapter to render Popover anatomy with the Runtime wiring included.

---
import { Popover } from "@starwind-ui/astro/popover";
---
<Popover.Root>
<Popover.Trigger>Open popover</Popover.Trigger>
<Popover.Backdrop />
<Popover.Positioner>
<Popover.Popup>
<Popover.Title>Popover title</Popover.Title>
<Popover.Description>Popover description</Popover.Description>
<Popover.Close>Close</Popover.Close>
<Popover.Arrow />
</Popover.Popup>
</Popover.Positioner>
</Popover.Root>

Astro, React, Vue, and Svelte components use the same underlying interactions. Each framework has its own way to read and update state. See the examples and your installed packageโ€™s types for the available props and events. Plain HTML uses DOM events and Runtime methods.

Floating Behavior

FactValue
Anchor parttrigger
Positioner partpositioner
Popup partpopup
Portal partportal
Option propsside, align, sideOffset, avoidCollisions, collisionStrategy

API Reference

Root

The main element that owns the Popover Runtime instance.

Default element
div
Discovery hook
data-sw-popover
Role
-

Props

Prop Type Default Toggle
open boolean -
Description
Controls whether Popover is open.
Kind
control
Targets
root
Full type
boolean
React

Use open for controlled state and defaultOpen for default state, and onOpenChange for change proposals.

  • open
  • defaultOpen
  • onOpenChange
Astro

Use open or defaultOpen for initial state, listen for starwind:open-change, and call setOpen for later updates.

  • open
  • defaultOpen
  • starwind:open-change
  • setOpen
Runtime / HTML

Use data-default-open for initial state, listen for starwind:open-change, and call setOpen for later updates.

  • data-default-open
  • starwind:open-change
  • setOpen
defaultOpen boolean false
Description
Sets whether Popover starts open.
Kind
control
Targets
root
Full type
boolean
React

Use open for controlled state and defaultOpen for default state, and onOpenChange for change proposals.

  • open
  • defaultOpen
  • onOpenChange
Astro

Use open or defaultOpen for initial state, listen for starwind:open-change, and call setOpen for later updates.

  • open
  • defaultOpen
  • starwind:open-change
  • setOpen
Runtime / HTML

Use data-default-open for initial state, listen for starwind:open-change, and call setOpen for later updates.

  • data-default-open
  • starwind:open-change
  • setOpen
closeOnEscape boolean true
Description
Closes Popover when Escape is pressed.
Kind
option
Targets
-
Full type
boolean
closeOnOutsideInteract boolean true
Description
Closes Popover when the user interacts outside it.
Kind
option
Targets
-
Full type
boolean
modal boolean false
Description
Makes Popover behave as a modal overlay.
Kind
option
Targets
-
Full type
boolean
openOnHover boolean false
Description
Configures the open on hover option for the Root part.
Kind
option
Targets
-
Full type
boolean
closeDelay number 200
Description
Sets how long Popover waits before closing.
Kind
option
Targets
root
Full type
number
onCloseComplete (open: boolean, details: PopoverCloseCompleteDetails) => void -
Description
Runs after Popover has finished closing.
Kind
callback
Targets
-
Full type
(open: boolean, details: PopoverCloseCompleteDetails) => void
onOpenChange (open: boolean, details: PopoverOpenChangeDetails) => void -
Description
Runs when Popover opens or closes.
Kind
callback
Targets
-
Full type
(open: boolean, details: PopoverOpenChangeDetails) => void
React

Use open for controlled state and defaultOpen for default state, and onOpenChange for change proposals.

  • open
  • defaultOpen
  • onOpenChange
Astro

Use open or defaultOpen for initial state, listen for starwind:open-change, and call setOpen for later updates.

  • open
  • defaultOpen
  • starwind:open-change
  • setOpen
Runtime / HTML

Use data-default-open for initial state, listen for starwind:open-change, and call setOpen for later updates.

  • data-default-open
  • starwind:open-change
  • setOpen

Events

Event Callback Value Toggle
openChange onOpenChange open: boolean
Description
Fires when Popover opens or closes.
DOM event
starwind:open-change
Details type
PopoverOpenChangeDetails
Timing
before-state-commit
Cancelable
Yes
Cancellation sequence
  1. Check internal eligibility and intent.
  2. Create one details object for the proposal.
  3. Call the Runtime callback with the details object when the controller exposes one.
  4. Dispatch the cancelable DOM event with the same details object, including when the callback canceled it.
  5. Read details.isCanceled, including cancellation caused by preventDefault().
  6. Apply the accepted state.
  7. Notify Runtime subscribers and other accepted-only observers.
closeComplete onCloseComplete open: boolean
Description
Fires after Popover has finished closing.
DOM event
starwind:close-complete
Details type
PopoverCloseCompleteDetails
Timing
after-state-commit
Cancelable
No

State

State Type Props Toggle
open boolean open / defaultOpen
Description
Tracks whether Popover is open.
Initial attribute
data-default-open
Runtime getter
getOpen
Runtime setter
setOpen
React

Use open for controlled state and defaultOpen for default state, and onOpenChange for change proposals.

  • open
  • defaultOpen
  • onOpenChange
Astro

Use open or defaultOpen for initial state, listen for starwind:open-change, and call setOpen for later updates.

  • open
  • defaultOpen
  • starwind:open-change
  • setOpen
Runtime / HTML

Use data-default-open for initial state, listen for starwind:open-change, and call setOpen for later updates.

  • data-default-open
  • starwind:open-change
  • setOpen

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-popover - Marks the Root part so Starwind Runtime can find it.
State
Attribute Value Description
data-state - Reflects the current state on the Root part.
Metadata
Attribute Value Description
data-default-open - Reflects the default open prop on the Root part.
data-close-on-escape - Reflects the close on escape prop on the Root part.
data-close-on-outside-interact - Reflects the close on outside interact prop on the Root part.
data-modal - Reflects the modal prop on the Root part.
data-open-on-hover - Reflects the open on hover prop on the Root part.
data-close-delay - Reflects the close delay prop on the Root part.

Trigger

The control that opens, closes, or targets the Popover content.

Default element
button
Discovery hook
data-sw-popover-trigger
Role
-

Props

Prop Type Default Toggle
asChild boolean -
Description
Merges behavior onto your child element instead of rendering the default Trigger element.
Kind
rendering
Targets
trigger
Full type
boolean

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-popover-trigger - Marks the Trigger part so Starwind Runtime can find it.
State
Attribute Value Description
data-state - Reflects the current state on the Trigger part.
Metadata
Attribute Value Description
data-as-child - Reflects the as child prop on the Trigger part.

Portal

Moves Popover overlay content to the document body when needed.

Default element
div
Discovery hook
data-sw-popover-portal
Role
-

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-popover-portal - Marks the Portal part so Starwind Runtime can find it.
data-placement - Marks the Portal part so Starwind Runtime can find it.
Metadata
Attribute Value Description
data-container - Reflects the container prop on the Portal part.
data-disabled - Reflects the disabled prop on the Portal part.
data-sw-portal-placement runtime Identifies Portal metadata for styling and selectors.

Positioner

Positions the Popover content relative to its trigger.

Default element
div
Discovery hook
data-sw-popover-positioner
Role
-

Props

Prop Type Default Toggle
side "top" | "right" | "bottom" | "left" "bottom"
Description
Sets the preferred side for Popover content.
Kind
option
Targets
positioner, popup
Full type
"top" | "right" | "bottom" | "left"
align "start" | "center" | "end" "center"
Description
Sets how Popover content aligns to its trigger.
Kind
option
Targets
positioner, popup
Full type
"start" | "center" | "end"
sideOffset number 4
Description
Sets the distance between Popover content and its trigger.
Kind
option
Targets
positioner, popup
Full type
number
avoidCollisions boolean true
Description
Allows Popover content to shift or flip to stay visible.
Kind
option
Targets
positioner, popup
Full type
boolean
collisionStrategy "initial-placement" | "best-fit" "initial-placement"
Description
Configures the collision strategy option for the Positioner part.
Kind
option
Targets
positioner, popup
Full type
"initial-placement" | "best-fit"

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-popover-positioner - Marks the Positioner part so Starwind Runtime can find it.
State
Attribute Value Description
data-state - Reflects the current state on the Positioner part.
Metadata
Attribute Value Description
data-side - Reflects the side prop on the Positioner part.
data-align - Reflects the align prop on the Positioner part.
data-side-offset - Reflects the side offset prop on the Positioner part.
data-avoid-collisions - Reflects the avoid collisions prop on the Positioner part.
data-collision-strategy - Reflects the collision strategy prop on the Positioner part.

The floating content container for Popover.

Default element
div
Discovery hook
data-sw-popover-popup
Role
dialog

Props

Prop Type Default Toggle
side "top" | "right" | "bottom" | "left" "bottom"
Description
Sets the preferred side for Popover content.
Kind
option
Targets
positioner, popup
Full type
"top" | "right" | "bottom" | "left"
align "start" | "center" | "end" "center"
Description
Sets how Popover content aligns to its trigger.
Kind
option
Targets
positioner, popup
Full type
"start" | "center" | "end"
sideOffset number 4
Description
Sets the distance between Popover content and its trigger.
Kind
option
Targets
positioner, popup
Full type
number
avoidCollisions boolean true
Description
Allows Popover content to shift or flip to stay visible.
Kind
option
Targets
positioner, popup
Full type
boolean
collisionStrategy "initial-placement" | "best-fit" "initial-placement"
Description
Configures the collision strategy option for the Popup part.
Kind
option
Targets
positioner, popup
Full type
"initial-placement" | "best-fit"

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-popover-popup - Marks the Popup part so Starwind Runtime can find it.
State
Attribute Value Description
data-state - Reflects the current state on the Popup part.
Metadata
Attribute Value Description
data-side - Reflects the side prop on the Popup part.
data-align - Reflects the align prop on the Popup part.
data-side-offset - Reflects the side offset prop on the Popup part.
data-avoid-collisions - Reflects the avoid collisions prop on the Popup part.
data-collision-strategy - Reflects the collision strategy prop on the Popup part.

Arrow

The arrow element that visually points to the trigger.

Default element
div
Discovery hook
data-sw-popover-arrow
Role
-

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-popover-arrow - Marks the Arrow part so Starwind Runtime can find it.

Backdrop

The backdrop shown behind the Popover overlay.

Default element
div
Discovery hook
data-sw-popover-backdrop
Role
-

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-popover-backdrop - Marks the Backdrop part so Starwind Runtime can find it.
State
Attribute Value Description
data-state - Reflects the current state on the Backdrop part.

Title

The accessible title for Popover.

Default element
h2
Discovery hook
data-sw-popover-title
Role
-

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-popover-title - Marks the Title part so Starwind Runtime can find it.

Description

Supporting description text for Popover.

Default element
p
Discovery hook
data-sw-popover-description
Role
-

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-popover-description - Marks the Description part so Starwind Runtime can find it.

Close

A control that closes Popover.

Default element
button
Discovery hook
data-sw-popover-close
Role
-

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-popover-close - Marks the Close part so Starwind Runtime can find it.

Viewport

The visible viewport for Popover content.

Default element
div
Discovery hook
data-sw-popover-viewport
Role
-

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-popover-viewport - Marks the Viewport part so Starwind Runtime can find it.

Runtime API

Factory
createPopover
Import
@starwind-ui/runtime/popover
Root hook
root data-sw-popover
Option props
closeOnEscape, closeOnOutsideInteract, defaultOpen, modal, onCloseComplete, onOpenChange, open, openOnHover

Option Lifecycles

OptionLifecycle
closeOnEscapeconstructor-only
closeOnOutsideInteractconstructor-only
defaultOpenconstructor-only
modalconstructor-only
onCloseCompleteconstructor-only
onOpenChangeconstructor-only
opensetter-backed
openOnHoverconstructor-only

Runtime Setters

Method Target Description
setOpen state: open Opens or closes Popover from Runtime code.
Component Relationship
Popover Direct primitive

Changelog

View version history v1.3.0 10 releases

v1.3.0

  • Popover content opens with the direction of its trigger and keeps it while open.
  • Popover now returns focus without scrolling the page. Before, in Safari, closing a popover after scrolling could make the page jump back to the trigger.
  • A click during the Popover close animation now goes to the page below the popup. Before, the closing popup caught the click, so a quick click on a control under it did nothing. An optional Popover backdrop still covers the page until the popup is hidden.
  • When you close a Popover with focus inside it, focus now goes back to the trigger as the close starts. The closing popup takes no keyboard input until it hides.
  • Fixed Popover in React and Vue when the Popup mounts after the Root. Before, the trigger did not open it. A Popup that you hide and show again, or replace with a new `key`, also opens again.
  • In React and Vue, an open Popup that unmounts now leaves the Root closed and removes the scroll lock. When it mounts again, it opens without a change event.
  • In React, a standalone `defaultOpen` Popover with no Portal no longer throws when it mounts.
  • In Vue, this Primitive now uses the same `asChild` child handling as the other Vue Primitives. Its public API is unchanged. An invalid `asChild` child now gives one shorter error message.
  • Escape in a Select or Combobox inside a Popover now closes only that inner list. Before, when focus was on the inner trigger or input, the same Escape also closed the Popover.
  • In Svelte, the `data-default-*` attributes of Popover now come only from its `default*` props, and `false` flags such as `data-close-on-click` are left out, as in the other frameworks.
  • In Vue, this component now needs Vue 3.5.21 or newer.
  • Internal code cleanup, such as unused code and import order. This cleanup does not change behavior.

v1.2.0

  • In Astro, an attribute that you set on a Popover part now wins over the part's own default for the same attribute, such as `role` or `aria-label`.
  • In Svelte, a defined `open` that you pass when Popover mounts now stays under your control, as in React and Vue. To change it, use `bind:` or update your state in the change callback. A form reset keeps it. If you pass `undefined` at mount, Popover keeps its own state.
  • In Svelte, the `children` snippet on the Popover root no longer receives `open`. Use `bind:open`.
  • Popover no longer moves focus back to its trigger when you move to another control while it closes. A field that you press outside the popup keeps focus.
  • Fixed a Popover trigger on a link or span that stayed disabled when a framework wrote `disabled="false"`. On a native form control, any `disabled` attribute still disables it.
  • In Svelte, the Popover trigger now accepts a link in `child`. Before, it warned in development, type checks rejected the link, and `ref` did not run. Use the new `TriggerChildPayload` type for your snippet.

v1.1.2

  • Vue Popover keeps its current open state when a change is canceled and responds to later open or close requests from your app.
  • Fixed Color Picker popups inside native dialogs so their controls remain visible and receive input.
  • Fixed popups extending beyond the viewport near an edge. They now shift to fit while keeping space from the trigger.
  • Reduced background work when a React page uses multiple menus, tooltips, or other portals.
  • Fixed nested Svelte overlays inside a dialog appearing behind their parent or failing to receive clicks.
  • Reduced background work when a Vue page uses multiple menus, tooltips, or other portals.
  • Fixed nested overlays appearing behind their parent in Vue and Svelte. Overlays can now render under the document body; if custom CSS or DOM queries require them to stay inside a parent, set a portal container or add `data-floating-root` to that parent.
  • Fixed React 18 retaining removed popup elements when the parent component stays mounted.
  • Reduced repeated JavaScript when Astro Popover is used with other Starwind components.

v1.1.1

  • Removed old comments from the Vue Primitive files that said the code was internal and not for release. The CLI also removes the blank line that these comments left in the Vue Primitive `index.ts` files that it copies into your project.

v1.1.0

  • Added `container` and `disabled` to the Portal part. `container` sets the element that holds the popup, and `disabled` keeps the popup in place. Portals now place nested popups in the same way every time, and they show their placement in data attributes.

v1.0.0

  • This Primitive is now stable at version `1.0.0`. Its API and behavior stay the same as in the previous release.

v0.1.3

  • The React Primitive files that the CLI copies into your project are now marked with `"use client"`, so they stay client components in React server frameworks.
  • In React, you can cancel a change from its change callback or DOM event before it applies. React then shows only the changes that apply.

v0.1.2

  • Astro and React Popover now accept `collisionStrategy`. Set it to `"best-fit"` to place the popup on the side with the most space when the screen is small.

v0.1.1

  • When `modal` is set, the page behind the Popover no longer scrolls while it is open.

v0.1.0

  • First release. Popover handles the open state, placement next to the trigger, focus, closing, open and close animations, and popovers inside popovers.