coss.com Svelte

Popover

An accessible popup anchored to a button.

API Reference
Loading p-popover-1 preview…

Installation

pnpm dlx shadcn-svelte@latest add https://coss-sv.vercel.app/r/popover.json

Usage

<script lang="ts">
  import * as Popover from "$lib/components/ui/popover/index.js";
</script>

<Popover.Root>
  <Popover.Trigger>Open Popover</Popover.Trigger>
  <Popover.Popup>
    <Popover.Title>Popover Title</Popover.Title>
    <Popover.Description>Popover Description</Popover.Description>
    <Popover.Close>Close</Popover.Close>
  </Popover.Popup>
</Popover.Root>

API Reference

Popover.Root

Root component. Wraps Popover.Root from Shards UI.

Popover.Trigger

Trigger button that opens the popover. Wraps Popover.Trigger from Shards UI.

Popover.Popup

Popup container that displays the popover content. Also exported as Popover.Content.

PropTypeDefaultDescription
tooltipStylebooleanfalseWhen true, applies tooltip-like styling (smaller padding, arrow)
side"top" \| "bottom" \| "left" \| "right""bottom"Side of the trigger to position the popup
align"start" \| "center" \| "end""center"Alignment relative to the trigger
sideOffsetnumber4Distance from the trigger in pixels
alignOffsetnumber0Offset along the alignment axis
portalPropsComponentProps<typeof Popover.PopoverPrimitive.Portal>-Props forwarded to the internal portal (keepMounted, container, etc.); see the Shards UI Popover portal API

Popover.Title

Title text for the popover. Styled wrapper for Popover.Title from Shards UI.

Popover.Description

Description text for the popover. Styled wrapper for Popover.Description from Shards UI.

Popover.Close

Close button for the popover. Wraps Popover.Close from Shards UI.

Popover.PopoverCreateHandle

Creates a handle for detached popover triggers. Returns a handle object to attach to multiple triggers.

Examples

With Close Button

Loading p-popover-2 preview…

Tooltip Style

Use the tooltipStyle prop to make a popover look like a tooltip. This is recommended when you have an info icon button whose only purpose is to show additional information. See the tooltip accessibility guidelines for best practices.

Loading p-input-group-7 preview…

Animated Popovers

You can create animated popovers that smoothly transition between different triggers using detached triggers. This pattern allows multiple triggers to share a single popover popup, with automatic animations for position, size, and content changes.

To create detached triggers:

  1. Create a handle using Popover.PopoverCreateHandle
  2. Attach the same handle to multiple Popover.Trigger components
  3. Each trigger provides a payload prop containing a content snippet
  4. Use a single Popover.Root component with the handle to render the popup
Loading p-popover-3 preview…