Skip to content

Popover ​

An accessible popup anchored to a button.

vue
<script setup lang="ts">
import { h } from 'vue';
import type { FunctionalComponent } from 'vue';
import { Popover } from '@vase-ui/vue/popover';
import styles from '../../_index.module.css';

const InfoIcon: FunctionalComponent = (_, { attrs }) =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'none',
      stroke: 'currentColor',
      'stroke-linecap': 'square',
      'stroke-linejoin': 'round',
      ...attrs,
      style: { display: 'block' },
    },
    [
      h('circle', { cx: '8', cy: '8', r: '6.5' }),
      h('path', { d: 'M8 7.5v3.5' }),
      h('circle', { cx: '8', cy: '5', r: '0.75', fill: 'currentColor', stroke: 'none' }),
    ],
  );

const XIcon: FunctionalComponent = (_, { attrs }) =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'none',
      stroke: 'currentColor',
      'stroke-linecap': 'square',
      'stroke-linejoin': 'round',
      ...attrs,
      style: { display: 'block' },
    },
    [h('path', { d: 'm4.5 4.5 7 7m-7 0 7-7' })],
  );

const popupHiddenClass = styles.PopupHidden;
</script>

<template>
  <Popover.Root>
    <Popover.Trigger :class="styles.IconButton" aria-label="Shipping information">
      <InfoIcon />
    </Popover.Trigger>
    <Popover.Portal>
      <Popover.Positioner :side-offset="8">
        <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
          <Popover.Popup :class="styles.Popup">
            <Popover.Arrow :class="styles.Arrow" />
            <Popover.Title :class="styles.Title">Free shipping</Popover.Title>
            <Popover.Description :class="styles.Description">
              Orders over $50 arrive in 3–5 business days at no extra cost.
            </Popover.Description>
            <a href="#" :class="styles.Link">View shipping policy</a>
            <Popover.Close aria-label="Close" :class="styles.Close">
              <XIcon />
            </Popover.Close>
          </Popover.Popup>
        </Transition>
      </Popover.Positioner>
    </Popover.Portal>
  </Popover.Root>
</template>
css
.Positioner {
  width: var(--positioner-width);
  height: var(--positioner-height);
  max-width: var(--available-width);
}

.Popup {
  box-sizing: border-box;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.75rem;
  outline: none;
  border: 1px solid oklch(14.5% 0 0deg);
  background-color: white;
  color: oklch(14.5% 0 0deg);
  box-shadow: 0.25rem 0.25rem 0 rgb(0 0 0 / 12%);
  transform-origin: var(--transform-origin);
  transition:
    transform 100ms ease-out,
    opacity 100ms ease-out;
  width: var(--popup-width, auto);
  height: var(--popup-height, auto);
  max-width: 500px;

  @media (prefers-color-scheme: dark) {
    border: 1px solid white;
    background-color: oklch(14.5% 0 0deg);
    color: white;
    box-shadow: none;
  }
}

/* The enter-from and leave-to class of the `<Transition>` around the popup. */
.PopupHidden {
  opacity: 0;
  transform: scale(0.98);
}

.Arrow {
  display: block;
  position: relative;
  width: 12px;
  height: 6px;
  overflow: clip;

  &[data-side='top'] {
    bottom: -6px;
    rotate: 180deg;
  }

  &[data-side='bottom'] {
    top: -6px;
    rotate: 0deg;
  }

  &[data-side='left'] {
    right: -9px;
    rotate: 90deg;
  }

  &[data-side='right'] {
    left: -9px;
    rotate: -90deg;
  }

  &::before {
    content: '';
    display: block;
    position: absolute;
    bottom: 0;
    left: 50%;
    box-sizing: border-box;
    width: calc(6px * sqrt(2));
    height: calc(6px * sqrt(2));
    background-color: white;
    border: 1px solid oklch(14.5% 0 0deg);
    transform: translate(-50%, 50%) rotate(45deg);

    @media (prefers-color-scheme: dark) {
      background-color: oklch(14.5% 0 0deg);
      border: 1px solid white;
    }
  }
}

.Title {
  margin: 0;
  padding-right: 2rem;
  font-size: 0.875rem;
  line-height: 1.25rem;
  font-weight: 700;
}

.Description {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.25rem;
  color: oklch(43.9% 0 0deg);

  @media (prefers-color-scheme: dark) {
    color: oklch(70.8% 0 0deg);
  }
}

.Link {
  align-self: flex-start;
  font-size: 0.875rem;
  line-height: 1.25rem;
  color: oklch(14.5% 0 0deg);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.16em;

  @media (prefers-color-scheme: dark) {
    color: white;
  }

  @media (hover: hover) {
    &:hover {
      text-decoration: none;
    }
  }

  &:focus-visible {
    outline: 2px solid oklch(14.5% 0 0deg);
    outline-offset: 2px;

    @media (prefers-color-scheme: dark) {
      outline-color: white;
    }
  }
}

.Close {
  box-sizing: border-box;
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  margin: 0;
  border: none;
  background: none;
  color: oklch(14.5% 0 0deg);

  @media (prefers-color-scheme: dark) {
    color: white;
  }

  @media (hover: hover) {
    &:hover {
      background-color: oklch(97% 0 0deg);

      @media (prefers-color-scheme: dark) {
        background-color: oklch(26.9% 0 0deg);
      }
    }
  }

  &:active {
    background-color: oklch(92.2% 0 0deg);

    @media (prefers-color-scheme: dark) {
      background-color: oklch(37.1% 0 0deg);
    }
  }

  &:focus-visible {
    outline: 2px solid oklch(14.5% 0 0deg);
    outline-offset: -1px;

    @media (prefers-color-scheme: dark) {
      outline-color: white;
    }
  }
}

.Container {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.Button {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  height: 2rem;
  padding: 0 0.75rem;
  margin: 0;
  border: 1px solid oklch(14.5% 0 0deg);
  background-color: white;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 400;
  line-height: 1;
  white-space: nowrap;
  color: oklch(14.5% 0 0deg);
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    border: 1px solid white;
    background-color: oklch(14.5% 0 0deg);
    color: white;
  }

  @media (hover: hover) {
    &:hover:not(:disabled) {
      background-color: oklch(97% 0 0deg);

      @media (prefers-color-scheme: dark) {
        background-color: oklch(26.9% 0 0deg);
      }
    }
  }

  &:active:not(:disabled) {
    background-color: oklch(92.2% 0 0deg);

    @media (prefers-color-scheme: dark) {
      background-color: oklch(37.1% 0 0deg);
    }
  }

  &[data-pressed]:not(:disabled) {
    background-color: oklch(97% 0 0deg);

    @media (prefers-color-scheme: dark) {
      background-color: oklch(26.9% 0 0deg);
    }
  }

  &:disabled {
    color: oklch(55.6% 0 0deg);
    border-color: oklch(55.6% 0 0deg);

    @media (prefers-color-scheme: dark) {
      color: oklch(70.8% 0 0deg);
      border-color: oklch(70.8% 0 0deg);
    }
  }

  &:focus-visible {
    outline: 2px solid oklch(14.5% 0 0deg);
    outline-offset: -1px;

    @media (prefers-color-scheme: dark) {
      outline-color: white;
    }
  }
}

.IconButton {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  margin: 0;
  outline: 0;
  border: 1px solid oklch(14.5% 0 0deg);
  border-radius: 0;
  background-color: white;
  color: oklch(14.5% 0 0deg);
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    border: 1px solid white;
    background-color: oklch(14.5% 0 0deg);
    color: white;
  }

  @media (hover: hover) {
    &:hover:not(:disabled) {
      background-color: oklch(97% 0 0deg);

      @media (prefers-color-scheme: dark) {
        background-color: oklch(26.9% 0 0deg);
      }
    }
  }

  &:active:not(:disabled) {
    background-color: oklch(92.2% 0 0deg);

    @media (prefers-color-scheme: dark) {
      background-color: oklch(37.1% 0 0deg);
    }
  }

  &[data-pressed] {
    background-color: oklch(97% 0 0deg);

    @media (prefers-color-scheme: dark) {
      background-color: oklch(26.9% 0 0deg);
    }
  }

  &:disabled {
    color: oklch(55.6% 0 0deg);
    border-color: oklch(55.6% 0 0deg);

    @media (prefers-color-scheme: dark) {
      color: oklch(70.8% 0 0deg);
      border-color: oklch(70.8% 0 0deg);
    }
  }

  &:focus-visible {
    outline: 2px solid oklch(14.5% 0 0deg);
    outline-offset: -1px;

    @media (prefers-color-scheme: dark) {
      outline-color: white;
    }
  }
}
vue
<script setup lang="ts">
import { h } from 'vue';
import type { FunctionalComponent } from 'vue';
import { Popover } from '@vase-ui/vue/popover';

const InfoIcon: FunctionalComponent = (_, { attrs }) =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'none',
      stroke: 'currentColor',
      'stroke-linecap': 'square',
      'stroke-linejoin': 'round',
      ...attrs,
      style: { display: 'block' },
    },
    [
      h('circle', { cx: '8', cy: '8', r: '6.5' }),
      h('path', { d: 'M8 7.5v3.5' }),
      h('circle', { cx: '8', cy: '5', r: '0.75', fill: 'currentColor', stroke: 'none' }),
    ],
  );

const XIcon: FunctionalComponent = (_, { attrs }) =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'none',
      stroke: 'currentColor',
      'stroke-linecap': 'square',
      'stroke-linejoin': 'round',
      ...attrs,
      style: { display: 'block' },
    },
    [h('path', { d: 'm4.5 4.5 7 7m-7 0 7-7' })],
  );

const triggerClassName =
  'flex size-8 items-center justify-center rounded-none border border-neutral-950 bg-white text-neutral-950 select-none hover:not-disabled:bg-neutral-100 active:not-disabled:bg-neutral-200 data-pressed:bg-neutral-100 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-disabled:bg-neutral-800 dark:active:not-disabled:bg-neutral-700 disabled:border-neutral-500 disabled:text-neutral-500 dark:data-pressed:bg-neutral-800 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white';

const popupHiddenClass = 'scale-[0.98] opacity-0';
</script>

<template>
  <Popover.Root>
    <Popover.Trigger :class="triggerClassName" aria-label="Shipping information">
      <InfoIcon />
    </Popover.Trigger>
    <Popover.Portal>
      <Popover.Positioner :side-offset="8">
        <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
          <Popover.Popup
            class="relative flex h-[var(--popup-height,auto)] w-[var(--popup-width,auto)] max-w-[500px] flex-col gap-1 origin-[var(--transform-origin)] bg-white dark:bg-neutral-950 p-3 text-neutral-950 dark:text-white outline-none border border-neutral-950 dark:border-white shadow-[0.25rem_0.25rem_0] shadow-black/12 dark:shadow-none transition-[scale,opacity] duration-100 ease-out"
          >
            <Popover.Arrow
              class="relative block w-3 h-1.5 overflow-clip data-[side=bottom]:top-[-6px] data-[side=left]:right-[-9px] data-[side=left]:rotate-90 data-[side=right]:left-[-9px] data-[side=right]:-rotate-90 data-[side=top]:bottom-[-6px] data-[side=top]:rotate-180 before:content-[''] before:absolute before:bottom-0 before:left-1/2 before:w-[calc(6px*sqrt(2))] before:h-[calc(6px*sqrt(2))] before:bg-white dark:before:bg-neutral-950 before:border before:border-neutral-950 dark:before:border-white before:[transform:translate(-50%,50%)_rotate(45deg)]"
            />
            <Popover.Title class="pr-8 text-sm font-bold">Free shipping</Popover.Title>
            <Popover.Description class="text-sm text-neutral-600 dark:text-neutral-400">
              Orders over $50 arrive in 3–5 business days at no extra cost.
            </Popover.Description>
            <a
              href="#"
              class="self-start text-sm text-neutral-950 dark:text-white underline underline-offset-[0.16em] decoration-[1px] hover:no-underline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
              >View shipping policy</a
            >
            <Popover.Close
              aria-label="Close"
              class="absolute top-2 right-2 flex size-7 items-center justify-center border-0 bg-transparent p-0 text-neutral-950 dark:text-white hover:bg-neutral-100 dark:hover:bg-neutral-800 active:bg-neutral-200 dark:active:bg-neutral-700 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
            >
              <XIcon />
            </Popover.Close>
          </Popover.Popup>
        </Transition>
      </Popover.Positioner>
    </Popover.Portal>
  </Popover.Root>
