Skip to content

Popover

A small panel that opens next to a button, for extra details or a quick form. Same markup and props in every style: switch the style in the header to see it change.

Basic

Text and a link. In HTML it's the browser's popover: button popovertarget opens it, Escape and a click outside close it.

popover-basic.html
<button type="button" class="vin-btn vin-btn--outline" popovertarget="pop-about">About this plan</button>
<div class="vin-popover" id="pop-about" popover role="dialog" aria-labelledby="pop-about-title" data-vin-popover>
  <p class="vin-popover__title" id="pop-about-title">Team plan</p>
  <p class="vin-popover__description">Up to 10 people share one theme and one set of components. <a class="vin-link" href="#">Compare plans</a></p>
</div>

With a form

A few fields that apply at once.

popover-form.html
<button type="button" class="vin-btn vin-btn--outline" popovertarget="pop-size">Dimensions</button>
<div class="vin-popover" id="pop-size" popover role="dialog" aria-labelledby="pop-size-title" data-vin-popover style="width: 260px">
  <p class="vin-popover__title" id="pop-size-title">Dimensions</p>
  <p class="vin-popover__description">Set the size of the layer.</p>
  <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 10px">
    <div class="vin-field">
      <label class="vin-label" for="pop-w">Width</label>
      <input id="pop-w" class="vin-input vin-input--sm" value="1200">
    </div>
    <div class="vin-field">
      <label class="vin-label" for="pop-h">Height</label>
      <input id="pop-h" class="vin-input vin-input--sm" value="800">
    </div>
  </div>
</div>

Share

A link to copy, lined up with the end of the button.

popover-share.html
<button type="button" class="vin-btn" popovertarget="pop-share">Share</button>
<div class="vin-popover" id="pop-share" popover role="dialog" aria-labelledby="pop-share-title" data-vin-popover data-align="end" style="width: 300px">
  <p class="vin-popover__title" id="pop-share-title">Share this page</p>
  <p class="vin-popover__description">Anyone with the link can view it.</p>
  <div class="vin-input vin-input-group">
    <input class="vin-input-group__input" value="https://vinish.dev/ui/s/8f2k" aria-label="Link" readonly>
    <span class="vin-input-group__addon"><button type="button" class="vin-btn vin-btn--ghost vin-btn--sm">Copy</button></span>
  </div>
</div>

Installation

React, Vue and Svelte: add the component to your project with the CLI. It reads your framework from vin.json and also copies any component this one needs. Then import it:

Terminal
npx @vinish/ui add popover
React
import { Popover } from "@/components/vin/popover";
Vue
import Popover from "@/components/vin/popover.vue";
Svelte
import Popover from "$lib/components/vin/popover.svelte";

The import paths assume the default folders: @/components/vin (React and Vue, with the usual @ → src alias) and $lib/components/vin (SvelteKit). Use your own if you chose another folder in init. How the Vue and Svelte versions pass values and content is in Frameworks.

Plain HTML: the classes come with the style's stylesheet. This component also needs vinui.js for its keyboard and pointer behaviour.

API

From spec/popover.json, which every framework version is tested against.

PropValuesDefaultIn HTML
trigger
The button that opens it.
ReactElement—button[popovertarget="id"]
title / descriptionReactNode—.vin-popover__title, .vin-popover__description
open / defaultOpen
Use onOpenChange to hear about changes.
boolean——
sidetoprightbottomleftbottomdata-side on .vin-popover
alignstartcenterendstartdata-align on .vin-popover

Parts

React, Vue, SvelteHTML classes
<Popover>.vin-popover.vin-popover__title.vin-popover__description

Accessibility

  • The panel is a dialog named by its title (aria-labelledby). The trigger says whether it is expanded.
  • Escape closes it, as does a click outside; focus goes back to the trigger.
  • Tab moves from the trigger into the panel, because it sits right after the trigger in the reading order.
  • It isn't modal: the rest of the page still works. Use a Dialog when the user must answer first.