bits

Popover

Displays content in a floating container that appears above the surrounding content.

Structure

	<script lang="ts">
  import { Popover } from "bits-ui";
</script>
 
<Popover.Root>
  <Popover.Trigger />
  <Popover.Content>
    <Popover.Close />
    <Popover.Arrow />
  </Popover.Content>
</Popover.Root>
	<script lang="ts">
  import { Popover } from "bits-ui";
</script>
 
<Popover.Root>
  <Popover.Trigger />
  <Popover.Content>
    <Popover.Close />
    <Popover.Arrow />
  </Popover.Content>
</Popover.Root>

Controlled Usage

If you want to control or be aware of the open state of the popover from outside of the component, you can bind to the open prop.

	<script lang="ts">
  import { Popover } from "bits-ui";
  let popoverOpen = false;
</script>
 
<button on:click={() => (popoverOpen = true)}>Open</button>
<Popover.Root bind:open={popoverOpen}>
  <Popover.Trigger />
  <Popover.Content>
    <Popover.Close />
    <Popover.Arrow />
  </Popover.Content>
</Popover.Root>
	<script lang="ts">
  import { Popover } from "bits-ui";
  let popoverOpen = false;
</script>
 
<button on:click={() => (popoverOpen = true)}>Open</button>
<Popover.Root bind:open={popoverOpen}>
  <Popover.Trigger />
  <Popover.Content>
    <Popover.Close />
    <Popover.Arrow />
  </Popover.Content>
</Popover.Root>

Component API

Popover.Root

The root component used to manage the state of the state of the popover.

Property Type Description
asChild
boolean

Whether to use render delegation with this component or not.

Default: false
disableFocusTrap
boolean

Whether or not to disable the focus trap that is applied to the popover when it's open.

Default: false
preventScroll
boolean

Whether or not to prevent scrolling the body while the popover is open.

Default: false
positioning
FloatingConfig

The positioning configuration for the popover. (docs coming soon)

Default: { position: "bottom", align: "center" }
closeOnOutsideClick
boolean

Whether or not to close the popover when clicking outside of it.

Default: true
closeOnEscape
boolean

Whether or not to close the popover when pressing the escape key.

Default: true
open
boolean

The open state of the link popover component.

Default: false
onOpenChange
(open: boolean) => void

A callback that fires when the open state changes.

Default:  —— undefined

Popover.Trigger

A component which toggles the opening and closing of the popover on press.

Property Type Description
asChild
boolean

Whether to use render delegation with this component or not.

Default: false
Data Attribute Description/Value
data-state

The open state of the link preview.

Value: 'open' | 'closed'

Popover.Content

The contents of the popover which are displayed when the popover is open.

Property Type Description
asChild
boolean

Whether to use render delegation with this component or not.

Default: false

Popover.Close

A button which closes the popover when pressed and is typically placed in the content.

Property Type Description
asChild
boolean

Whether to use render delegation with this component or not.

Default: false

Popover.Arrow

An optional arrow element which points to the trigger when the popover is open.

Property Type Description
asChild
boolean

Whether to use render delegation with this component or not.

Default: false
size
number

The height and width of the arrow in pixels.

Default: 8
Data Attribute Description/Value
data-arrow

Present on the arrow element.

Value: ''

🚧 UNDER CONSTRUCTION 🚧