</template>

Anatomy ​

Import the component and assemble its parts:

vue
<script setup lang="ts">
import { Popover } from '@vase-ui/vue/popover';
</script>

<template>
  <Popover.Root>
    <Popover.Trigger />
    <Popover.Portal>
      <Popover.Backdrop />
      <Popover.Positioner>
        <Popover.Popup>
          <Popover.Arrow />
          <Popover.Viewport>
            <Popover.Title />
            <Popover.Description />
            <Popover.Close />
          </Popover.Viewport>
        </Popover.Popup>
      </Popover.Positioner>
    </Popover.Portal>
  </Popover.Root>
</template>

Examples ​

Opening on hover ​

To open the popover when the mouse rests on the trigger, set openOnHover on Popover.Trigger. The delay prop gives the time in milliseconds before the open.

vue
<script setup lang="ts">
import { h } from 'vue';
import type { FunctionalComponent } from 'vue';
import { Popover } from '@vase-ui/vue/popover';
import styles from '../../_index.module.css';

const InfoIcon: FunctionalComponent = (_, { attrs }) =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'none',
      stroke: 'currentColor',
      'stroke-linecap': 'square',
      'stroke-linejoin': 'round',
      ...attrs,
      style: { display: 'block' },
    },
    [
      h('circle', { cx: '8', cy: '8', r: '6.5' }),
      h('path', { d: 'M8 7.5v3.5' }),
      h('circle', { cx: '8', cy: '5', r: '0.75', fill: 'currentColor', stroke: 'none' }),
    ],
  );

const XIcon: FunctionalComponent = (_, { attrs }) =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'none',
      stroke: 'currentColor',
      'stroke-linecap': 'square',
      'stroke-linejoin': 'round',
      ...attrs,
      style: { display: 'block' },
    },
    [h('path', { d: 'm4.5 4.5 7 7m-7 0 7-7' })],
  );

const popupHiddenClass = styles.PopupHidden;
</script>

<template>
  <Popover.Root>
    <Popover.Trigger open-on-hover :class="styles.IconButton" aria-label="Shipping information">
      <InfoIcon />
    </Popover.Trigger>
    <Popover.Portal>
      <Popover.Positioner :side-offset="8">
        <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
          <Popover.Popup :class="styles.Popup">
            <Popover.Arrow :class="styles.Arrow" />
            <Popover.Title :class="styles.Title">Free shipping</Popover.Title>
            <Popover.Description :class="styles.Description">
              Orders over $50 arrive in 3–5 business days at no extra cost.
            </Popover.Description>
            <a href="#" :class="styles.Link">View shipping policy</a>
            <Popover.Close aria-label="Close" :class="styles.Close">
              <XIcon />
            </Popover.Close>
          </Popover.Popup>
        </Transition>
      </Popover.Positioner>
    </Popover.Portal>
  </Popover.Root>
</template>
css
.Positioner {
  width: var(--positioner-width);
  height: var(--positioner-height);
  max-width: var(--available-width);
}

.Popup {
  box-sizing: border-box;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.75rem;
  outline: none;
  border: 1px solid oklch(14.5% 0 0deg);
  background-color: white;
  color: oklch(14.5% 0 0deg);
  box-shadow: 0.25rem 0.25rem 0 rgb(0 0 0 / 12%);
  transform-origin: var(--transform-origin);
  transition:
    transform 100ms ease-out,
    opacity 100ms ease-out;
  width: var(--popup-width, auto);
  height: var(--popup-height, auto);
  max-width: 500px;

  @media (prefers-color-scheme: dark) {
    border: 1px solid white;
    background-color: oklch(14.5% 0 0deg);
    color: white;
    box-shadow: none;
  }
}

/* The enter-from and leave-to class of the `<Transition>` around the popup. */
.PopupHidden {
  opacity: 0;
  transform: scale(0.98);
}

.Arrow {
  display: block;
  position: relative;
  width: 12px;
  height: 6px;
  overflow: clip;

  &[data-side='top'] {
    bottom: -6px;
    rotate: 180deg;
  }

  &[data-side='bottom'] {
    top: -6px;
    rotate: 0deg;
  }

  &[data-side='left'] {
    right: -9px;
    rotate: 90deg;
  }

  &[data-side='right'] {
    left: -9px;
    rotate: -90deg;
  }

  &::before {
    content: '';
    display: block;
    position: absolute;
    bottom: 0;
    left: 50%;
    box-sizing: border-box;
    width: calc(6px * sqrt(2));
    height: calc(6px * sqrt(2));
    background-color: white;
    border: 1px solid oklch(14.5% 0 0deg);
    transform: translate(-50%, 50%) rotate(45deg);

    @media (prefers-color-scheme: dark) {
      background-color: oklch(14.5% 0 0deg);
      border: 1px solid white;
    }
  }
}

.Title {
  margin: 0;
  padding-right: 2rem;
  font-size: 0.875rem;
  line-height: 1.25rem;
  font-weight: 700;
}

.Description {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.25rem;
  color: oklch(43.9% 0 0deg);

  @media (prefers-color-scheme: dark) {
    color: oklch(70.8% 0 0deg);
  }
}

.Link {
  align-self: flex-start;
  font-size: 0.875rem;
  line-height: 1.25rem;
  color: oklch(14.5% 0 0deg);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.16em;

  @media (prefers-color-scheme: dark) {
    color: white;
  }

  @media (hover: hover) {
    &:hover {
      text-decoration: none;
    }
  }

  &:focus-visible {
    outline: 2px solid oklch(14.5% 0 0deg);
    outline-offset: 2px;

    @media (prefers-color-scheme: dark) {
      outline-color: white;
    }
  }
}

.Close {
  box-sizing: border-box;
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  margin: 0;
  border: none;
  background: none;
  color: oklch(14.5% 0 0deg);

  @media (prefers-color-scheme: dark) {
    color: white;
  }

  @media (hover: hover) {
    &:hover {
      background-color: oklch(97% 0 0deg);

      @media (prefers-color-scheme: dark) {
        background-color: oklch(26.9% 0 0deg);
      }
    }
  }

  &:active {
    background-color: oklch(92.2% 0 0deg);

    @media (prefers-color-scheme: dark) {
      background-color: oklch(37.1% 0 0deg);
    }
  }

  &:focus-visible {
    outline: 2px solid oklch(14.5% 0 0deg);
    outline-offset: -1px;

    @media (prefers-color-scheme: dark) {
      outline-color: white;
    }
  }
}

.Container {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.Button {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  height: 2rem;
  padding: 0 0.75rem;
  margin: 0;
  border: 1px solid oklch(14.5% 0 0deg);
  background-color: white;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 400;
  line-height: 1;
  white-space: nowrap;
  color: oklch(14.5% 0 0deg);
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    border: 1px solid white;
    background-color: oklch(14.5% 0 0deg);
    color: white;
  }

  @media (hover: hover) {
    &:hover:not(:disabled) {
      background-color: oklch(97% 0 0deg);

      @media (prefers-color-scheme: dark) {
        background-color: oklch(26.9% 0 0deg);
      }
    }
  }

  &:active:not(:disabled) {
    background-color: oklch(92.2% 0 0deg);

    @media (prefers-color-scheme: dark) {
      background-color: oklch(37.1% 0 0deg);
    }
  }

  &[data-pressed]:not(:disabled) {
    background-color: oklch(97% 0 0deg);

    @media (prefers-color-scheme: dark) {
      background-color: oklch(26.9% 0 0deg);
    }
  }

  &:disabled {
    color: oklch(55.6% 0 0deg);
    border-color: oklch(55.6% 0 0deg);

    @media (prefers-color-scheme: dark) {
      color: oklch(70.8% 0 0deg);
      border-color: oklch(70.8% 0 0deg);
    }
  }

  &:focus-visible {
    outline: 2px solid oklch(14.5% 0 0deg);
    outline-offset: -1px;

    @media (prefers-color-scheme: dark) {
      outline-color: white;
    }
  }
}

.IconButton {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  margin: 0;
  outline: 0;
  border: 1px solid oklch(14.5% 0 0deg);
  border-radius: 0;
  background-color: white;
  color: oklch(14.5% 0 0deg);
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    border: 1px solid white;
    background-color: oklch(14.5% 0 0deg);
    color: white;
  }

  @media (hover: hover) {
    &:hover:not(:disabled) {
      background-color: oklch(97% 0 0deg);

      @media (prefers-color-scheme: dark) {
        background-color: oklch(26.9% 0 0deg);
      }
    }
  }

  &:active:not(:disabled) {
    background-color: oklch(92.2% 0 0deg);

    @media (prefers-color-scheme: dark) {
      background-color: oklch(37.1% 0 0deg);
    }
  }

  &[data-pressed] {
    background-color: oklch(97% 0 0deg);

    @media (prefers-color-scheme: dark) {
      background-color: oklch(26.9% 0 0deg);
    }
  }

  &:disabled {
    color: oklch(55.6% 0 0deg);
    border-color: oklch(55.6% 0 0deg);

    @media (prefers-color-scheme: dark) {
      color: oklch(70.8% 0 0deg);
      border-color: oklch(70.8% 0 0deg);
    }
  }

  &:focus-visible {
    outline: 2px solid oklch(14.5% 0 0deg);
    outline-offset: -1px;

    @media (prefers-color-scheme: dark) {
      outline-color: white;
    }
  }
}
vue
<script setup lang="ts">
import { h } from 'vue';
import type { FunctionalComponent } from 'vue';
import { Popover } from '@vase-ui/vue/popover';

const InfoIcon: FunctionalComponent = (_, { attrs }) =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'none',
      stroke: 'currentColor',
      'stroke-linecap': 'square',
      'stroke-linejoin': 'round',
      ...attrs,
      style: { display: 'block' },
    },
    [
      h('circle', { cx: '8', cy: '8', r: '6.5' }),
      h('path', { d: 'M8 7.5v3.5' }),
      h('circle', { cx: '8', cy: '5', r: '0.75', fill: 'currentColor', stroke: 'none' }),
    ],
  );

const XIcon: FunctionalComponent = (_, { attrs }) =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'none',
      stroke: 'currentColor',
      'stroke-linecap': 'square',
      'stroke-linejoin': 'round',
      ...attrs,
      style: { display: 'block' },
    },
    [h('path', { d: 'm4.5 4.5 7 7m-7 0 7-7' })],
  );

const triggerClassName =
  'flex size-8 items-center justify-center rounded-none border border-neutral-950 bg-white text-neutral-950 select-none hover:not-disabled:bg-neutral-100 active:not-disabled:bg-neutral-200 data-pressed:bg-neutral-100 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-disabled:bg-neutral-800 dark:active:not-disabled:bg-neutral-700 disabled:border-neutral-500 disabled:text-neutral-500 dark:data-pressed:bg-neutral-800 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white';

const popupHiddenClass = 'scale-[0.98] opacity-0';
</script>

<template>
  <Popover.Root>
    <Popover.Trigger open-on-hover :class="triggerClassName" aria-label="Shipping information">
      <InfoIcon />
    </Popover.Trigger>
    <Popover.Portal>
      <Popover.Positioner :side-offset="8">
        <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
          <Popover.Popup
            class="relative flex h-[var(--popup-height,auto)] w-[var(--popup-width,auto)] max-w-[500px] flex-col gap-1 origin-[var(--transform-origin)] bg-white dark:bg-neutral-950 p-3 text-neutral-950 dark:text-white outline-none border border-neutral-950 dark:border-white shadow-[0.25rem_0.25rem_0] shadow-black/12 dark:shadow-none transition-[scale,opacity] duration-100 ease-out"
          >
            <Popover.Arrow
              class="relative block w-3 h-1.5 overflow-clip data-[side=bottom]:top-[-6px] data-[side=left]:right-[-9px] data-[side=left]:rotate-90 data-[side=right]:left-[-9px] data-[side=right]:-rotate-90 data-[side=top]:bottom-[-6px] data-[side=top]:rotate-180 before:content-[''] before:absolute before:bottom-0 before:left-1/2 before:w-[calc(6px*sqrt(2))] before:h-[calc(6px*sqrt(2))] before:bg-white dark:before:bg-neutral-950 before:border before:border-neutral-950 dark:before:border-white before:[transform:translate(-50%,50%)_rotate(45deg)]"
            />
            <Popover.Title class="pr-8 text-sm font-bold">Free shipping</Popover.Title>
            <Popover.Description class="text-sm text-neutral-600 dark:text-neutral-400">
              Orders over $50 arrive in 3–5 business days at no extra cost.
            </Popover.Description>
            <a
              href="#"
              class="self-start text-sm text-neutral-950 dark:text-white underline underline-offset-[0.16em] decoration-[1px] hover:no-underline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
              >View shipping policy</a
            >
            <Popover.Close
              aria-label="Close"
              class="absolute top-2 right-2 flex size-7 items-center justify-center border-0 bg-transparent p-0 text-neutral-950 dark:text-white hover:bg-neutral-100 dark:hover:bg-neutral-800 active:bg-neutral-200 dark:active:bg-neutral-700 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
            >
              <XIcon />
            </Popover.Close>
          </Popover.Popup>
        </Transition>
      </Popover.Positioner>
    </Popover.Portal>
  </Popover.Root>
</template>

Detached triggers ​

A trigger can be inside or outside Popover.Root. For a simple popover, put Popover.Trigger inside Popover.Root, as the demo at the top of this page does.

When the content of the popover cannot be next to its trigger, use a detached trigger. Put Popover.Trigger outside Popover.Root, and connect the two with a handle from Popover.createHandle().

The methods open() and close() of the handle need a mounted Popover.Root with the same handle. The handle ignores a call while no root uses it: before a root mounts, and after it unmounts. Each root starts with a new state at its mount. It does not replay an earlier call, and it does not keep the open state of an earlier root.

vue
<script setup lang="ts">
import { Popover } from '@vase-ui/vue/popover';

const demoPopover = Popover.createHandle();
</script>

<template>
  <Popover.Trigger :handle="demoPopover">Trigger</Popover.Trigger>

  <Popover.Root :handle="demoPopover">
    <Popover.Portal>
      <Popover.Positioner>
        <Popover.Popup>Popover</Popover.Popup>
      </Popover.Positioner>
    </Popover.Portal>
  </Popover.Root>
</template>
vue
<script setup lang="ts">
import { h } from 'vue';
import type { FunctionalComponent } from 'vue';
import { Popover } from '@vase-ui/vue/popover';
import styles from '../../_index.module.css';

const demoPopover = Popover.createHandle();

const InfoIcon: FunctionalComponent = (_, { attrs }) =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'none',
      stroke: 'currentColor',
      'stroke-linecap': 'square',
      'stroke-linejoin': 'round',
      ...attrs,
      style: { display: 'block' },
    },
    [
      h('circle', { cx: '8', cy: '8', r: '6.5' }),
      h('path', { d: 'M8 7.5v3.5' }),
      h('circle', { cx: '8', cy: '5', r: '0.75', fill: 'currentColor', stroke: 'none' }),
    ],
  );

const XIcon: FunctionalComponent = (_, { attrs }) =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'none',
      stroke: 'currentColor',
      'stroke-linecap': 'square',
      'stroke-linejoin': 'round',
      ...attrs,
      style: { display: 'block' },
    },
    [h('path', { d: 'm4.5 4.5 7 7m-7 0 7-7' })],
  );

const popupHiddenClass = styles.PopupHidden;
</script>

<template>
  <Popover.Trigger
    :class="styles.IconButton"
    :handle="demoPopover"
    aria-label="Shipping information"
  >
    <InfoIcon />
  </Popover.Trigger>

  <Popover.Root :handle="demoPopover">
    <Popover.Portal>
      <Popover.Positioner :side-offset="8">
        <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
          <Popover.Popup :class="styles.Popup">
            <Popover.Arrow :class="styles.Arrow" />
            <Popover.Title :class="styles.Title">Free shipping</Popover.Title>
            <Popover.Description :class="styles.Description">
              Orders over $50 arrive in 3–5 business days at no extra cost.
            </Popover.Description>
            <a href="#" :class="styles.Link">View shipping policy</a>
            <Popover.Close aria-label="Close" :class="styles.Close">
              <XIcon />
            </Popover.Close>
          </Popover.Popup>
        </Transition>
      </Popover.Positioner>
    </Popover.Portal>
  </Popover.Root>
</template>
css
.Positioner {
  width: var(--positioner-width);
  height: var(--positioner-height);
  max-width: var(--available-width);
}

.Popup {
  box-sizing: border-box;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.75rem;
  outline: none;
  border: 1px solid oklch(14.5% 0 0deg);
  background-color: white;
  color: oklch(14.5% 0 0deg);
  box-shadow: 0.25rem 0.25rem 0 rgb(0 0 0 / 12%);
  transform-origin: var(--transform-origin);
  transition:
    transform 100ms ease-out,
    opacity 100ms ease-out;
  width: var(--popup-width, auto);
  height: var(--popup-height, auto);
  max-width: 500px;

  @media (prefers-color-scheme: dark) {
    border: 1px solid white;
    background-color: oklch(14.5% 0 0deg);
    color: white;
    box-shadow: none;
  }
}

/* The enter-from and leave-to class of the `<Transition>` around the popup. */
.PopupHidden {
  opacity: 0;
  transform: scale(0.98);
}

.Arrow {
  display: block;
  position: relative;
  width: 12px;
  height: 6px;
  overflow: clip;

  &[data-side='top'] {
    bottom: -6px;
    rotate: 180deg;
  }

  &[data-side='bottom'] {
    top: -6px;
    rotate: 0deg;
  }

  &[data-side='left'] {
    right: -9px;
    rotate: 90deg;
  }

  &[data-side='right'] {
    left: -9px;
    rotate: -90deg;
  }

  &::before {
    content: '';
    display: block;
    position: absolute;
    bottom: 0;
    left: 50%;
    box-sizing: border-box;
    width: calc(6px * sqrt(2));
    height: calc(6px * sqrt(2));
    background-color: white;
    border: 1px solid oklch(14.5% 0 0deg);
    transform: translate(-50%, 50%) rotate(45deg);

    @media (prefers-color-scheme: dark) {
      background-color: oklch(14.5% 0 0deg);
      border: 1px solid white;
    }
  }
}

.Title {
  margin: 0;
  padding-right: 2rem;
  font-size: 0.875rem;
  line-height: 1.25rem;
  font-weight: 700;
}

.Description {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.25rem;
  color: oklch(43.9% 0 0deg);

  @media (prefers-color-scheme: dark) {
    color: oklch(70.8% 0 0deg);
  }
}

.Link {
  align-self: flex-start;
  font-size: 0.875rem;
  line-height: 1.25rem;
  color: oklch(14.5% 0 0deg);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.16em;

  @media (prefers-color-scheme: dark) {
    color: white;
  }

  @media (hover: hover) {
    &:hover {
      text-decoration: none;
    }
  }

  &:focus-visible {
    outline: 2px solid oklch(14.5% 0 0deg);
    outline-offset: 2px;

    @media (prefers-color-scheme: dark) {
      outline-color: white;
    }
  }
}

.Close {
  box-sizing: border-box;
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  margin: 0;
  border: none;
  background: none;
  color: oklch(14.5% 0 0deg);

  @media (prefers-color-scheme: dark) {
    color: white;
  }

  @media (hover: hover) {
    &:hover {
      background-color: oklch(97% 0 0deg);

      @media (prefers-color-scheme: dark) {
        background-color: oklch(26.9% 0 0deg);
      }
    }
  }

  &:active {
    background-color: oklch(92.2% 0 0deg);

    @media (prefers-color-scheme: dark) {
      background-color: oklch(37.1% 0 0deg);
    }
  }

  &:focus-visible {
    outline: 2px solid oklch(14.5% 0 0deg);
    outline-offset: -1px;

    @media (prefers-color-scheme: dark) {
      outline-color: white;
    }
  }
}

.Container {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.Button {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  height: 2rem;
  padding: 0 0.75rem;
  margin: 0;
  border: 1px solid oklch(14.5% 0 0deg);
  background-color: white;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 400;
  line-height: 1;
  white-space: nowrap;
  color: oklch(14.5% 0 0deg);
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    border: 1px solid white;
    background-color: oklch(14.5% 0 0deg);
    color: white;
  }

  @media (hover: hover) {
    &:hover:not(:disabled) {
      background-color: oklch(97% 0 0deg);

      @media (prefers-color-scheme: dark) {
        background-color: oklch(26.9% 0 0deg);
      }
    }
  }

  &:active:not(:disabled) {
    background-color: oklch(92.2% 0 0deg);

    @media (prefers-color-scheme: dark) {
      background-color: oklch(37.1% 0 0deg);
    }
  }

  &[data-pressed]:not(:disabled) {
    background-color: oklch(97% 0 0deg);

    @media (prefers-color-scheme: dark) {
      background-color: oklch(26.9% 0 0deg);
    }
  }

  &:disabled {
    color: oklch(55.6% 0 0deg);
    border-color: oklch(55.6% 0 0deg);

    @media (prefers-color-scheme: dark) {
      color: oklch(70.8% 0 0deg);
      border-color: oklch(70.8% 0 0deg);
    }
  }

  &:focus-visible {
    outline: 2px solid oklch(14.5% 0 0deg);
    outline-offset: -1px;

    @media (prefers-color-scheme: dark) {
      outline-color: white;
    }
  }
}

.IconButton {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  margin: 0;
  outline: 0;
  border: 1px solid oklch(14.5% 0 0deg);
  border-radius: 0;
  background-color: white;
  color: oklch(14.5% 0 0deg);
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    border: 1px solid white;
    background-color: oklch(14.5% 0 0deg);
    color: white;
  }

  @media (hover: hover) {
    &:hover:not(:disabled) {
      background-color: oklch(97% 0 0deg);

      @media (prefers-color-scheme: dark) {
        background-color: oklch(26.9% 0 0deg);
      }
    }
  }

  &:active:not(:disabled) {
    background-color: oklch(92.2% 0 0deg);

    @media (prefers-color-scheme: dark) {
      background-color: oklch(37.1% 0 0deg);
    }
  }

  &[data-pressed] {
    background-color: oklch(97% 0 0deg);

    @media (prefers-color-scheme: dark) {
      background-color: oklch(26.9% 0 0deg);
    }
  }

  &:disabled {
    color: oklch(55.6% 0 0deg);
    border-color: oklch(55.6% 0 0deg);

    @media (prefers-color-scheme: dark) {
      color: oklch(70.8% 0 0deg);
      border-color: oklch(70.8% 0 0deg);
    }
  }

  &:focus-visible {
    outline: 2px solid oklch(14.5% 0 0deg);
    outline-offset: -1px;

    @media (prefers-color-scheme: dark) {
      outline-color: white;
    }
  }
}
vue
<script setup lang="ts">
import { h } from 'vue';
import type { FunctionalComponent } from 'vue';
import { Popover } from '@vase-ui/vue/popover';

const demoPopover = Popover.createHandle();

const InfoIcon: FunctionalComponent = (_, { attrs }) =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'none',
      stroke: 'currentColor',
      'stroke-linecap': 'square',
      'stroke-linejoin': 'round',
      ...attrs,
      style: { display: 'block' },
    },
    [
      h('circle', { cx: '8', cy: '8', r: '6.5' }),
      h('path', { d: 'M8 7.5v3.5' }),
      h('circle', { cx: '8', cy: '5', r: '0.75', fill: 'currentColor', stroke: 'none' }),
    ],
  );

const XIcon: FunctionalComponent = (_, { attrs }) =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'none',
      stroke: 'currentColor',
      'stroke-linecap': 'square',
      'stroke-linejoin': 'round',
      ...attrs,
      style: { display: 'block' },
    },
    [h('path', { d: 'm4.5 4.5 7 7m-7 0 7-7' })],
  );

const triggerClassName =
  'flex size-8 items-center justify-center rounded-none border border-neutral-950 bg-white text-neutral-950 select-none hover:not-disabled:bg-neutral-100 active:not-disabled:bg-neutral-200 data-pressed:bg-neutral-100 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-disabled:bg-neutral-800 dark:active:not-disabled:bg-neutral-700 disabled:border-neutral-500 disabled:text-neutral-500 dark:data-pressed:bg-neutral-800 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white';

const popupHiddenClass = 'scale-[0.98] opacity-0';
</script>

<template>
  <Popover.Trigger
    :class="triggerClassName"
    :handle="demoPopover"
    aria-label="Shipping information"
  >
    <InfoIcon />
  </Popover.Trigger>

  <Popover.Root :handle="demoPopover">
    <Popover.Portal>
      <Popover.Positioner :side-offset="8">
        <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
          <Popover.Popup
            class="relative flex h-[var(--popup-height,auto)] w-[var(--popup-width,auto)] max-w-[500px] flex-col gap-1 origin-[var(--transform-origin)] bg-white dark:bg-neutral-950 p-3 text-neutral-950 dark:text-white outline-none border border-neutral-950 dark:border-white shadow-[0.25rem_0.25rem_0] shadow-black/12 dark:shadow-none transition-[scale,opacity] duration-100 ease-out"
          >
            <Popover.Arrow
              class="relative block w-3 h-1.5 overflow-clip data-[side=bottom]:top-[-6px] data-[side=left]:right-[-9px] data-[side=left]:rotate-90 data-[side=right]:left-[-9px] data-[side=right]:-rotate-90 data-[side=top]:bottom-[-6px] data-[side=top]:rotate-180 before:content-[''] before:absolute before:bottom-0 before:left-1/2 before:w-[calc(6px*sqrt(2))] before:h-[calc(6px*sqrt(2))] before:bg-white dark:before:bg-neutral-950 before:border before:border-neutral-950 dark:before:border-white before:[transform:translate(-50%,50%)_rotate(45deg)]"
            />
            <Popover.Title class="pr-8 text-sm font-bold">Free shipping</Popover.Title>
            <Popover.Description class="text-sm text-neutral-600 dark:text-neutral-400">
              Orders over $50 arrive in 3–5 business days at no extra cost.
            </Popover.Description>
            <a
              href="#"
              class="self-start text-sm text-neutral-950 dark:text-white underline underline-offset-[0.16em] decoration-[1px] hover:no-underline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
              >View shipping policy</a
            >
            <Popover.Close
              aria-label="Close"
              class="absolute top-2 right-2 flex size-7 items-center justify-center border-0 bg-transparent p-0 text-neutral-950 dark:text-white hover:bg-neutral-100 dark:hover:bg-neutral-800 active:bg-neutral-200 dark:active:bg-neutral-700 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
            >
              <XIcon />
            </Popover.Close>
          </Popover.Popup>
        </Transition>
      </Popover.Positioner>
    </Popover.Portal>
  </Popover.Root>
</template>

Multiple triggers ​

One popover can have more than one trigger. Give the same handle to more than one detached trigger, or put more than one Popover.Trigger in one Popover.Root.

vue
<script setup lang="ts">
import { Popover } from '@vase-ui/vue/popover';
</script>

<template>
  <Popover.Root>
    <Popover.Trigger>Trigger 1</Popover.Trigger>
    <Popover.Trigger>Trigger 2</Popover.Trigger>
    <Popover.Portal>
      <Popover.Positioner>
        <Popover.Popup>Popover</Popover.Popup>
      </Popover.Positioner>
    </Popover.Portal>
  </Popover.Root>
</template>
vue
<script setup lang="ts">
import { Popover } from '@vase-ui/vue/popover';

const demoPopover = Popover.createHandle();
</script>

<template>
  <Popover.Trigger :handle="demoPopover">Trigger 1</Popover.Trigger>

  <Popover.Trigger :handle="demoPopover">Trigger 2</Popover.Trigger>

  <Popover.Root :handle="demoPopover">
    <Popover.Portal>
      <Popover.Positioner>
        <Popover.Popup>Popover</Popover.Popup>
      </Popover.Positioner>
    </Popover.Portal>
  </Popover.Root>
</template>

The popover can show different content for each trigger. Give a payload to each Popover.Trigger. The default slot of Popover.Root gets the payload of the active trigger. The type argument of createHandle() gives the payload its type:

vue
<script setup lang="ts">
import { Popover } from '@vase-ui/vue/popover';

const demoPopover = Popover.createHandle<{ text: string }>();
</script>

<template>
  <Popover.Trigger :handle="demoPopover" :payload="{ text: 'Trigger 1' }">
    Trigger 1
  </Popover.Trigger>

  <Popover.Trigger :handle="demoPopover" :payload="{ text: 'Trigger 2' }">
    Trigger 2
  </Popover.Trigger>

  <Popover.Root v-slot="{ payload }" :handle="demoPopover">
    <Popover.Portal>
      <Popover.Positioner :side-offset="8">
        <Popover.Popup>
          <Popover.Arrow />
          <Popover.Title>Popover</Popover.Title>
          <Popover.Description v-if="payload !== undefined">
            Opened by {{ payload.text }}
          </Popover.Description>
        </Popover.Popup>
      </Popover.Positioner>
    </Popover.Portal>
  </Popover.Root>
</template>

Controlled mode with multiple triggers ​

To control the open state, use v-model:open on Popover.Root, or the open prop and the openChange event. With more than one trigger, control the active trigger with v-model:trigger-id on Popover.Root and the id prop of each Popover.Trigger.

The second argument of openChange has trigger, the element of the trigger that started the change.

vue
<script setup lang="ts">
import { h, shallowRef } from 'vue';
import type { FunctionalComponent } from 'vue';
import { Popover } from '@vase-ui/vue/popover';
import styles from '../../_index.module.css';

const demoPopover = Popover.createHandle();

const open = shallowRef(false);
const triggerId = shallowRef<string | null>(null);

function handleOpenChange(isOpen: boolean, eventDetails: Popover.Root.ChangeEventDetails) {
  open.value = isOpen;
  triggerId.value = eventDetails.trigger?.id ?? null;
}

function openProgrammatically() {
  triggerId.value = 'trigger-2';
  open.value = true;
}

const XIcon: FunctionalComponent = (_, { attrs }) =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'none',
      stroke: 'currentColor',
      'stroke-linecap': 'square',
      'stroke-linejoin': 'round',
      ...attrs,
      style: { display: 'block' },
    },
    [h('path', { d: 'm4.5 4.5 7 7m-7 0 7-7' })],
  );

const popupHiddenClass = styles.PopupHidden;
</script>

<template>
  <div :class="styles.Container">
    <Popover.Trigger :class="styles.Button" :handle="demoPopover" id="trigger-1">
      Trigger 1
    </Popover.Trigger>

    <Popover.Trigger :class="styles.Button" :handle="demoPopover" id="trigger-2">
      Trigger 2
    </Popover.Trigger>

    <Popover.Trigger :class="styles.Button" :handle="demoPopover" id="trigger-3">
      Trigger 3
    </Popover.Trigger>

    <button type="button" :class="styles.Button" @click="openProgrammatically">
      Open programmatically
    </button>
  </div>

  <Popover.Root
    :handle="demoPopover"
    :open="open"
    :trigger-id="triggerId"
    @open-change="handleOpenChange"
  >
    <Popover.Portal>
      <Popover.Positioner :class="styles.Positioner" :side-offset="8">
        <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
          <Popover.Popup :class="styles.Popup">
            <Popover.Arrow :class="styles.Arrow" />
            <Popover.Title :class="styles.Title">Free shipping</Popover.Title>
            <Popover.Description :class="styles.Description">
              Orders over $50 arrive in 3–5 business days at no extra cost.
            </Popover.Description>
            <a href="#" :class="styles.Link">View shipping policy</a>
            <Popover.Close aria-label="Close" :class="styles.Close">
              <XIcon />
            </Popover.Close>
          </Popover.Popup>
        </Transition>
      </Popover.Positioner>
    </Popover.Portal>
  </Popover.Root>
</template>
css
.Positioner {
  width: var(--positioner-width);
  height: var(--positioner-height);
  max-width: var(--available-width);
}

.Popup {
  box-sizing: border-box;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.75rem;
  outline: none;
  border: 1px solid oklch(14.5% 0 0deg);
  background-color: white;
  color: oklch(14.5% 0 0deg);
  box-shadow: 0.25rem 0.25rem 0 rgb(0 0 0 / 12%);
  transform-origin: var(--transform-origin);
  transition:
    transform 100ms ease-out,
    opacity 100ms ease-out;
  width: var(--popup-width, auto);
  height: var(--popup-height, auto);
  max-width: 500px;

  @media (prefers-color-scheme: dark) {
    border: 1px solid white;
    background-color: oklch(14.5% 0 0deg);
    color: white;
    box-shadow: none;
  }
}

/* The enter-from and leave-to class of the `<Transition>` around the popup. */
.PopupHidden {
  opacity: 0;
  transform: scale(0.98);
}

.Arrow {
  display: block;
  position: relative;
  width: 12px;
  height: 6px;
  overflow: clip;

  &[data-side='top'] {
    bottom: -6px;
    rotate: 180deg;
  }

  &[data-side='bottom'] {
    top: -6px;
    rotate: 0deg;
  }

  &[data-side='left'] {
    right: -9px;
    rotate: 90deg;
  }

  &[data-side='right'] {
    left: -9px;
    rotate: -90deg;
  }

  &::before {
    content: '';
    display: block;
    position: absolute;
    bottom: 0;
    left: 50%;
    box-sizing: border-box;
    width: calc(6px * sqrt(2));
    height: calc(6px * sqrt(2));
    background-color: white;
    border: 1px solid oklch(14.5% 0 0deg);
    transform: translate(-50%, 50%) rotate(45deg);

    @media (prefers-color-scheme: dark) {
      background-color: oklch(14.5% 0 0deg);
      border: 1px solid white;
    }
  }
}

.Title {
  margin: 0;
  padding-right: 2rem;
  font-size: 0.875rem;
  line-height: 1.25rem;
  font-weight: 700;
}

.Description {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.25rem;
  color: oklch(43.9% 0 0deg);

  @media (prefers-color-scheme: dark) {
    color: oklch(70.8% 0 0deg);
  }
}

.Link {
  align-self: flex-start;
  font-size: 0.875rem;
  line-height: 1.25rem;
  color: oklch(14.5% 0 0deg);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.16em;

  @media (prefers-color-scheme: dark) {
    color: white;
  }

  @media (hover: hover) {
    &:hover {
      text-decoration: none;
    }
  }

  &:focus-visible {
    outline: 2px solid oklch(14.5% 0 0deg);
    outline-offset: 2px;

    @media (prefers-color-scheme: dark) {
      outline-color: white;
    }
  }
}

.Close {
  box-sizing: border-box;
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  margin: 0;
  border: none;
  background: none;
  color: oklch(14.5% 0 0deg);

  @media (prefers-color-scheme: dark) {
    color: white;
  }

  @media (hover: hover) {
    &:hover {
      background-color: oklch(97% 0 0deg);

      @media (prefers-color-scheme: dark) {
        background-color: oklch(26.9% 0 0deg);
      }
    }
  }

  &:active {
    background-color: oklch(92.2% 0 0deg);

    @media (prefers-color-scheme: dark) {
      background-color: oklch(37.1% 0 0deg);
    }
  }

  &:focus-visible {
    outline: 2px solid oklch(14.5% 0 0deg);
    outline-offset: -1px;

    @media (prefers-color-scheme: dark) {
      outline-color: white;
    }
  }
}

.Container {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.Button {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  height: 2rem;
  padding: 0 0.75rem;
  margin: 0;
  border: 1px solid oklch(14.5% 0 0deg);
  background-color: white;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 400;
  line-height: 1;
  white-space: nowrap;
  color: oklch(14.5% 0 0deg);
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    border: 1px solid white;
    background-color: oklch(14.5% 0 0deg);
    color: white;
  }

  @media (hover: hover) {
    &:hover:not(:disabled) {
      background-color: oklch(97% 0 0deg);

      @media (prefers-color-scheme: dark) {
        background-color: oklch(26.9% 0 0deg);
      }
    }
  }

  &:active:not(:disabled) {
    background-color: oklch(92.2% 0 0deg);

    @media (prefers-color-scheme: dark) {
      background-color: oklch(37.1% 0 0deg);
    }
  }

  &[data-pressed]:not(:disabled) {
    background-color: oklch(97% 0 0deg);

    @media (prefers-color-scheme: dark) {
      background-color: oklch(26.9% 0 0deg);
    }
  }

  &:disabled {
    color: oklch(55.6% 0 0deg);
    border-color: oklch(55.6% 0 0deg);

    @media (prefers-color-scheme: dark) {
      color: oklch(70.8% 0 0deg);
      border-color: oklch(70.8% 0 0deg);
    }
  }

  &:focus-visible {
    outline: 2px solid oklch(14.5% 0 0deg);
    outline-offset: -1px;

    @media (prefers-color-scheme: dark) {
      outline-color: white;
    }
  }
}

.IconButton {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  margin: 0;
  outline: 0;
  border: 1px solid oklch(14.5% 0 0deg);
  border-radius: 0;
  background-color: white;
  color: oklch(14.5% 0 0deg);
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    border: 1px solid white;
    background-color: oklch(14.5% 0 0deg);
    color: white;
  }

  @media (hover: hover) {
    &:hover:not(:disabled) {
      background-color: oklch(97% 0 0deg);

      @media (prefers-color-scheme: dark) {
        background-color: oklch(26.9% 0 0deg);
      }
    }
  }

  &:active:not(:disabled) {
    background-color: oklch(92.2% 0 0deg);

    @media (prefers-color-scheme: dark) {
      background-color: oklch(37.1% 0 0deg);
    }
  }

  &[data-pressed] {
    background-color: oklch(97% 0 0deg);

    @media (prefers-color-scheme: dark) {
      background-color: oklch(26.9% 0 0deg);
    }
  }

  &:disabled {
    color: oklch(55.6% 0 0deg);
    border-color: oklch(55.6% 0 0deg);

    @media (prefers-color-scheme: dark) {
      color: oklch(70.8% 0 0deg);
      border-color: oklch(70.8% 0 0deg);
    }
  }

  &:focus-visible {
    outline: 2px solid oklch(14.5% 0 0deg);
    outline-offset: -1px;

    @media (prefers-color-scheme: dark) {
      outline-color: white;
    }
  }
}
vue
<script setup lang="ts">
import { h, shallowRef } from 'vue';
import type { FunctionalComponent } from 'vue';
import { Popover } from '@vase-ui/vue/popover';

const demoPopover = Popover.createHandle();

const open = shallowRef(false);
const triggerId = shallowRef<string | null>(null);

function handleOpenChange(isOpen: boolean, eventDetails: Popover.Root.ChangeEventDetails) {
  open.value = isOpen;
  triggerId.value = eventDetails.trigger?.id ?? null;
}

function openProgrammatically() {
  triggerId.value = 'trigger-2';
  open.value = true;
}

const XIcon: FunctionalComponent = (_, { attrs }) =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'none',
      stroke: 'currentColor',
      'stroke-linecap': 'square',
      'stroke-linejoin': 'round',
      ...attrs,
      style: { display: 'block' },
    },
    [h('path', { d: 'm4.5 4.5 7 7m-7 0 7-7' })],
  );

const triggerClassName =
  'flex h-8 items-center justify-center border border-neutral-950 dark:border-white bg-white dark:bg-neutral-950 px-3 text-sm font-normal whitespace-nowrap text-neutral-950 dark:text-white select-none hover:not-disabled:bg-neutral-100 dark:hover:not-disabled:bg-neutral-800 active:not-disabled:bg-neutral-200 dark:active:not-disabled:bg-neutral-700 disabled:border-neutral-500 disabled:text-neutral-500 data-pressed:bg-neutral-100 dark:data-pressed:bg-neutral-800 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white';

const popupHiddenClass = 'scale-[0.98] opacity-0';
</script>

<template>
  <div class="flex gap-2 flex-wrap justify-center">
    <Popover.Trigger :class="triggerClassName" :handle="demoPopover" id="trigger-1">
      Trigger 1
    </Popover.Trigger>

    <Popover.Trigger :class="triggerClassName" :handle="demoPopover" id="trigger-2">
      Trigger 2
    </Popover.Trigger>

    <Popover.Trigger :class="triggerClassName" :handle="demoPopover" id="trigger-3">
      Trigger 3
    </Popover.Trigger>

    <button
      type="button"
      class="flex h-8 items-center justify-center border border-neutral-950 dark:border-white bg-white dark:bg-neutral-950 px-3 text-sm font-normal whitespace-nowrap text-neutral-950 dark:text-white select-none hover:bg-neutral-100 dark:hover:bg-neutral-800 active:bg-neutral-200 dark:active:bg-neutral-700 disabled:border-neutral-500 disabled:text-neutral-500 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
      @click="openProgrammatically"
    >
      Open programmatically
    </button>
  </div>

  <Popover.Root
    :handle="demoPopover"
    :open="open"
    :trigger-id="triggerId"
    @open-change="handleOpenChange"
  >
    <Popover.Portal>
      <Popover.Positioner
        class="h-[var(--positioner-height)] w-[var(--positioner-width)] max-w-[var(--available-width)]"
        :side-offset="8"
      >
        <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
          <Popover.Popup
            class="relative flex h-[var(--popup-height,auto)] w-[var(--popup-width,auto)] max-w-[500px] flex-col gap-1 origin-[var(--transform-origin)] bg-white dark:bg-neutral-950 p-3 text-neutral-950 dark:text-white outline-none border border-neutral-950 dark:border-white shadow-[0.25rem_0.25rem_0] shadow-black/12 dark:shadow-none transition-[scale,opacity] duration-100 ease-out"
          >
            <Popover.Arrow
              class="relative block w-3 h-1.5 overflow-clip data-[side=bottom]:top-[-6px] data-[side=left]:right-[-9px] data-[side=left]:rotate-90 data-[side=right]:left-[-9px] data-[side=right]:-rotate-90 data-[side=top]:bottom-[-6px] data-[side=top]:rotate-180 before:content-[''] before:absolute before:bottom-0 before:left-1/2 before:w-[calc(6px*sqrt(2))] before:h-[calc(6px*sqrt(2))] before:bg-white dark:before:bg-neutral-950 before:border before:border-neutral-950 dark:before:border-white before:[transform:translate(-50%,50%)_rotate(45deg)]"
            />
            <Popover.Title class="pr-8 text-sm font-bold">Free shipping</Popover.Title>
            <Popover.Description class="text-sm text-neutral-600 dark:text-neutral-400">
              Orders over $50 arrive in 3–5 business days at no extra cost.
            </Popover.Description>
            <a
              href="#"
              class="self-start text-sm text-neutral-950 dark:text-white underline underline-offset-[0.16em] decoration-[1px] hover:no-underline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
              >View shipping policy</a
            >
            <Popover.Close
              aria-label="Close"
              class="absolute top-2 right-2 flex size-7 items-center justify-center border-0 bg-transparent p-0 text-neutral-950 dark:text-white hover:bg-neutral-100 dark:hover:bg-neutral-800 active:bg-neutral-200 dark:active:bg-neutral-700 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
            >
              <XIcon />
            </Popover.Close>
          </Popover.Popup>
        </Transition>
      </Popover.Positioner>
    </Popover.Portal>
  </Popover.Root>
</template>

Animating the Popover ​

A popover can animate its position, its size and its content when it moves from one trigger to another.

Position and size ​

To animate the position, give Popover.Positioner a CSS transition of left, right, top and bottom. To animate the size, give Popover.Popup a transition of width and height.

Content ​

To animate the content, put it in Popover.Viewport. The default slot of the viewport gets triggerId, the id of the active trigger. Put the content in a <Transition>, with triggerId as its key. At a move, the old content leaves while the new content enters. Select the old content with the leave classes, and the viewport while it has old content with :has(> .x-leave-active).

The data-activation-direction attribute of the viewport gives the place of the new trigger from the old trigger. Its value has one or two tokens, one for each axis: left or right, and up or down, such as right down. Match one token with the ~= selector, such as [data-activation-direction~='right'].

Use a viewport only when one popup has more than one trigger, and the content changes with an animation at a move to another trigger. With a viewport, give Popover.Positioner the styles width: var(--positioner-width) and height: var(--positioner-height). The positioner then keeps the measured size during the transition. Without these styles, the size of the content can change the size of the popup in each frame, or move the popup to another side.

vue
<script setup lang="ts">
import { h } from 'vue';
import type { FunctionalComponent } from 'vue';
import { Popover } from '@vase-ui/vue/popover';
import baseStyles from '../../_index.module.css';
import styles from './index.module.css';

type Panel = 'shipping' | 'returns' | 'profile';

const demoPopover = Popover.createHandle<Panel>();

const XIcon: FunctionalComponent = (_, { attrs }) =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'none',
      stroke: 'currentColor',
      'stroke-linecap': 'square',
      'stroke-linejoin': 'round',
      ...attrs,
      style: { display: 'block' },
    },
    [h('path', { d: 'm4.5 4.5 7 7m-7 0 7-7' })],
  );

const popupHiddenClass = styles.PopupHidden;
const contentEnterFromClass = styles.ContentEnterFrom;
const contentLeavingClass = styles.ContentLeaving;
const contentLeaveToClass = styles.ContentLeaveTo;
</script>

<template>
  <div :class="styles.Container">
    <Popover.Trigger :class="baseStyles.Button" :handle="demoPopover" payload="shipping">
      Shipping
    </Popover.Trigger>

    <Popover.Trigger :class="baseStyles.Button" :handle="demoPopover" payload="returns">
      Returns
    </Popover.Trigger>

    <Popover.Trigger :class="baseStyles.Button" :handle="demoPopover" payload="profile">
      Profile
    </Popover.Trigger>

    <Popover.Root v-slot="{ payload }" :handle="demoPopover">
      <Popover.Portal>
        <Popover.Positioner :side-offset="8" :class="styles.Positioner">
          <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
            <Popover.Popup :class="styles.Popup">
              <Popover.Arrow :class="styles.Arrow" />

              <Popover.Viewport v-slot="{ triggerId }" :class="styles.Viewport">
                <Transition
                  :enter-from-class="contentEnterFromClass"
                  :leave-active-class="contentLeavingClass"
                  :leave-to-class="contentLeaveToClass"
                >
                  <div :key="triggerId ?? ''" :class="styles.Content">
                    <div v-if="payload === 'shipping'" :class="styles.Stack">
                      <Popover.Title :class="styles.Title">Free shipping</Popover.Title>
                      <Popover.Description :class="styles.Description">
                        Orders over $50 arrive in 3–5 business days at no extra cost.
                      </Popover.Description>
                    </div>
                    <div v-else-if="payload === 'returns'" :class="styles.Stack">
                      <Popover.Title :class="styles.Title">Free returns</Popover.Title>
                      <Popover.Description :class="styles.Description">
                        Return any item within 30 days for a full refund.
                      </Popover.Description>
                    </div>
                    <div v-else-if="payload === 'profile'" :class="styles.ProfilePanel">
                      <Popover.Title :class="styles.Title">Jason Eventon</Popover.Title>
                      <img
                        src="https://images.unsplash.com/photo-1543610892-0b1f7e6d8ac1?w=128&h=128&dpr=2&q=80"
                        width="48"
                        height="48"
                        alt=""
                        :class="styles.Avatar"
                      />
                      <span :class="styles.Plan">Pro plan</span>
                      <div :class="styles.ProfileActions">
                        <a href="#">Profile settings</a>
                        <a href="#">Log out</a>
                      </div>
                    </div>
                  </div>
                </Transition>
              </Popover.Viewport>

              <Popover.Close aria-label="Close" :class="styles.Close">
                <XIcon />
              </Popover.Close>
            </Popover.Popup>
          </Transition>
        </Popover.Positioner>
      </Popover.Portal>
    </Popover.Root>
  </div>
</template>
css
.Positioner {
  --easing: cubic-bezier(0.22, 1, 0.36, 1);
  --animation-duration: 0.35s;

  width: var(--positioner-width);
  height: var(--positioner-height);
  max-width: var(--available-width);

  transition-property: top, left, right, bottom, transform;
  transition-timing-function: var(--easing);
  transition-duration: var(--animation-duration);

  &[data-instant] {
    transition: none;
  }
}

.Popup {
  position: relative;
  outline: none;
  background-color: white;
  color: oklch(14.5% 0 0deg);
  border: 1px solid oklch(14.5% 0 0deg);
  box-shadow: 0.25rem 0.25rem 0 rgb(0 0 0 / 12%);
  transform-origin: var(--transform-origin);

  /* These are required to make the size animations work */
  width: var(--popup-width, auto);
  height: var(--popup-height, auto);

  max-width: 31.25rem;

  /* width and height are essential for the resize animation; opacity and transform handle the enter/exit animation */
  transition-property: width, height, opacity, transform;
  transition-timing-function: var(--easing);
  transition-duration: var(--animation-duration);

  @media (prefers-color-scheme: dark) {
    background-color: oklch(14.5% 0 0deg);
    color: white;
    border: 1px solid white;
    box-shadow: none;
  }

  &[data-instant] {
    transition: none;
  }
}

/* The enter-from and leave-to class of the `<Transition>` around the popup. */
.PopupHidden {
  opacity: 0;
  transform: scale(0.9);
}

.Viewport {
  --viewport-inline-padding: 0.5rem;
  box-sizing: border-box;
  /* Required to clip the overflowing content during the slide in/out animations */
  position: relative;
  overflow: clip;
  width: 100%;
  height: 100%;
  padding: 0.5rem var(--viewport-inline-padding);

  /* The content of a trigger. A `<Transition>` with the trigger id as the key keeps the old content
     for its leave while the new content enters. */
  .Content {
    /* This freezes the width of the content while transitioning. --popup-width measures the
       border-box of the popup. */
    width: calc(var(--popup-width) - 2 * var(--viewport-inline-padding));
    transform: translateX(0);
    opacity: 1;
    transition:
      transform var(--animation-duration) var(--easing),
      opacity calc(var(--animation-duration) / 2) var(--easing);
  }

  .ContentLeaving {
    position: absolute;
    top: 0.5rem;
    left: var(--viewport-inline-padding);
  }

  &[data-activation-direction~='right'] .ContentLeaveTo,
  &[data-activation-direction~='left'] .ContentEnterFrom {
    transform: translateX(-50%);
    opacity: 0;
  }

  &[data-activation-direction~='right'] .ContentEnterFrom,
  &[data-activation-direction~='left'] .ContentLeaveTo {
    transform: translateX(50%);
    opacity: 0;
  }
}

.Arrow {
  display: block;
  position: relative;
  width: 12px;
  height: 6px;
  overflow: clip;
  transition: left calc(var(--animation-duration)) var(--easing);

  &[data-side='top'] {
    bottom: -6px;
    rotate: 180deg;
  }

  &[data-side='bottom'] {
    top: -6px;
    rotate: 0deg;
  }

  &[data-side='left'] {
    right: -9px;
    rotate: 90deg;
  }

  &[data-side='right'] {
    left: -9px;
    rotate: -90deg;
  }

  &::before {
    content: '';
    display: block;
    position: absolute;
    bottom: 0;
    left: 50%;
    box-sizing: border-box;
    width: calc(6px * sqrt(2));
    height: calc(6px * sqrt(2));
    background-color: white;
    border: 1px solid oklch(14.5% 0 0deg);
    transform: translate(-50%, 50%) rotate(45deg);

    @media (prefers-color-scheme: dark) {
      background-color: oklch(14.5% 0 0deg);
      border: 1px solid white;
    }
  }
}

.Stack {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.Title {
  margin: 0;
  padding-right: 2rem;
  font-size: 0.875rem;
  line-height: 1.25rem;
  font-weight: 700;
}

.Description {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.25rem;
  color: oklch(43.9% 0 0deg);

  @media (prefers-color-scheme: dark) {
    color: oklch(70.8% 0 0deg);
  }
}

.Close {
  box-sizing: border-box;
  position: absolute;
  top: 0.25rem;
  right: 0.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  margin: 0;
  border: none;
  background: none;
  color: oklch(14.5% 0 0deg);

  @media (prefers-color-scheme: dark) {
    color: white;
  }

  @media (hover: hover) {
    &:hover {
      background-color: oklch(97% 0 0deg);

      @media (prefers-color-scheme: dark) {
        background-color: oklch(26.9% 0 0deg);
      }
    }
  }

  &:active {
    background-color: oklch(92.2% 0 0deg);

    @media (prefers-color-scheme: dark) {
      background-color: oklch(37.1% 0 0deg);
    }
  }

  &:focus-visible {
    outline: 2px solid oklch(14.5% 0 0deg);
    outline-offset: -1px;

    @media (prefers-color-scheme: dark) {
      outline-color: white;
    }
  }
}

.Container {
  display: flex;
  gap: 0.5rem;
}

.ProfilePanel {
  display: grid;
  grid-template-columns: auto auto;
  width: max-content;
  column-gap: 0.5rem;

  .Title {
    grid-column: 2;
    grid-row: 1;
  }

  .Plan {
    grid-column: 2;
    grid-row: 2;
    font-size: 0.875rem;
    line-height: 1.25rem;
    color: oklch(43.9% 0 0deg);

    @media (prefers-color-scheme: dark) {
      color: oklch(70.8% 0 0deg);
    }
  }

  .Avatar {
    grid-column: 1;
    grid-row: 1 / span 2;
    width: 3rem;
    height: 3rem;
    object-fit: cover;
    background-color: oklch(92.2% 0 0deg);

    @media (prefers-color-scheme: dark) {
      background-color: oklch(26.9% 0 0deg);
    }
  }

  .ProfileActions {
    grid-column: 1 / span 2;
    grid-row: 3;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding-top: 0.5rem;
    font-size: 0.875rem;
    line-height: 1.25rem;

    a {
      color: oklch(14.5% 0 0deg);
      text-decoration: underline;
      text-decoration-thickness: 1px;
      text-underline-offset: 0.16em;

      @media (prefers-color-scheme: dark) {
        color: white;
      }

      @media (hover: hover) {
        &:hover {
          text-decoration: none;
        }
      }

      &:focus-visible {
        outline: 2px solid oklch(14.5% 0 0deg);
        outline-offset: 2px;

        @media (prefers-color-scheme: dark) {
          outline-color: white;
        }
      }
    }
  }
}
vue
<script setup lang="ts">
import { h } from 'vue';
import type { FunctionalComponent } from 'vue';
import { Popover } from '@vase-ui/vue/popover';

type Panel = 'shipping' | 'returns' | 'profile';

const demoPopover = Popover.createHandle<Panel>();

const XIcon: FunctionalComponent = (_, { attrs }) =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'none',
      stroke: 'currentColor',
      'stroke-linecap': 'square',
      'stroke-linejoin': 'round',
      ...attrs,
      style: { display: 'block' },
    },
    [h('path', { d: 'm4.5 4.5 7 7m-7 0 7-7' })],
  );

// The viewport has the side of the new trigger in `data-activation-direction`.
const contentEnterFromClass =
  'opacity-0 group-data-[activation-direction~=left]:-translate-x-1/2 group-data-[activation-direction~=right]:translate-x-1/2';
const contentLeavingClass = 'absolute top-2 left-2';
const contentLeaveToClass =
  'opacity-0 group-data-[activation-direction~=left]:translate-x-1/2 group-data-[activation-direction~=right]:-translate-x-1/2';

const triggerClassName =
  'flex h-8 items-center justify-center border border-neutral-950 dark:border-white bg-white dark:bg-neutral-950 px-3 text-sm font-normal whitespace-nowrap text-neutral-950 dark:text-white select-none hover:not-disabled:bg-neutral-100 dark:hover:not-disabled:bg-neutral-800 active:not-disabled:bg-neutral-200 dark:active:not-disabled:bg-neutral-700 disabled:border-neutral-500 disabled:text-neutral-500 data-pressed:bg-neutral-100 dark:data-pressed:bg-neutral-800 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white';

const popupHiddenClass = 'scale-90 opacity-0';
</script>

<template>
  <div class="flex gap-2">
    <Popover.Trigger :class="triggerClassName" :handle="demoPopover" payload="shipping">
      Shipping
    </Popover.Trigger>

    <Popover.Trigger :class="triggerClassName" :handle="demoPopover" payload="returns">
      Returns
    </Popover.Trigger>

    <Popover.Trigger :class="triggerClassName" :handle="demoPopover" payload="profile">
      Profile
    </Popover.Trigger>

    <Popover.Root v-slot="{ payload }" :handle="demoPopover">
      <Popover.Portal>
        <Popover.Positioner
          :side-offset="8"
          class="h-[var(--positioner-height)] w-[var(--positioner-width)] max-w-[var(--available-width)] transition-[top,left,right,bottom,transform] duration-[0.35s] ease-[cubic-bezier(0.22,1,0.36,1)] data-instant:transition-none"
        >
          <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
            <Popover.Popup
              class="relative flex h-[var(--popup-height,auto)] w-[var(--popup-width,auto)] max-w-[31.25rem] flex-col gap-1 origin-[var(--transform-origin)] bg-white dark:bg-neutral-950 text-neutral-950 dark:text-white outline-none border border-neutral-950 dark:border-white shadow-[0.25rem_0.25rem_0] shadow-black/12 dark:shadow-none transition-[width,height,opacity,scale] duration-[0.35s] ease-[cubic-bezier(0.22,1,0.36,1)] data-instant:transition-none"
            >
              <Popover.Arrow
                class="relative block w-3 h-1.5 overflow-clip transition-[left] duration-[0.35s] ease-[cubic-bezier(0.22,1,0.36,1)] data-[side=bottom]:top-[-6px] data-[side=left]:right-[-9px] data-[side=left]:rotate-90 data-[side=right]:left-[-9px] data-[side=right]:-rotate-90 data-[side=top]:bottom-[-6px] data-[side=top]:rotate-180 before:content-[''] before:absolute before:bottom-0 before:left-1/2 before:w-[calc(6px*sqrt(2))] before:h-[calc(6px*sqrt(2))] before:bg-white dark:before:bg-neutral-950 before:border before:border-neutral-950 dark:before:border-white before:[transform:translate(-50%,50%)_rotate(45deg)]"
              />

              <Popover.Viewport
                v-slot="{ triggerId }"
                class="group relative h-full w-full overflow-clip p-2"
              >
                <Transition
                  :enter-from-class="contentEnterFromClass"
                  :leave-active-class="contentLeavingClass"
                  :leave-to-class="contentLeaveToClass"
                >
                  <div
                    :key="triggerId ?? ''"
                    class="w-[calc(var(--popup-width)-1rem)] transition-[translate,opacity] duration-[350ms,175ms] ease-[cubic-bezier(0.22,1,0.36,1)]"
                  >
                    <div v-if="payload === 'shipping'" class="flex flex-col gap-1">
                      <Popover.Title class="pr-8 text-sm font-bold">Free shipping</Popover.Title>
                      <Popover.Description class="text-sm text-neutral-600 dark:text-neutral-400">
                        Orders over $50 arrive in 3–5 business days at no extra cost.
                      </Popover.Description>
                    </div>
                    <div v-else-if="payload === 'returns'" class="flex flex-col gap-1">
                      <Popover.Title class="pr-8 text-sm font-bold">Free returns</Popover.Title>
                      <Popover.Description class="text-sm text-neutral-600 dark:text-neutral-400">
                        Return any item within 30 days for a full refund.
                      </Popover.Description>
                    </div>
                    <div
                      v-else-if="payload === 'profile'"
                      class="grid w-max grid-cols-[auto_auto] gap-x-2"
                    >
                      <Popover.Title
                        class="col-start-2 col-end-3 row-start-1 row-end-2 pr-8 text-sm font-bold"
                        >Jason Eventon</Popover.Title
                      >
                      <img
                        src="https://images.unsplash.com/photo-1543610892-0b1f7e6d8ac1?w=128&h=128&dpr=2&q=80"
                        width="48"
                        height="48"
                        alt=""
                        class="col-start-1 col-end-2 row-start-1 row-end-3 h-12 w-12 object-cover bg-neutral-200 dark:bg-neutral-800"
                      />
                      <span
                        class="col-start-2 col-end-3 row-start-2 row-end-3 text-sm text-neutral-600 dark:text-neutral-400"
                        >Pro plan</span
                      >
                      <div
                        class="col-start-1 col-end-3 row-start-3 row-end-4 flex flex-col gap-2 pt-2 text-sm"
                      >
                        <a
                          href="#"
                          class="text-neutral-950 dark:text-white underline underline-offset-[0.16em] decoration-[1px] hover:no-underline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
                          >Profile settings</a
                        >
                        <a
                          href="#"
                          class="text-neutral-950 dark:text-white underline underline-offset-[0.16em] decoration-[1px] hover:no-underline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
                          >Log out</a
                        >
                      </div>
                    </div>
                  </div>
                </Transition>
              </Popover.Viewport>

              <Popover.Close
                aria-label="Close"
                class="absolute top-1 right-1 flex size-7 items-center justify-center border-0 bg-transparent p-0 text-neutral-950 dark:text-white hover:bg-neutral-100 dark:hover:bg-neutral-800 active:bg-neutral-200 dark:active:bg-neutral-700 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
              >
                <XIcon />
              </Popover.Close>
            </Popover.Popup>
          </Transition>
        </Popover.Positioner>
      </Popover.Portal>
    </Popover.Root>
  </div>
</template>

API reference ​

Popover.Root ​

Groups the parts of the popover. Renders no element.

Props

PropTypeDefaultDescription
defaultOpenboolean | undefinedfalseThe popover is open at the mount of an uncontrolled root.
defaultTriggerIdstring | null | undefinednullThe id of the active trigger at the mount, with defaultOpen.
handlePopoverHandle<Payload> | undefinedConnects the root to triggers outside it and to code.
modalboolean | "trap-focus" | undefinedfalseThe modal state of the open popover: - false: the page stays in use. - true: the page does not scroll, and only the popup and the active trigger get a pointer. After a touch open, the page scrolls, unless the popup is about as wide as the view. With a Popover.Close in the popup, the focus stays in the popup, and the rest of the page is inert. - 'trap-focus': with a Popover.Close in the popup, the focus stays in the popup, and screen readers do not read the rest of the page. The page stays in use. The focus stays in the popup only with a Popover.Close, so a user of a touch screen reader has a way out. A popover that a hover opened is not modal until a press on its trigger.
openboolean | undefinedThe popover is open. v-model:open binds it.
triggerIdstring | null | undefinedThe id of the active trigger. v-model:trigger-id binds it.

Slots

SlotSlot propsDescription
default
payload: Payload | undefined
The content of the popover. payload is the payload of the active trigger.

Events

EventArgumentsDescription
openChange[open: boolean, details: PopoverRootChangeEventDetails]The popover opens or closes. details.cancel() keeps it as it was.
update:open[open: boolean]Comes after openChange, unless a listener cancels the change. v-model:open uses it.
update:triggerId[id: string | null]The active trigger changes. v-model:trigger-id uses it.

Exposed

MemberTypeDescription
close() => voidCloses the popover with the reason 'imperative-action'.

Popover.Trigger ​

A button that opens the popover. Renders a <button> element.

Props

PropTypeDefaultDescription
closeDelaynumber | undefined0The time in milliseconds before the close, after the pointer left the trigger and the popup, with openOnHover.
delaynumber | undefined300The time in milliseconds that the mouse rests on the trigger before the open, with openOnHover.
disabledboolean | undefinedfalseThe user cannot press the trigger.
handlePopoverHandle<Payload> | undefinedConnects the trigger to a root outside it.
idstring | undefinedThe id of the element, with a generated id as the default. The triggerId of the root and open() of the handle name the trigger by it.
openOnHoverboolean | undefinedfalseA mouse that rests on the trigger also opens the popover.
payloadPayload | undefinedThe payload that the popover gets when this trigger opens it.
askeyof HTMLElementTagNameMap | Component | GenericComponent | undefinedA tag or a component that the part renders in place of its own element, with the same attributes and content. The element slot wins over it.

Slots

SlotSlot propsDescription
default
state: PopoverTriggerState
The content of the part.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: PopoverTriggerState
Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref.

Exposed

MemberTypeDescription
elementHTMLElement | nullThe element of the part, or null while it is not mounted.

Selectors

SelectorDescription
[aria-expanded="true"]The popover is open for this trigger.
[data-pressed]The popover is open for this trigger, and a press on the trigger opened it or kept it open.
:disabledThe trigger is a native button, and the trigger or a fieldset around it is disabled.
[aria-disabled="true"]The trigger is another element, and it is disabled.

Popover.Backdrop ​

An overlay under the popup. Renders a <div> element.

Props

PropTypeDefaultDescription
askeyof HTMLElementTagNameMap | Component | GenericComponent | undefinedA tag or a component that the part renders in place of its own element, with the same attributes and content. The element slot wins over it.

Slots

SlotSlot propsDescription
default
state: PopoverBackdropState
The content of the part.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: PopoverBackdropState
Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref.

Exposed

MemberTypeDescription
elementHTMLElement | nullThe element of the part, or null while it is not mounted.

Selectors

SelectorDescription
[hidden]The popover is closed, and keepMounted keeps the backdrop in the DOM.

Popover.Portal ​

Moves its content to another place of the DOM, <body> by default. Renders a visually hidden <span> in place while the moved popup is open and Tab can leave it. Its aria-owns names the popup, so a screen reader reads the popup after its trigger.

Props

PropTypeDefaultDescription
deferboolean | undefinedfalseMoves the content after the other content of the same update mounted.
disabledboolean | undefinedfalseRenders the content in place, also on the server.
keepMountedboolean | undefinedfalseThe closed popup stays in the DOM, with hidden and inert.
toPortalTarget | undefinedThe target of the content. With no value, the target of the nearest portal above, else body. While it is null, the portal renders nothing.

Slots

SlotSlot propsDescription
defaultThe content of the part.

Popover.Positioner ​

Places the popup at its anchor. Renders a <div> element.

Props

PropTypeDefaultDescription
alignAlign | undefined'center'The alignment of the popup on the side.
alignOffsetnumber | OffsetFunction | undefined0The offset on the align axis in pixels, or a function that gives it.
anchorAnchor | (() => Anchor)The element to place the popup against: an element, a virtual element, a template ref of a part, or a function that gives one. With no value, the active trigger.
arrowPaddingnumber | undefined5The smallest space between the arrow and an inner edge of its nearest positioned ancestor, in pixels.
collisionAvoidanceCollisionAvoidance | undefinedHow the popup avoids the edge of the boundary.
collisionBoundaryBoundary | undefined'clipping-ancestors'The area that holds the popup: an element, elements, or a rectangle.
collisionPaddingPadding | undefined5The space between the popup and the edge of the boundary, in pixels.
disableAnchorTrackingboolean | undefinedfalseThe popup does not follow a move of its anchor.
positionMethod"absolute" | "fixed" | undefined'absolute'The CSS position of the positioner.
sideSide | undefined'bottom'The side of the anchor for the popup. It can change to avoid a collision. inline-start and inline-end follow the CSS direction of the positioner: give the positioner dir when the target of its portal has another direction.
sideOffsetnumber | OffsetFunction | undefined0The distance from the anchor in pixels, or a function that gives it.
stickyboolean | undefinedfalseThe popup stays in the view after its anchor scrolls out of it.
askeyof HTMLElementTagNameMap | Component | GenericComponent | undefinedA tag or a component that the part renders in place of its own element, with the same attributes and content. The element slot wins over it.

Slots

SlotSlot propsDescription
default
state: PopoverPositionerState
The content of the part.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: PopoverPositionerState
Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref.

Exposed

MemberTypeDescription
elementHTMLElement | nullThe element of the part, or null while it is not mounted.

Selectors

SelectorDescription
[data-side]The side of the anchor that the popup is on: top, bottom, left or right, or inline-start or inline-end for a logical side prop.
[data-align]The alignment of the popup on its side: start, center or end.
[data-anchor-hidden]The anchor is out of view.

CSS variables

VariableDescription
--anchor-widthThe width of the anchor, in pixels.
--anchor-heightThe height of the anchor, in pixels.
--available-widthThe width that the popup can have before it goes over the edge of the collision boundary.
--available-heightThe height that the popup can have before it goes over the edge of the collision boundary.
--transform-originThe point that the popup grows from, for the transform-origin of the popup. It is at the arrow, on the edge of the anchor. With no arrow, it is at the aligned edge of the popup or at the center of the anchor.
--positioner-widthThe width of the popup, in pixels, with a Popover.Viewport in the popup. During a move to another trigger, the width of the new content.
--positioner-heightThe height of the popup, in pixels, with a Popover.Viewport in the popup. During a move to another trigger, the height of the new content.

Popover.Popup ​

The container of the content of the popover. Renders a <div> element.

Props

PropTypeDefaultDescription
finalFocusFocusTarget | undefinedThe element that gets the focus at the close. By default: the trigger, else the element that had the focus before the open. After an open by code, that element comes before the trigger. For an element that is no tab stop, the focus goes to its first tab stop outside the popup. An element in the popup is no target.
idstring | undefinedThe id of the element, with a generated id as the default. The open trigger names it in aria-controls.
initialFocusFocusTarget | undefinedThe element that gets the focus at the open. By default: the element with autofocus, else the first tab stop, else the popup; after a touch, the popup.
askeyof HTMLElementTagNameMap | Component | GenericComponent | undefinedA tag or a component that the part renders in place of its own element, with the same attributes and content. The element slot wins over it.

Slots

SlotSlot propsDescription
default
state: PopoverPopupState
The content of the part.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: PopoverPopupState
Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref.

Exposed

MemberTypeDescription
elementHTMLElement | nullThe element of the part, or null while it is not mounted.

Selectors

SelectorDescription
[data-side]The side of the anchor that the popup is on, as on the positioner.
[data-align]The alignment of the popup on its side, as on the positioner.
[data-instant]An animation must not run. The value says why: click (a key on the trigger opened or closed the popover), dismiss (Escape closed it), focus (the focus left it) or trigger-change (a move to another trigger ended).
[hidden]The popover is closed, and keepMounted keeps the popup in the DOM.

CSS variables

VariableDescription
--popup-widthThe width of the popup, in pixels, during a move to another trigger with a Popover.Viewport: first the old width, then the new width.
--popup-heightThe height of the popup, in pixels, during a move to another trigger with a Popover.Viewport: first the old height, then the new height.

Popover.Arrow ​

An element that points to the center of the anchor. Renders a <div> element. Its place is in the padding box of its nearest positioned ancestor: the popup when the popup has a position, else the positioner.

Props

PropTypeDefaultDescription
askeyof HTMLElementTagNameMap | Component | GenericComponent | undefinedA tag or a component that the part renders in place of its own element, with the same attributes and content. The element slot wins over it.

Slots

SlotSlot propsDescription
default
state: PopoverArrowState
The content of the part.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: PopoverArrowState
Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref.

Exposed

MemberTypeDescription
elementHTMLElement | nullThe element of the part, or null while it is not mounted.

Selectors

SelectorDescription
[data-side]The side of the anchor that the popup is on, as on the positioner.
[data-align]The alignment of the popup on its side, as on the positioner.
[data-uncentered]The arrow cannot point at the center of the anchor.

Popover.Title ​

A heading that names the popover. Renders an <h2> element.

Props

PropTypeDefaultDescription
idstring | undefinedThe id of the element, with a generated id as the default. The popup names it in aria-labelledby.
askeyof HTMLElementTagNameMap | Component | GenericComponent | undefinedA tag or a component that the part renders in place of its own element, with the same attributes and content. The element slot wins over it.

Slots

SlotSlot propsDescription
default
state: PopoverTitleState
The content of the part.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: PopoverTitleState
Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref.

Exposed

MemberTypeDescription
elementHTMLElement | nullThe element of the part, or null while it is not mounted.

Popover.Description ​

A paragraph that describes the popover. Renders a <p> element.

Props

PropTypeDefaultDescription
idstring | undefinedThe id of the element, with a generated id as the default. The popup names it in aria-describedby.
askeyof HTMLElementTagNameMap | Component | GenericComponent | undefinedA tag or a component that the part renders in place of its own element, with the same attributes and content. The element slot wins over it.

Slots

SlotSlot propsDescription
default
state: PopoverDescriptionState
The content of the part.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: PopoverDescriptionState
Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref.

Exposed

MemberTypeDescription
elementHTMLElement | nullThe element of the part, or null while it is not mounted.

Popover.Close ​

A button that closes the popover. Renders a <button> element.

Props

PropTypeDefaultDescription
disabledboolean | undefinedfalseThe user cannot press the button.
askeyof HTMLElementTagNameMap | Component | GenericComponent | undefinedA tag or a component that the part renders in place of its own element, with the same attributes and content. The element slot wins over it.

Slots

SlotSlot propsDescription
default
state: PopoverCloseState
The content of the part.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: PopoverCloseState
Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref.

Exposed

MemberTypeDescription
elementHTMLElement | nullThe element of the part, or null while it is not mounted.

Selectors

SelectorDescription
:disabledThe button is a native button, and the button or a fieldset around it is disabled.
[aria-disabled="true"]The button is another element, and it is disabled.

Popover.Viewport ​

The container of content that changes when the popover moves to another trigger. Renders a <div> element.

Props

PropTypeDefaultDescription
askeyof HTMLElementTagNameMap | Component | GenericComponent | undefinedA tag or a component that the part renders in place of its own element, with the same attributes and content. The element slot wins over it.

Slots

SlotSlot propsDescription
default
state: PopoverViewportState
triggerId: string | null
Give the content the triggerId as its key in a <Transition>, so that it leaves and enters at a move.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: PopoverViewportState
Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref.

Exposed

MemberTypeDescription
elementHTMLElement | nullThe element of the part, or null while it is not mounted.

Selectors

SelectorDescription
[data-activation-direction]The place of the new trigger from the old trigger, after a move: at most two tokens, left or right and up or down, such as right down.
[data-instant]An animation must not run, with the values of the popup.

createHandle ​

Makes a Popover.Handle with the type argument as the type of its payload.

Return value

PopoverHandle<Payload>

Handle ​

A handle opens and closes the popover from code, and connects the triggers outside the root to it.

Properties

PropertyTypeModifiersDescription
isOpenbooleanreadonlyThe popup is open. It is false while no root has the handle.

Methods

MethodReturnsDescription
open(triggerId: string)voidOpens the popup for the trigger with this id. With no mounted root, it does nothing, and a development build warns. Throws an error when the root has no trigger with this id.
close()voidCloses the popup. With no mounted root, it does nothing.

Differences from Base UI ​

Vase UI ports Popover from Base UI 1.9.0.

API ​

Base UIVase UI
Popover.Root prop onOpenChangeComplete@after-enter and @after-leave of a <Transition> around the popup run after its animations.
Popover.Root prop actionsRefA template ref of the root has close(). With :css="false", the leave hook of a <Transition> keeps the popup until it calls done, so the root has no unmount action.
Popover.Trigger prop nativeButtonThe trigger reads the element that it renders, so it has no nativeButton.
Popover.Backdrop<Transition> around the backdrop animates it, so the state has no transitionStatus, and the backdrop has no data-starting-style and no data-ending-style. CSS selects a closed backdrop that stays in the DOM with [hidden], so the backdrop has no data-open and no data-closed.
Popover.Portal prop renderThe portal is a <Teleport>: its content goes to the target, and its only element in place is the visually hidden element that owns the popup. So it has no as and no element slot. Put an element in the portal when you need one.
Popover.Popup<Transition> around the popup animates it, so the state has no transitionStatus, and the popup has no data-starting-style and no data-ending-style. CSS selects a closed popup that stays in the DOM with [hidden], so the popup has no data-open and no data-closed.
Popover.Close prop nativeButtonThe button reads the element that it renders, so it has no nativeButton.

Added in Vase UI ​

PartMemberWhy
Popover.Portaldisabled propThe portal is a <Teleport>, and disabled renders its content in place, also on the server.
Popover.Rootupdate:triggerId eventv-model:trigger-id binds the active trigger: Vue binds a second state of a component with a named v-model.
Popover.Portaldefer propThe portal is a <Teleport>, and it takes the props of <Teleport>: defer waits for the other content of the update.
Popover.Closedisabled state fieldThe state of the button says that it is disabled, by its prop or by a disabled fieldset, as the state of Button does.

Return types ​

FunctionVase UI returnsWhy
Popover.createHandlePopoverHandle<Payload>Popover.Handle is the class PopoverHandle. The declaration of the function names the class, and Base UI documents the same class by its name in the namespace.

Behavior ​

Vase UIEvidence
An open Popover can have no popup part, and an open Navigation Menu can have no viewport. A consumer can remove the part with v-if, or the part can be an async component that has not loaded. The Tab key then skips the popup, as it skips a popup with no tabbable element. Shift+Tab moves the focus from the element after Popover.Trigger to the trigger, and it asks for no close. Tab moves the focus from an active NavigationMenu.Trigger to the next tabbable element, and Shift+Tab moves it from that element to the trigger. Tab from NavigationMenu.Trigger closes the item with the reason focus-out in the cases where Tab from the end of a viewport closes it. In Base UI, Shift+Tab from the element after the trigger of such a Popover focuses that element again. Tab from an active NavigationMenu.Trigger with no viewport focuses that trigger again, and Shift+Tab from the next trigger focuses the next trigger again.
A hover moves an open popup to another trigger of its root at once. When the point where the pointer enters that trigger is in the triangle from the last point on the active trigger to the near edge of the popup, the trigger opens nothing while the pointer moves in the triangle. It opens when the pointer leaves the triangle on it or rests there for 40 ms. This rule holds for Popover, Preview Card, Tooltip, Menu and Navigation Menu. Base UI blocks the other triggers in the triangle only in Navigation Menu and Menu, so in a Popover, a Preview Card or a Tooltip with a hoverable popup, a trigger in the triangle takes the popup while the user moves to it.
A touch outside an open popup closes it only at a tap. A tap ends with pointerup in less than 1 s and moves 8 px or less. Chromium on Android sends click for a move of 8 px and not for 8.1 px, the smallest limit of the measured browsers. A touch that scrolls the page ends with pointercancel and closes nothing, as a native popover stays open in Chromium and WebKit. A drag of more than 8 px on an element that does not scroll also closes nothing. A tap on a backdrop, or on the element that a modal popup puts over the page, closes the popup and gives the page under it no click. In Base UI, a touch that scrolls the page closes a Popover, a Menu or a Select.
An arrow points at the center of its anchor. Its place is in the padding box of its nearest positioned ancestor, so the borders of a popup with a position do not move it. arrowPadding keeps the same space from each inner edge of that box. In the Popover demo of Base UI, the popup has position: relative and a 1 px border, and the arrow is 1.5 px off the center of its trigger.
--transform-origin is in the pixels of the popup, from its border box: the arrow or the aligned edge or the center of the anchor, on the edge of the anchor. A margin of the popup, a padding of the positioner, a margin that collapses through the popup and a zoom of the popup do not move it. A Select popup over the trigger grows from the middle of the value, also after it grows while the user scrolls the list. In the Popover demo of Base UI, a 16 px margin on the popup moves the origin 16 px off the edge of the trigger.
An arrow in a popup with a CSS zoom points at the center of its anchor. Its place and arrowPadding are in the pixels of its nearest positioned ancestor. A Select popup over the trigger with a zoom puts the text of the selected item over the text of the value. In the Popover demo of Base UI, a zoom: 2 on the popup moves the arrow 225 px off the center of the trigger.
A press of the mouse on an element outside a popover that is not modal closes the popover at the release, with the reason outside-press, also when the press gives that element the focus. The press and the release decide, so a press that starts outside and ends in the popup closes nothing. In Base UI, a press that moves the focus out of the popup closes the popover at the press, with the reason focus-out. A pressed button takes the focus in Chromium, and not in Firefox and WebKit on macOS, so in Base UI the moment and the reason of the close depend on the browser. The layer reads the press, the release and the click of a mouse in the capture phase of the document, and it closes the popover at the click that follows the release. So a capture listener of the document that stops the click, such as one of a drag library, does not keep the popover open. A developer keeps the popover open with details.cancel() in openChange. In Base UI, a click that such a listener stops before it reaches its target closes nothing.
close() of a handle with no mounted root does nothing and gives no warning: the popup is closed, which is what the call asks for. When two mounted roots have one handle, the root that mounted last has the handle, and the other root gets it back when that root unmounts; the library gives no warning. Base UI warns in a development build in both cases.
A button part knows the element of a component in as or of the element slot only at the mount, and it needs no prop that says what the element is. Until the mount, the element has the attributes that suit a <button> and each other element: type="button", role="button", a tab stop, and the disabled state of both. So in the server HTML, Tab reaches a <div> before a lazy hydration, and a <button> does not submit its form. At the mount, the part keeps the attributes of its element. Base UI needs nativeButton set to false for an element that is not a <button>.

The handbook gives the differences that all components share: Styling, Animation, Composition, Customization, Forms and TypeScript.