Skip to content

Menu ​

A list of actions in a dropdown, with keyboard navigation.

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

const CaretDownIcon: FunctionalComponent = () =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'currentColor',
      style: { display: 'block' },
    },
    [h('path', { d: 'M12 6H4l4 4.5z' })],
  );

const popupHiddenClass = styles.PopupHidden;
</script>

<template>
  <Menu.Root>
    <Menu.Trigger :class="styles.Button">
      Song
      <CaretDownIcon />
    </Menu.Trigger>
    <Menu.Portal>
      <Menu.Positioner :class="styles.Positioner" :side-offset="8" align="start">
        <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
          <Menu.Popup :class="styles.Popup">
            <Menu.Item :class="styles.Item">Add to Library</Menu.Item>
            <Menu.Item :class="styles.Item">Add to Playlist</Menu.Item>
            <Menu.Separator :class="styles.Separator" />
            <Menu.Item :class="styles.Item">Play Next</Menu.Item>
            <Menu.Item :class="styles.Item">Play Last</Menu.Item>
            <Menu.Separator :class="styles.Separator" />
            <Menu.Item :class="styles.Item">Favorite</Menu.Item>
            <Menu.Item :class="styles.Item">Share</Menu.Item>
          </Menu.Popup>
        </Transition>
      </Menu.Positioner>
    </Menu.Portal>
  </Menu.Root>
</template>
css
.Button {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  height: 2rem;
  padding: 0 0.5rem 0 0.75rem;
  margin: 0;
  outline: 0;
  border: 1px solid oklch(14.5% 0 0deg);
  border-radius: 0;
  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] {
    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;
    }
  }
}

.Positioner {
  outline: 0;
}

.Popup {
  box-sizing: border-box;
  position: relative;
  outline: 0;
  padding-block: 0.25rem;
  border: 1px solid oklch(14.5% 0 0deg);
  border-radius: 0;
  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;

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

.Item {
  outline: 0;
  cursor: default;
  -webkit-user-select: none;
  user-select: none;
  padding-block: 0.5rem;
  padding-left: 1rem;
  padding-right: 2rem;
  display: flex;
  font-size: 0.875rem;
  line-height: 1rem;

  &[data-highlighted] {
    z-index: 0;
    position: relative;
    color: white;

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

  &[data-highlighted]::before {
    content: '';
    z-index: -1;
    position: absolute;
    inset-block: 0;
    inset-inline: 0.25rem;
    background-color: oklch(14.5% 0 0deg);

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

  &[aria-disabled="true"] {
    color: oklch(55.6% 0 0deg);

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

.Separator {
  margin: 0.25rem;
  height: 1px;
  background-color: oklch(14.5% 0 0deg);

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

/* The enter-from and leave-to class of the `<Transition>` around the popup. */
.PopupHidden {
  opacity: 0;
  transform: scale(0.98);
}
vue
<script setup lang="ts">
import { h } from 'vue';
import type { FunctionalComponent } from 'vue';
import { Menu } from '@vase-ui/vue/menu';

const CaretDownIcon: FunctionalComponent = () =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'currentColor',
      style: { display: 'block' },
    },
    [h('path', { d: 'M12 6H4l4 4.5z' })],
  );

const itemClass =
  "flex cursor-default py-2 pr-8 pl-4 text-sm leading-4 outline-hidden select-none data-highlighted:relative data-highlighted:z-0 data-highlighted:text-white data-highlighted:before:absolute data-highlighted:before:inset-x-1 data-highlighted:before:inset-y-0 data-highlighted:before:z-[-1] data-highlighted:before:bg-neutral-950 data-highlighted:before:content-[''] aria-disabled:text-neutral-500 dark:data-highlighted:text-neutral-950 dark:data-highlighted:before:bg-white dark:aria-disabled:text-neutral-400";

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

<template>
  <Menu.Root>
    <Menu.Trigger
      class="flex h-8 items-center justify-center gap-1.5 rounded-none border border-neutral-950 bg-white pl-3 pr-2 text-sm leading-none whitespace-nowrap font-normal 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:disabled:border-neutral-400 dark:disabled:text-neutral-400 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"
    >
      Song
      <CaretDownIcon />
    </Menu.Trigger>
    <Menu.Portal>
      <Menu.Positioner class="outline-hidden" :side-offset="8" align="start">
        <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
          <Menu.Popup
            class="relative origin-[var(--transform-origin)] border border-neutral-950 bg-white py-1 text-neutral-950 shadow-[0.25rem_0.25rem_0] shadow-black/12 outline-hidden transition-[scale,opacity] duration-100 ease-out dark:border-white dark:bg-neutral-950 dark:text-white dark:shadow-none"
          >
            <Menu.Item :class="itemClass">Add to Library</Menu.Item>
            <Menu.Item :class="itemClass">Add to Playlist</Menu.Item>
            <Menu.Separator class="mx-1 my-1 h-px bg-neutral-950 dark:bg-white" />
            <Menu.Item :class="itemClass">Play Next</Menu.Item>
            <Menu.Item :class="itemClass">Play Last</Menu.Item>
            <Menu.Separator class="mx-1 my-1 h-px bg-neutral-950 dark:bg-white" />
            <Menu.Item :class="itemClass">Favorite</Menu.Item>
            <Menu.Item :class="itemClass">Share</Menu.Item>
          </Menu.Popup>
        </Transition>
      </Menu.Positioner>
    </Menu.Portal>
  </Menu.Root>
</template>

Anatomy ​

Import the component and assemble its parts:

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

<template>
  <Menu.FilterProvider>
    <Menu.Root>
      <Menu.Trigger />
      <Menu.Portal>
        <Menu.Backdrop />
        <Menu.Positioner>
          <Menu.Popup>
            <Menu.Arrow />
            <Menu.Input />
            <Menu.Clear />
            <Menu.Empty />

            <Menu.List>
              <Menu.Item />
              <Menu.LinkItem />
              <Menu.Separator />

              <Menu.SubmenuRoot>
                <Menu.SubmenuTrigger />
              </Menu.SubmenuRoot>

              <Menu.Group>
                <Menu.GroupLabel />
              </Menu.Group>

              <Menu.RadioGroup>
                <Menu.GroupLabel />
                <Menu.RadioItem value="" />
              </Menu.RadioGroup>

              <Menu.CheckboxItem />
            </Menu.List>

            <Menu.Viewport />
          </Menu.Popup>
        </Menu.Positioner>
      </Menu.Portal>
    </Menu.Root>
  </Menu.FilterProvider>
</template>

Examples ​

Open on hover ​

To open the menu when the pointer is on the trigger, set the openOnHover prop of <Menu.Trigger>. The delay prop gives the time in milliseconds to wait before the menu opens on hover.

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

const CaretDownIcon: FunctionalComponent = () =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'currentColor',
      style: { display: 'block' },
    },
    [h('path', { d: 'M12 6H4l4 4.5z' })],
  );

const popupHiddenClass = styles.PopupHidden;
</script>

<template>
  <Menu.Root>
    <Menu.Trigger open-on-hover :class="styles.Button">
      Add to playlist
      <CaretDownIcon />
    </Menu.Trigger>
    <Menu.Portal>
      <Menu.Positioner :class="styles.Positioner" :side-offset="8" align="start">
        <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
          <Menu.Popup :class="styles.Popup">
            <Menu.Item :class="styles.Item">Get Up!</Menu.Item>
            <Menu.Item :class="styles.Item">Inside Out</Menu.Item>
            <Menu.Item :class="styles.Item">Night Beats</Menu.Item>
            <Menu.Separator :class="styles.Separator" />
            <Menu.Item :class="styles.Item">New playlist…</Menu.Item>
          </Menu.Popup>
        </Transition>
      </Menu.Positioner>
    </Menu.Portal>
  </Menu.Root>
</template>
css
.Button {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  height: 2rem;
  padding: 0 0.5rem 0 0.75rem;
  margin: 0;
  outline: 0;
  border: 1px solid oklch(14.5% 0 0deg);
  border-radius: 0;
  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] {
    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;
    }
  }
}

.Positioner {
  outline: 0;
}

.Popup {
  box-sizing: border-box;
  position: relative;
  outline: 0;
  padding-block: 0.25rem;
  border: 1px solid oklch(14.5% 0 0deg);
  border-radius: 0;
  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;

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

.Item {
  outline: 0;
  cursor: default;
  -webkit-user-select: none;
  user-select: none;
  padding-block: 0.5rem;
  padding-left: 1rem;
  padding-right: 2rem;
  display: flex;
  font-size: 0.875rem;
  line-height: 1rem;

  &[data-highlighted] {
    z-index: 0;
    position: relative;
    color: white;

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

  &[data-highlighted]::before {
    content: '';
    z-index: -1;
    position: absolute;
    inset-block: 0;
    inset-inline: 0.25rem;
    background-color: oklch(14.5% 0 0deg);

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

  &[aria-disabled="true"] {
    color: oklch(55.6% 0 0deg);

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

.Separator {
  margin: 0.25rem;
  height: 1px;
  background-color: oklch(14.5% 0 0deg);

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

/* The enter-from and leave-to class of the `<Transition>` around the popup. */
.PopupHidden {
  opacity: 0;
  transform: scale(0.98);
}
vue
<script setup lang="ts">
import { h } from 'vue';
import type { FunctionalComponent } from 'vue';
import { Menu } from '@vase-ui/vue/menu';

const CaretDownIcon: FunctionalComponent = () =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'currentColor',
      style: { display: 'block' },
    },
    [h('path', { d: 'M12 6H4l4 4.5z' })],
  );

const itemClass =
  "flex cursor-default py-2 pr-8 pl-4 text-sm leading-4 outline-hidden select-none data-highlighted:relative data-highlighted:z-0 data-highlighted:text-white data-highlighted:before:absolute data-highlighted:before:inset-x-1 data-highlighted:before:inset-y-0 data-highlighted:before:z-[-1] data-highlighted:before:bg-neutral-950 data-highlighted:before:content-[''] aria-disabled:text-neutral-500 dark:data-highlighted:text-neutral-950 dark:data-highlighted:before:bg-white dark:aria-disabled:text-neutral-400";

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

<template>
  <Menu.Root>
    <Menu.Trigger
      open-on-hover
      class="flex h-8 items-center justify-center gap-1.5 rounded-none border border-neutral-950 bg-white pl-3 pr-2 text-sm leading-none whitespace-nowrap font-normal 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:disabled:border-neutral-400 dark:disabled:text-neutral-400 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"
    >
      Add to playlist
      <CaretDownIcon />
    </Menu.Trigger>
    <Menu.Portal>
      <Menu.Positioner class="outline-hidden" :side-offset="8" align="start">
        <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
          <Menu.Popup
            class="relative origin-[var(--transform-origin)] border border-neutral-950 bg-white py-1 text-neutral-950 shadow-[0.25rem_0.25rem_0] shadow-black/12 outline-hidden transition-[scale,opacity] duration-100 ease-out dark:border-white dark:bg-neutral-950 dark:text-white dark:shadow-none"
          >
            <Menu.Item :class="itemClass">Get Up!</Menu.Item>
            <Menu.Item :class="itemClass">Inside Out</Menu.Item>
            <Menu.Item :class="itemClass">Night Beats</Menu.Item>
            <Menu.Separator class="mx-1 my-1 h-px bg-neutral-950 dark:bg-white" />
            <Menu.Item :class="itemClass">New playlist…</Menu.Item>
          </Menu.Popup>
        </Transition>
      </Menu.Positioner>
    </Menu.Portal>
  </Menu.Root>
</template>

Checkbox items ​

Use <Menu.CheckboxItem> for an item that turns a setting on or off. Bind its state with v-model. The default slot of the item gets state.checked: show a mark with v-if, or style the item with [aria-checked="true"].

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

const showMinimap = shallowRef(true);
const showSearch = shallowRef(true);
const showSidebar = shallowRef(false);

const CaretDownIcon: FunctionalComponent = () =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'currentColor',
      style: { display: 'block' },
    },
    [h('path', { d: 'M12 6H4l4 4.5z' })],
  );

const CheckIcon: FunctionalComponent = () =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'none',
      stroke: 'currentColor',
      style: { display: 'block' },
    },
    [h('path', { d: 'm2.5 8.5 4 4 7-9' })],
  );

const popupHiddenClass = styles.PopupHidden;
</script>

<template>
  <Menu.Root>
    <Menu.Trigger :class="styles.Button">
      Workspace
      <CaretDownIcon />
    </Menu.Trigger>
    <Menu.Portal>
      <Menu.Positioner :class="styles.Positioner" :side-offset="8" align="start">
        <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
          <Menu.Popup :class="styles.Popup">
            <Menu.CheckboxItem
              v-model="showMinimap"
              :class="styles.CheckboxItem"
              v-slot="{ state }"
            >
              <span v-if="state.checked" :class="styles.CheckboxItemIndicator">
                <CheckIcon />
              </span>
              <span :class="styles.CheckboxItemText">Minimap</span>
            </Menu.CheckboxItem>
            <Menu.CheckboxItem v-model="showSearch" :class="styles.CheckboxItem" v-slot="{ state }">
              <span v-if="state.checked" :class="styles.CheckboxItemIndicator">
                <CheckIcon />
              </span>
              <span :class="styles.CheckboxItemText">Search</span>
            </Menu.CheckboxItem>
            <Menu.CheckboxItem
              v-model="showSidebar"
              :class="styles.CheckboxItem"
              v-slot="{ state }"
            >
              <span v-if="state.checked" :class="styles.CheckboxItemIndicator">
                <CheckIcon />
              </span>
              <span :class="styles.CheckboxItemText">Sidebar</span>
            </Menu.CheckboxItem>
          </Menu.Popup>
        </Transition>
      </Menu.Positioner>
    </Menu.Portal>
  </Menu.Root>
</template>
css
.Button {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  height: 2rem;
  padding: 0 0.5rem 0 0.75rem;
  margin: 0;
  outline: 0;
  border: 1px solid oklch(14.5% 0 0deg);
  border-radius: 0;
  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] {
    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;
    }
  }
}

.Positioner {
  outline: 0;
}

.Popup {
  box-sizing: border-box;
  position: relative;
  outline: 0;
  padding-block: 0.25rem;
  border: 1px solid oklch(14.5% 0 0deg);
  border-radius: 0;
  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;

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

.CheckboxItem {
  outline: 0;
  cursor: default;
  -webkit-user-select: none;
  user-select: none;
  padding-block: 0.5rem;
  padding-left: 0.625rem;
  padding-right: 2rem;
  font-size: 0.875rem;
  line-height: 1rem;

  display: grid;
  gap: 0.5rem;
  align-items: center;
  grid-template-columns: 1rem 1fr;

  &[data-highlighted] {
    z-index: 0;
    position: relative;
    color: white;

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

  &[data-highlighted]::before {
    content: '';
    z-index: -1;
    position: absolute;
    inset-block: 0;
    inset-inline: 0.25rem;
    background-color: oklch(14.5% 0 0deg);

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

  &[aria-disabled="true"] {
    color: oklch(55.6% 0 0deg);

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

.CheckboxItemIndicator {
  grid-column-start: 1;
}

.CheckboxItemText {
  grid-column-start: 2;
}

.Separator {
  margin: 0.25rem;
  height: 1px;
  background-color: oklch(14.5% 0 0deg);

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

/* The enter-from and leave-to class of the `<Transition>` around the popup. */
.PopupHidden {
  opacity: 0;
  transform: scale(0.98);
}
vue
<script setup lang="ts">
import { h, shallowRef } from 'vue';
import type { FunctionalComponent } from 'vue';
import { Menu } from '@vase-ui/vue/menu';

const showMinimap = shallowRef(true);
const showSearch = shallowRef(true);
const showSidebar = shallowRef(false);

const CaretDownIcon: FunctionalComponent = () =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'currentColor',
      style: { display: 'block' },
    },
    [h('path', { d: 'M12 6H4l4 4.5z' })],
  );

const CheckIcon: FunctionalComponent = () =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'none',
      stroke: 'currentColor',
      style: { display: 'block' },
    },
    [h('path', { d: 'm2.5 8.5 4 4 7-9' })],
  );

const checkboxItemClass =
  "grid cursor-default grid-cols-[1rem_1fr] items-center gap-2 py-2 pr-8 pl-2.5 text-sm leading-4 outline-hidden select-none data-highlighted:relative data-highlighted:z-0 data-highlighted:text-white data-highlighted:before:absolute data-highlighted:before:inset-x-1 data-highlighted:before:inset-y-0 data-highlighted:before:z-[-1] data-highlighted:before:bg-neutral-950 data-highlighted:before:content-[''] aria-disabled:text-neutral-500 dark:data-highlighted:text-neutral-950 dark:data-highlighted:before:bg-white dark:aria-disabled:text-neutral-400";

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

<template>
  <Menu.Root>
    <Menu.Trigger
      class="flex h-8 items-center justify-center gap-1.5 rounded-none border border-neutral-950 bg-white pl-3 pr-2 text-sm leading-none whitespace-nowrap font-normal 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:disabled:border-neutral-400 dark:disabled:text-neutral-400 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"
    >
      Workspace
      <CaretDownIcon />
    </Menu.Trigger>
    <Menu.Portal>
      <Menu.Positioner class="outline-hidden" :side-offset="8" align="start">
        <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
          <Menu.Popup
            class="relative origin-[var(--transform-origin)] border border-neutral-950 bg-white py-1 text-neutral-950 shadow-[0.25rem_0.25rem_0] shadow-black/12 outline-hidden transition-[scale,opacity] duration-100 ease-out dark:border-white dark:bg-neutral-950 dark:text-white dark:shadow-none"
          >
            <Menu.CheckboxItem v-model="showMinimap" :class="checkboxItemClass" v-slot="{ state }">
              <span v-if="state.checked" class="col-start-1">
                <CheckIcon />
              </span>
              <span class="col-start-2">Minimap</span>
            </Menu.CheckboxItem>
            <Menu.CheckboxItem v-model="showSearch" :class="checkboxItemClass" v-slot="{ state }">
              <span v-if="state.checked" class="col-start-1">
                <CheckIcon />
              </span>
              <span class="col-start-2">Search</span>
            </Menu.CheckboxItem>
            <Menu.CheckboxItem v-model="showSidebar" :class="checkboxItemClass" v-slot="{ state }">
              <span v-if="state.checked" class="col-start-1">
                <CheckIcon />
              </span>
              <span class="col-start-2">Sidebar</span>
            </Menu.CheckboxItem>
          </Menu.Popup>
        </Transition>
      </Menu.Positioner>
    </Menu.Portal>
  </Menu.Root>
</template>

Radio items ​

Use <Menu.RadioGroup> and <Menu.RadioItem> for items that work like radio buttons. Bind the selected value with v-model on the group. The default slot of each item gets state.checked.

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

const value = shallowRef('date');

const CaretDownIcon: FunctionalComponent = () =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'currentColor',
      style: { display: 'block' },
    },
    [h('path', { d: 'M12 6H4l4 4.5z' })],
  );

const CheckIcon: FunctionalComponent = () =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'none',
      stroke: 'currentColor',
      style: { display: 'block' },
    },
    [h('path', { d: 'm2.5 8.5 4 4 7-9' })],
  );

const popupHiddenClass = styles.PopupHidden;
</script>

<template>
  <Menu.Root>
    <Menu.Trigger :class="styles.Button">
      Sort
      <CaretDownIcon />
    </Menu.Trigger>
    <Menu.Portal>
      <Menu.Positioner :class="styles.Positioner" :side-offset="8" align="start">
        <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
          <Menu.Popup :class="styles.Popup">
            <Menu.RadioGroup v-model="value">
              <Menu.RadioItem :class="styles.RadioItem" value="date" v-slot="{ state }">
                <span v-if="state.checked" :class="styles.RadioItemIndicator">
                  <CheckIcon />
                </span>
                <span :class="styles.RadioItemText">Date</span>
              </Menu.RadioItem>
              <Menu.RadioItem :class="styles.RadioItem" value="name" v-slot="{ state }">
                <span v-if="state.checked" :class="styles.RadioItemIndicator">
                  <CheckIcon />
                </span>
                <span :class="styles.RadioItemText">Name</span>
              </Menu.RadioItem>
              <Menu.RadioItem :class="styles.RadioItem" value="type" v-slot="{ state }">
                <span v-if="state.checked" :class="styles.RadioItemIndicator">
                  <CheckIcon />
                </span>
                <span :class="styles.RadioItemText">Type</span>
              </Menu.RadioItem>
            </Menu.RadioGroup>
          </Menu.Popup>
        </Transition>
      </Menu.Positioner>
    </Menu.Portal>
  </Menu.Root>
</template>
css
.Button {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  height: 2rem;
  padding: 0 0.5rem 0 0.75rem;
  margin: 0;
  outline: 0;
  border: 1px solid oklch(14.5% 0 0deg);
  border-radius: 0;
  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] {
    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;
    }
  }
}

.Positioner {
  outline: 0;
}

.Popup {
  box-sizing: border-box;
  position: relative;
  outline: 0;
  padding-block: 0.25rem;
  border: 1px solid oklch(14.5% 0 0deg);
  border-radius: 0;
  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;

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

.RadioItem {
  outline: 0;
  cursor: default;
  -webkit-user-select: none;
  user-select: none;
  padding-block: 0.5rem;
  padding-left: 0.625rem;
  padding-right: 2rem;
  font-size: 0.875rem;
  line-height: 1rem;
  display: grid;
  gap: 0.5rem;
  align-items: center;
  grid-template-columns: 1rem 1fr;

  &[data-highlighted] {
    z-index: 0;
    position: relative;
    color: white;

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

  &[data-highlighted]::before {
    content: '';
    z-index: -1;
    position: absolute;
    inset-block: 0;
    inset-inline: 0.25rem;
    background-color: oklch(14.5% 0 0deg);

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

  &[aria-disabled="true"] {
    color: oklch(55.6% 0 0deg);

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

.RadioItemIndicator {
  grid-column-start: 1;
}

.RadioItemText {
  grid-column-start: 2;
}

.Separator {
  margin: 0.25rem;
  height: 1px;
  background-color: oklch(14.5% 0 0deg);

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

/* The enter-from and leave-to class of the `<Transition>` around the popup. */
.PopupHidden {
  opacity: 0;
  transform: scale(0.98);
}
vue
<script setup lang="ts">
import { h, shallowRef } from 'vue';
import type { FunctionalComponent } from 'vue';
import { Menu } from '@vase-ui/vue/menu';

const value = shallowRef('date');

const CaretDownIcon: FunctionalComponent = () =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'currentColor',
      style: { display: 'block' },
    },
    [h('path', { d: 'M12 6H4l4 4.5z' })],
  );

const CheckIcon: FunctionalComponent = () =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'none',
      stroke: 'currentColor',
      style: { display: 'block' },
    },
    [h('path', { d: 'm2.5 8.5 4 4 7-9' })],
  );

const radioItemClass =
  "grid cursor-default grid-cols-[1rem_1fr] items-center gap-2 py-2 pr-8 pl-2.5 text-sm leading-4 outline-hidden select-none data-highlighted:relative data-highlighted:z-0 data-highlighted:text-white data-highlighted:before:absolute data-highlighted:before:inset-x-1 data-highlighted:before:inset-y-0 data-highlighted:before:z-[-1] data-highlighted:before:bg-neutral-950 data-highlighted:before:content-[''] aria-disabled:text-neutral-500 dark:data-highlighted:text-neutral-950 dark:data-highlighted:before:bg-white dark:aria-disabled:text-neutral-400";

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

<template>
  <Menu.Root>
    <Menu.Trigger
      class="flex h-8 items-center justify-center gap-1.5 rounded-none border border-neutral-950 bg-white pl-3 pr-2 text-sm leading-none whitespace-nowrap font-normal 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:disabled:border-neutral-400 dark:disabled:text-neutral-400 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"
    >
      Sort
      <CaretDownIcon />
    </Menu.Trigger>
    <Menu.Portal>
      <Menu.Positioner class="outline-hidden" :side-offset="8" align="start">
        <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
          <Menu.Popup
            class="relative origin-[var(--transform-origin)] border border-neutral-950 bg-white py-1 text-neutral-950 shadow-[0.25rem_0.25rem_0] shadow-black/12 outline-hidden transition-[scale,opacity] duration-100 ease-out dark:border-white dark:bg-neutral-950 dark:text-white dark:shadow-none"
          >
            <Menu.RadioGroup v-model="value">
              <Menu.RadioItem :class="radioItemClass" value="date" v-slot="{ state }">
                <span v-if="state.checked" class="col-start-1">
                  <CheckIcon />
                </span>
                <span class="col-start-2">Date</span>
              </Menu.RadioItem>
              <Menu.RadioItem :class="radioItemClass" value="name" v-slot="{ state }">
                <span v-if="state.checked" class="col-start-1">
                  <CheckIcon />
                </span>
                <span class="col-start-2">Name</span>
              </Menu.RadioItem>
              <Menu.RadioItem :class="radioItemClass" value="type" v-slot="{ state }">
                <span v-if="state.checked" class="col-start-1">
                  <CheckIcon />
                </span>
                <span class="col-start-2">Type</span>
              </Menu.RadioItem>
            </Menu.RadioGroup>
          </Menu.Popup>
        </Transition>
      </Menu.Positioner>
    </Menu.Portal>
  </Menu.Root>
</template>

Close on click ​

Use the closeOnClick prop to set whether a click on an item closes the menu. <Menu.Item> closes the menu by default. <Menu.CheckboxItem>, <Menu.RadioItem> and <Menu.LinkItem> keep it open by default.

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

<template>
  <Menu.Root>
    <Menu.Trigger>Actions</Menu.Trigger>
    <Menu.Portal>
      <Menu.Positioner>
        <Menu.Popup>
          <!-- Close the menu when a checkbox item is clicked -->
          <Menu.CheckboxItem close-on-click>Pin</Menu.CheckboxItem>

          <!-- Keep the menu open when an item is clicked -->
          <Menu.Item :close-on-click="false">Refresh</Menu.Item>
        </Menu.Popup>
      </Menu.Positioner>
    </Menu.Portal>
  </Menu.Root>
</template>

Group labels ​

Use <Menu.GroupLabel> to add a label to a <Menu.Group> or a <Menu.RadioGroup>. The group gets its aria-labelledby from the label.

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

const value = shallowRef('date');
const showMinimap = shallowRef(true);
const showSearch = shallowRef(true);
const showSidebar = shallowRef(false);

const CaretDownIcon: FunctionalComponent = () =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'currentColor',
      style: { display: 'block' },
    },
    [h('path', { d: 'M12 6H4l4 4.5z' })],
  );

const CheckIcon: FunctionalComponent = () =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'none',
      stroke: 'currentColor',
      style: { display: 'block' },
    },
    [h('path', { d: 'm2.5 8.5 4 4 7-9' })],
  );

const popupHiddenClass = styles.PopupHidden;
</script>

<template>
  <Menu.Root>
    <Menu.Trigger :class="styles.Button">
      View
      <CaretDownIcon />
    </Menu.Trigger>
    <Menu.Portal>
      <Menu.Positioner :class="styles.Positioner" :side-offset="8" align="start">
        <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
          <Menu.Popup :class="styles.Popup">
            <Menu.RadioGroup v-model="value">
              <Menu.GroupLabel :class="styles.GroupLabel">Sort</Menu.GroupLabel>
              <Menu.RadioItem :class="styles.RadioItem" value="date" v-slot="{ state }">
                <span v-if="state.checked" :class="styles.RadioItemIndicator">
                  <CheckIcon />
                </span>
                <span :class="styles.RadioItemText">Date</span>
              </Menu.RadioItem>
              <Menu.RadioItem :class="styles.RadioItem" value="name" v-slot="{ state }">
                <span v-if="state.checked" :class="styles.RadioItemIndicator">
                  <CheckIcon />
                </span>
                <span :class="styles.RadioItemText">Name</span>
              </Menu.RadioItem>
              <Menu.RadioItem :class="styles.RadioItem" value="type" v-slot="{ state }">
                <span v-if="state.checked" :class="styles.RadioItemIndicator">
                  <CheckIcon />
                </span>
                <span :class="styles.RadioItemText">Type</span>
              </Menu.RadioItem>
            </Menu.RadioGroup>

            <Menu.Separator :class="styles.Separator" />

            <Menu.Group>
              <Menu.GroupLabel :class="styles.GroupLabel">Workspace</Menu.GroupLabel>
              <Menu.CheckboxItem
                v-model="showMinimap"
                :class="styles.CheckboxItem"
                v-slot="{ state }"
              >
                <span v-if="state.checked" :class="styles.CheckboxItemIndicator">
                  <CheckIcon />
                </span>
                <span :class="styles.CheckboxItemText">Minimap</span>
              </Menu.CheckboxItem>
              <Menu.CheckboxItem
                v-model="showSearch"
                :class="styles.CheckboxItem"
                v-slot="{ state }"
              >
                <span v-if="state.checked" :class="styles.CheckboxItemIndicator">
                  <CheckIcon />
                </span>
                <span :class="styles.CheckboxItemText">Search</span>
              </Menu.CheckboxItem>
              <Menu.CheckboxItem
                v-model="showSidebar"
                :class="styles.CheckboxItem"
                v-slot="{ state }"
              >
                <span v-if="state.checked" :class="styles.CheckboxItemIndicator">
                  <CheckIcon />
                </span>
                <span :class="styles.CheckboxItemText">Sidebar</span>
              </Menu.CheckboxItem>
            </Menu.Group>
          </Menu.Popup>
        </Transition>
      </Menu.Positioner>
    </Menu.Portal>
  </Menu.Root>
</template>
css
.Button {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  height: 2rem;
  padding: 0 0.5rem 0 0.75rem;
  margin: 0;
  outline: 0;
  border: 1px solid oklch(14.5% 0 0deg);
  border-radius: 0;
  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] {
    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;
    }
  }
}

.Positioner {
  outline: 0;
}

.Popup {
  box-sizing: border-box;
  position: relative;
  outline: 0;
  padding-block: 0.25rem;
  border: 1px solid oklch(14.5% 0 0deg);
  border-radius: 0;
  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;

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

.CheckboxItem,
.RadioItem {
  outline: 0;
  cursor: default;
  -webkit-user-select: none;
  user-select: none;
  padding-block: 0.5rem;
  padding-left: 0.625rem;
  padding-right: 2rem;
  font-size: 0.875rem;
  line-height: 1rem;
  display: grid;
  gap: 0.5rem;
  align-items: center;
  grid-template-columns: 1rem 1fr;

  &[data-highlighted] {
    z-index: 0;
    position: relative;
    color: white;

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

  &[data-highlighted]::before {
    content: '';
    z-index: -1;
    position: absolute;
    inset-block: 0;
    inset-inline: 0.25rem;
    background-color: oklch(14.5% 0 0deg);

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

  &[aria-disabled="true"] {
    color: oklch(55.6% 0 0deg);

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

.CheckboxItemIndicator,
.RadioItemIndicator {
  grid-column-start: 1;
}

.CheckboxItemText,
.RadioItemText {
  grid-column-start: 2;
}

.Separator {
  margin-block: 0.25rem;
  margin-inline: 0.25rem;
  height: 1px;
  background-color: oklch(14.5% 0 0deg);

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

.GroupLabel {
  -webkit-user-select: none;
  user-select: none;
  padding-block: 0.5rem;
  padding-left: 2.125rem;
  padding-right: 2rem;
  font-size: 0.875rem;
  line-height: 1rem;
  color: oklch(55.6% 0 0deg);

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

/* The enter-from and leave-to class of the `<Transition>` around the popup. */
.PopupHidden {
  opacity: 0;
  transform: scale(0.98);
}
vue
<script setup lang="ts">
import { h, shallowRef } from 'vue';
import type { FunctionalComponent } from 'vue';
import { Menu } from '@vase-ui/vue/menu';

const value = shallowRef('date');
const showMinimap = shallowRef(true);
const showSearch = shallowRef(true);
const showSidebar = shallowRef(false);

const CaretDownIcon: FunctionalComponent = () =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'currentColor',
      style: { display: 'block' },
    },
    [h('path', { d: 'M12 6H4l4 4.5z' })],
  );

const CheckIcon: FunctionalComponent = () =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'none',
      stroke: 'currentColor',
      style: { display: 'block' },
    },
    [h('path', { d: 'm2.5 8.5 4 4 7-9' })],
  );

const itemClass =
  "grid cursor-default grid-cols-[1rem_1fr] items-center gap-2 py-2 pr-8 pl-2.5 text-sm leading-4 outline-hidden select-none data-highlighted:relative data-highlighted:z-0 data-highlighted:text-white data-highlighted:before:absolute data-highlighted:before:inset-x-1 data-highlighted:before:inset-y-0 data-highlighted:before:z-[-1] data-highlighted:before:bg-neutral-950 data-highlighted:before:content-[''] aria-disabled:text-neutral-500 dark:data-highlighted:text-neutral-950 dark:data-highlighted:before:bg-white dark:aria-disabled:text-neutral-400";

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

<template>
  <Menu.Root>
    <Menu.Trigger
      class="flex h-8 items-center justify-center gap-1.5 rounded-none border border-neutral-950 bg-white pl-3 pr-2 text-sm leading-none whitespace-nowrap font-normal 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:disabled:border-neutral-400 dark:disabled:text-neutral-400 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"
    >
      View
      <CaretDownIcon />
    </Menu.Trigger>
    <Menu.Portal>
      <Menu.Positioner class="outline-hidden" :side-offset="8" align="start">
        <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
          <Menu.Popup
            class="relative origin-[var(--transform-origin)] border border-neutral-950 bg-white py-1 text-neutral-950 shadow-[0.25rem_0.25rem_0] shadow-black/12 outline-hidden transition-[scale,opacity] duration-100 ease-out dark:border-white dark:bg-neutral-950 dark:text-white dark:shadow-none"
          >
            <Menu.RadioGroup v-model="value">
              <Menu.GroupLabel
                class="py-2 pr-8 pl-[2.125rem] text-sm leading-4 text-neutral-500 select-none dark:text-neutral-400"
                >Sort</Menu.GroupLabel
              >
              <Menu.RadioItem :class="itemClass" value="date" v-slot="{ state }">
                <span v-if="state.checked" class="col-start-1">
                  <CheckIcon />
                </span>
                <span class="col-start-2">Date</span>
              </Menu.RadioItem>
              <Menu.RadioItem :class="itemClass" value="name" v-slot="{ state }">
                <span v-if="state.checked" class="col-start-1">
                  <CheckIcon />
                </span>
                <span class="col-start-2">Name</span>
              </Menu.RadioItem>
              <Menu.RadioItem :class="itemClass" value="type" v-slot="{ state }">
                <span v-if="state.checked" class="col-start-1">
                  <CheckIcon />
                </span>
                <span class="col-start-2">Type</span>
              </Menu.RadioItem>
            </Menu.RadioGroup>

            <Menu.Separator class="mx-1 my-1 h-px bg-neutral-950 dark:bg-white" />

            <Menu.Group>
              <Menu.GroupLabel
                class="py-2 pr-8 pl-[2.125rem] text-sm leading-4 text-neutral-500 select-none dark:text-neutral-400"
                >Workspace</Menu.GroupLabel
              >
              <Menu.CheckboxItem v-model="showMinimap" :class="itemClass" v-slot="{ state }">
                <span v-if="state.checked" class="col-start-1">
                  <CheckIcon />
                </span>
                <span class="col-start-2">Minimap</span>
              </Menu.CheckboxItem>
              <Menu.CheckboxItem v-model="showSearch" :class="itemClass" v-slot="{ state }">
                <span v-if="state.checked" class="col-start-1">
                  <CheckIcon />
                </span>
                <span class="col-start-2">Search</span>
              </Menu.CheckboxItem>
              <Menu.CheckboxItem v-model="showSidebar" :class="itemClass" v-slot="{ state }">
                <span v-if="state.checked" class="col-start-1">
                  <CheckIcon />
                </span>
                <span class="col-start-2">Sidebar</span>
              </Menu.CheckboxItem>
            </Menu.Group>
          </Menu.Popup>
        </Transition>
      </Menu.Positioner>
    </Menu.Portal>
  </Menu.Root>
</template>

Nested menu ​

To make a submenu, put a <Menu.SubmenuRoot> in the parent menu. Use <Menu.SubmenuTrigger> for the item that opens the nested menu. When the parent menu closes, the popup of an open submenu leaves first.

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

<template>
  <Menu.Root>
    <Menu.Trigger />
    <Menu.Portal>
      <Menu.Positioner>
        <Menu.Popup>
          <Menu.Item />

          <Menu.SubmenuRoot>
            <Menu.SubmenuTrigger />
            <Menu.Portal>
              <Menu.Positioner>
                <Menu.Popup>
                  <Menu.Item />
                </Menu.Popup>
              </Menu.Positioner>
            </Menu.Portal>
          </Menu.SubmenuRoot>
        </Menu.Popup>
      </Menu.Positioner>
    </Menu.Portal>
  </Menu.Root>
</template>
vue
<script setup lang="ts">
import { h } from 'vue';
import type { FunctionalComponent } from 'vue';
import { Menu } from '@vase-ui/vue/menu';
import styles from './index.module.css';

function getOffset({ side }: { side: Menu.Positioner.Props['side'] }) {
  return side === 'top' || side === 'bottom' ? 4 : -4;
}

const CaretDownIcon: FunctionalComponent = () =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'currentColor',
      style: { display: 'block' },
    },
    [h('path', { d: 'M12 6H4l4 4.5z' })],
  );

const CaretRightIcon: FunctionalComponent = () =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'currentColor',
      style: { display: 'block' },
    },
    [h('path', { d: 'M6 12V4l4.5 4z' })],
  );

const popupHiddenClass = styles.PopupHidden;
</script>

<template>
  <Menu.Root>
    <Menu.Trigger :class="styles.Button">
      Song
      <CaretDownIcon />
    </Menu.Trigger>
    <Menu.Portal>
      <Menu.Positioner :class="styles.Positioner" :side-offset="8" align="start">
        <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
          <Menu.Popup :class="styles.Popup">
            <Menu.Item :class="styles.Item">Add to Library</Menu.Item>

            <Menu.SubmenuRoot>
              <Menu.SubmenuTrigger :class="styles.SubmenuTrigger">
                Add to Playlist
                <CaretRightIcon />
              </Menu.SubmenuTrigger>
              <Menu.Portal>
                <Menu.Positioner
                  :class="styles.Positioner"
                  :side-offset="getOffset"
                  :align-offset="getOffset"
                >
                  <Transition
                    :enter-from-class="popupHiddenClass"
                    :leave-to-class="popupHiddenClass"
                  >
                    <Menu.Popup :class="styles.Popup">
                      <Menu.Item :class="styles.Item">Get Up!</Menu.Item>
                      <Menu.Item :class="styles.Item">Inside Out</Menu.Item>
                      <Menu.Item :class="styles.Item">Night Beats</Menu.Item>
                      <Menu.Separator :class="styles.Separator" />
                      <Menu.Item :class="styles.Item">New playlist…</Menu.Item>
                    </Menu.Popup>
                  </Transition>
                </Menu.Positioner>
              </Menu.Portal>
            </Menu.SubmenuRoot>

            <Menu.Separator :class="styles.Separator" />
            <Menu.Item :class="styles.Item">Play Next</Menu.Item>
            <Menu.Item :class="styles.Item">Play Last</Menu.Item>
            <Menu.Separator :class="styles.Separator" />
            <Menu.Item :class="styles.Item">Favorite</Menu.Item>
            <Menu.Item :class="styles.Item">Share</Menu.Item>
          </Menu.Popup>
        </Transition>
      </Menu.Positioner>
    </Menu.Portal>
  </Menu.Root>
</template>
css
.Button {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  height: 2rem;
  padding: 0 0.5rem 0 0.75rem;
  margin: 0;
  outline: 0;
  border: 1px solid oklch(14.5% 0 0deg);
  border-radius: 0;
  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] {
    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;
    }
  }
}

.Positioner {
  outline: 0;
}

.Popup {
  box-sizing: border-box;
  position: relative;
  outline: 0;
  padding-block: 0.25rem;
  border: 1px solid oklch(14.5% 0 0deg);
  border-radius: 0;
  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;

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

.Item,
.SubmenuTrigger {
  outline: 0;
  cursor: default;
  -webkit-user-select: none;
  user-select: none;
  padding-block: 0.5rem;
  padding-left: 1rem;
  padding-right: 1.5rem;
  display: flex;
  font-size: 0.875rem;
  line-height: 1rem;

  &[data-highlighted] {
    z-index: 0;
    position: relative;
    color: white;

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

  &[data-highlighted]::before {
    content: '';
    z-index: -1;
    position: absolute;
    inset-block: 0;
    inset-inline: 0.25rem;
    background-color: oklch(14.5% 0 0deg);

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

  &[aria-disabled="true"] {
    color: oklch(55.6% 0 0deg);

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

.SubmenuTrigger {
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-right: 0.5rem;

  &[data-popup-open] {
    z-index: 0;
    position: relative;
  }

  &[data-popup-open]::before {
    content: '';
    z-index: -1;
    position: absolute;
    inset-block: 0;
    inset-inline: 0.25rem;
    background-color: oklch(97% 0 0deg);

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

  &[data-highlighted][data-popup-open]::before {
    background-color: oklch(14.5% 0 0deg);

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

.Separator {
  margin: 0.25rem;
  height: 1px;
  background-color: oklch(14.5% 0 0deg);

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

/* The enter-from and leave-to class of the `<Transition>` around the popup. */
.PopupHidden {
  opacity: 0;
  transform: scale(0.98);
}
vue
<script setup lang="ts">
import { h } from 'vue';
import type { FunctionalComponent } from 'vue';
import { Menu } from '@vase-ui/vue/menu';

function getOffset({ side }: { side: Menu.Positioner.Props['side'] }) {
  return side === 'top' || side === 'bottom' ? 4 : -4;
}

const CaretDownIcon: FunctionalComponent = () =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'currentColor',
      style: { display: 'block' },
    },
    [h('path', { d: 'M12 6H4l4 4.5z' })],
  );

const CaretRightIcon: FunctionalComponent = () =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'currentColor',
      style: { display: 'block' },
    },
    [h('path', { d: 'M6 12V4l4.5 4z' })],
  );

const popupClass =
  'relative origin-[var(--transform-origin)] border border-neutral-950 bg-white py-1 text-neutral-950 shadow-[0.25rem_0.25rem_0] shadow-black/12 outline-hidden transition-[scale,opacity] duration-100 ease-out dark:border-white dark:bg-neutral-950 dark:text-white dark:shadow-none';
const itemClass =
  "flex cursor-default py-2 pr-6 pl-4 text-sm leading-4 outline-hidden select-none data-highlighted:relative data-highlighted:z-0 data-highlighted:text-white data-highlighted:before:absolute data-highlighted:before:inset-x-1 data-highlighted:before:inset-y-0 data-highlighted:before:z-[-1] data-highlighted:before:bg-neutral-950 data-highlighted:before:content-[''] aria-disabled:text-neutral-500 dark:data-highlighted:text-neutral-950 dark:data-highlighted:before:bg-white dark:aria-disabled:text-neutral-400";
const submenuTriggerClass =
  "flex cursor-default items-center justify-between gap-4 py-2 pr-2 pl-4 text-sm leading-4 outline-hidden select-none data-popup-open:relative data-popup-open:z-0 data-popup-open:before:absolute data-popup-open:before:inset-x-1 data-popup-open:before:inset-y-0 data-popup-open:before:z-[-1] data-popup-open:before:bg-neutral-100 data-popup-open:before:content-[''] data-highlighted:relative data-highlighted:z-0 data-highlighted:text-white data-highlighted:before:absolute data-highlighted:before:inset-x-1 data-highlighted:before:inset-y-0 data-highlighted:before:z-[-1] data-highlighted:before:bg-neutral-950 data-highlighted:before:content-[''] data-highlighted:data-popup-open:before:bg-neutral-950 aria-disabled:text-neutral-500 dark:data-popup-open:before:bg-neutral-800 dark:data-highlighted:text-neutral-950 dark:data-highlighted:before:bg-white dark:data-highlighted:data-popup-open:before:bg-white dark:aria-disabled:text-neutral-400";

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

<template>
  <Menu.Root>
    <Menu.Trigger
      class="flex h-8 items-center justify-center gap-1.5 rounded-none border border-neutral-950 bg-white pl-3 pr-2 text-sm leading-none whitespace-nowrap font-normal 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:disabled:border-neutral-400 dark:disabled:text-neutral-400 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"
    >
      Song
      <CaretDownIcon />
    </Menu.Trigger>
    <Menu.Portal>
      <Menu.Positioner class="outline-hidden" :side-offset="8" align="start">
        <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
          <Menu.Popup :class="popupClass">
            <Menu.Item :class="itemClass">Add to Library</Menu.Item>

            <Menu.SubmenuRoot>
              <Menu.SubmenuTrigger :class="submenuTriggerClass">
                Add to Playlist
                <CaretRightIcon />
              </Menu.SubmenuTrigger>
              <Menu.Portal>
                <Menu.Positioner
                  class="outline-hidden"
                  :side-offset="getOffset"
                  :align-offset="getOffset"
                >
                  <Transition
                    :enter-from-class="popupHiddenClass"
                    :leave-to-class="popupHiddenClass"
                  >
                    <Menu.Popup :class="popupClass">
                      <Menu.Item :class="itemClass">Add to Library</Menu.Item>
                      <Menu.Item :class="itemClass">Add to Playlist</Menu.Item>
                      <Menu.Separator class="mx-1 my-1 h-px bg-neutral-950 dark:bg-white" />
                      <Menu.Item :class="itemClass">Play Next</Menu.Item>
                      <Menu.Item :class="itemClass">Play Last</Menu.Item>
                      <Menu.Separator class="mx-1 my-1 h-px bg-neutral-950 dark:bg-white" />
                      <Menu.Item :class="itemClass">Favorite</Menu.Item>
                      <Menu.Item :class="itemClass">Share</Menu.Item>
                    </Menu.Popup>
                  </Transition>
                </Menu.Positioner>
              </Menu.Portal>
            </Menu.SubmenuRoot>

            <Menu.Separator class="mx-1 my-1 h-px bg-neutral-950 dark:bg-white" />
            <Menu.Item :class="itemClass">Play Next</Menu.Item>
            <Menu.Item :class="itemClass">Play Last</Menu.Item>
            <Menu.Separator class="mx-1 my-1 h-px bg-neutral-950 dark:bg-white" />
            <Menu.Item :class="itemClass">Favorite</Menu.Item>
            <Menu.Item :class="itemClass">Share</Menu.Item>
          </Menu.Popup>
        </Transition>
      </Menu.Positioner>
    </Menu.Portal>
  </Menu.Root>
</template>

Use <Menu.LinkItem> to make a link.

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

<template>
  <Menu.Root>
    <Menu.Trigger>Actions</Menu.Trigger>
    <Menu.Portal>
      <Menu.Positioner>
        <Menu.Popup>
          <Menu.LinkItem href="/projects">Go to Projects</Menu.LinkItem>
        </Menu.Popup>
      </Menu.Positioner>
    </Menu.Portal>
  </Menu.Root>
</template>

Detached triggers ​

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

If the menu cannot be next to its trigger, use a detached trigger. Put <Menu.Trigger> outside <Menu.Root>, and connect the two with a handle from Menu.createHandle(). Only a menu at the top level can have a detached trigger. A submenu has its trigger in its <Menu.SubmenuRoot>.

The methods of the handle, open() and close(), need a mounted <Menu.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 that mounts starts with a new state. 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 { Menu } from '@vase-ui/vue/menu';

const demoMenu = Menu.createHandle();
</script>

<template>
  <Menu.Trigger :handle="demoMenu">Actions</Menu.Trigger>

  <Menu.Root :handle="demoMenu">
    <Menu.Portal>
      <Menu.Positioner>
        <Menu.Popup>
          <Menu.Item>Edit</Menu.Item>
          <Menu.Item>Share</Menu.Item>
        </Menu.Popup>
      </Menu.Positioner>
    </Menu.Portal>
  </Menu.Root>
</template>
vue
<script setup lang="ts">
import { h } from 'vue';
import type { FunctionalComponent } from 'vue';
import { Menu } from '@vase-ui/vue/menu';
import styles from '../../_index.module.css';

const demoMenu = Menu.createHandle();

const EllipsisHorizontalIcon: FunctionalComponent = () =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'currentColor',
      style: { display: 'block' },
    },
    [
      h('circle', { cx: '3', cy: '8', r: '1' }),
      h('circle', { cx: '8', cy: '8', r: '1' }),
      h('circle', { cx: '13', cy: '8', r: '1' }),
    ],
  );

const popupHiddenClass = styles.PopupHidden;
</script>

<template>
  <Menu.Trigger :class="styles.IconButton" :handle="demoMenu" aria-label="Project actions">
    <EllipsisHorizontalIcon />
  </Menu.Trigger>

  <Menu.Root :handle="demoMenu">
    <Menu.Portal>
      <Menu.Positioner :side-offset="8" align="start" :class="styles.Positioner">
        <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
          <Menu.Popup :class="styles.Popup">
            <Menu.Item :class="styles.Item">Rename</Menu.Item>
            <Menu.Item :class="styles.Item">Duplicate</Menu.Item>
            <Menu.Item :class="styles.Item">Move to folder</Menu.Item>
            <Menu.Separator :class="styles.Separator" />
            <Menu.Item :class="styles.Item">Archive</Menu.Item>
            <Menu.Item :class="styles.Item">Delete</Menu.Item>
          </Menu.Popup>
        </Transition>
      </Menu.Positioner>
    </Menu.Portal>
  </Menu.Root>
</template>
css
.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;
    }
  }
}

.Container {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.Button {
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  height: 2rem;
  padding: 0 0.75rem;
  margin: 0;
  outline: 0;
  border: 1px solid oklch(14.5% 0 0deg);
  border-radius: 0;
  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] {
    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;
    }
  }
}

.Positioner {
  outline: 0;
}

.Popup {
  box-sizing: border-box;
  position: relative;
  outline: 0;
  padding-block: 0.25rem;
  border: 1px solid oklch(14.5% 0 0deg);
  border-radius: 0;
  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;

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

.Item {
  outline: 0;
  cursor: default;
  -webkit-user-select: none;
  user-select: none;
  padding-block: 0.5rem;
  padding-left: 1rem;
  padding-right: 2rem;
  display: flex;
  font-size: 0.875rem;
  line-height: 1rem;
  color: inherit;

  &[data-highlighted] {
    z-index: 0;
    position: relative;
    color: white;

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

  &[data-highlighted]::before {
    content: '';
    z-index: -1;
    position: absolute;
    inset-block: 0;
    inset-inline: 0.25rem;
    background-color: oklch(14.5% 0 0deg);

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

  &[aria-disabled="true"] {
    color: oklch(55.6% 0 0deg);

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

.Label {
  -webkit-user-select: none;
  user-select: none;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  line-height: 1rem;
  color: oklch(55.6% 0 0deg);

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

.Separator {
  margin: 0.25rem;
  height: 1px;
  background-color: oklch(14.5% 0 0deg);

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

/* The enter-from and leave-to class of the `<Transition>` around the popup. */
.PopupHidden {
  opacity: 0;
  transform: scale(0.98);
}
vue
<script setup lang="ts">
import { h } from 'vue';
import type { FunctionalComponent } from 'vue';
import { Menu } from '@vase-ui/vue/menu';

const demoMenu = Menu.createHandle();

const EllipsisHorizontalIcon: FunctionalComponent = () =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'currentColor',
      style: { display: 'block' },
    },
    [
      h('circle', { cx: '3', cy: '8', r: '1' }),
      h('circle', { cx: '8', cy: '8', r: '1' }),
      h('circle', { cx: '13', cy: '8', r: '1' }),
    ],
  );

const popupClass =
  'relative origin-[var(--transform-origin)] border border-neutral-950 bg-white py-1 text-neutral-950 shadow-[0.25rem_0.25rem_0] shadow-black/12 outline-hidden transition-[scale,opacity] duration-100 ease-out dark:border-white dark:bg-neutral-950 dark:text-white dark:shadow-none';
const itemClass =
  "flex cursor-default py-2 pr-8 pl-4 text-sm leading-4 outline-hidden select-none data-highlighted:relative data-highlighted:z-0 data-highlighted:text-white data-highlighted:before:absolute data-highlighted:before:inset-x-1 data-highlighted:before:inset-y-0 data-highlighted:before:z-[-1] data-highlighted:before:bg-neutral-950 data-highlighted:before:content-[''] aria-disabled:text-neutral-500 dark:data-highlighted:text-neutral-950 dark:data-highlighted:before:bg-white dark:aria-disabled:text-neutral-400";

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

<template>
  <Menu.Trigger
    class="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:disabled:border-neutral-400 dark:disabled:text-neutral-400 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"
    :handle="demoMenu"
    aria-label="Project actions"
  >
    <EllipsisHorizontalIcon />
  </Menu.Trigger>

  <Menu.Root :handle="demoMenu">
    <Menu.Portal>
      <Menu.Positioner :side-offset="8" align="start" class="outline-hidden">
        <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
          <Menu.Popup :class="popupClass">
            <Menu.Item :class="itemClass">Rename</Menu.Item>
            <Menu.Item :class="itemClass">Duplicate</Menu.Item>
            <Menu.Item :class="itemClass">Move to folder</Menu.Item>
            <Menu.Separator class="mx-1 my-1 h-px bg-neutral-950 dark:bg-white" />
            <Menu.Item :class="itemClass">Archive</Menu.Item>
            <Menu.Item :class="[itemClass, 'text-red-600']">Delete</Menu.Item>
          </Menu.Popup>
        </Transition>
      </Menu.Positioner>
    </Menu.Portal>
  </Menu.Root>
</template>

Multiple triggers ​

One menu can have more than one trigger. Give the same handle to more than one detached trigger, or put more than one <Menu.Trigger> in one <Menu.Root>.

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

<template>
  <Menu.Root>
    <Menu.Trigger>Row actions</Menu.Trigger>
    <Menu.Trigger>Quick actions</Menu.Trigger>
    <Menu.Portal>
      <Menu.Positioner>
        <Menu.Popup>
          <Menu.Item>Edit</Menu.Item>
          <Menu.Item>Share</Menu.Item>
        </Menu.Popup>
      </Menu.Positioner>
    </Menu.Portal>
  </Menu.Root>
</template>
vue
<script setup lang="ts">
import { Menu } from '@vase-ui/vue/menu';

const projectMenu = Menu.createHandle();
</script>

<template>
  <Menu.Trigger :handle="projectMenu">Row actions</Menu.Trigger>

  <Menu.Trigger :handle="projectMenu">Quick actions</Menu.Trigger>

  <Menu.Root :handle="projectMenu">
    <Menu.Portal>
      <Menu.Positioner>
        <Menu.Popup>
          <Menu.Item>Edit</Menu.Item>
          <Menu.Item>Share</Menu.Item>
        </Menu.Popup>
      </Menu.Positioner>
    </Menu.Portal>
  </Menu.Root>
</template>

The menu can show a different content for each trigger. Give a payload to each <Menu.Trigger>. The default slot of <Menu.Root> gets the payload of the active trigger.

The type argument of createHandle() gives the payload its type:

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

const menus = {
  file: ['New', 'Open', 'Save'],
  edit: ['Undo', 'Redo', 'Cut', 'Copy', 'Paste'],
};

const demoMenu = Menu.createHandle<{ items: string[] }>();
</script>

<template>
  <Menu.Trigger :handle="demoMenu" :payload="{ items: menus.file }">File</Menu.Trigger>

  <Menu.Trigger :handle="demoMenu" :payload="{ items: menus.edit }">Edit</Menu.Trigger>

  <Menu.Root v-slot="{ payload }" :handle="demoMenu">
    <Menu.Portal>
      <Menu.Positioner>
        <Menu.Popup>
          <Menu.Viewport>
            <Menu.Item v-for="item in payload?.items ?? []" :key="item">{{ item }}</Menu.Item>
          </Menu.Viewport>
        </Menu.Popup>
      </Menu.Positioner>
    </Menu.Portal>
  </Menu.Root>
</template>

Controlled mode with multiple triggers ​

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

The openChange event gives a second argument, eventDetails. Its trigger is the trigger element that started the change.

vue
<script setup lang="ts">
import { shallowRef } from 'vue';
import { Menu } from '@vase-ui/vue/menu';
import styles from '../../_index.module.css';

const itemGroups = {
  library: [
    { label: 'Add to library', onClick: () => console.log('Adding to library') },
    { label: 'Add to favorites', onClick: () => console.log('Adding to favorites') },
  ],
  playback: [
    { label: 'Play', onClick: () => console.log('Playing') },
    { label: 'Add to queue', onClick: () => console.log('Adding to queue') },
  ],
  share: [
    { label: 'Share', onClick: () => console.log('Sharing') },
    { label: 'Copy link', onClick: () => console.log('Copying link') },
  ],
} as const;

type MenuKey = keyof typeof itemGroups;

const demoMenu = Menu.createHandle<MenuKey>();

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

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

function openPlayback() {
  activeTrigger.value = 'menu-trigger-2';
  open.value = true;
}

const popupHiddenClass = styles.PopupHidden;
</script>

<template>
  <div :class="styles.Container">
    <Menu.Trigger :class="styles.Button" :handle="demoMenu" id="menu-trigger-1" payload="library">
      Library
    </Menu.Trigger>

    <Menu.Trigger :class="styles.Button" :handle="demoMenu" id="menu-trigger-2" payload="playback">
      Playback
    </Menu.Trigger>

    <Menu.Trigger :class="styles.Button" :handle="demoMenu" id="menu-trigger-3" payload="share">
      Share
    </Menu.Trigger>

    <button type="button" :class="styles.Button" @click="openPlayback">
      Open playback (controlled)
    </button>
  </div>

  <Menu.Root
    v-slot="{ payload }"
    :handle="demoMenu"
    :open="open"
    :trigger-id="activeTrigger"
    @open-change="handleOpenChange"
  >
    <Menu.Portal>
      <Menu.Positioner :class="styles.Positioner" :side-offset="8" align="start">
        <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
          <Menu.Popup :class="styles.Popup">
            <template v-if="payload">
              <Menu.Item
                v-for="item in itemGroups[payload]"
                :key="item.label"
                :class="styles.Item"
                @click="item.onClick"
              >
                {{ item.label }}
              </Menu.Item>
            </template>
          </Menu.Popup>
        </Transition>
      </Menu.Positioner>
    </Menu.Portal>
  </Menu.Root>
</template>
css
.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;
    }
  }
}

.Container {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.Button {
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  height: 2rem;
  padding: 0 0.75rem;
  margin: 0;
  outline: 0;
  border: 1px solid oklch(14.5% 0 0deg);
  border-radius: 0;
  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] {
    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;
    }
  }
}

.Positioner {
  outline: 0;
}

.Popup {
  box-sizing: border-box;
  position: relative;
  outline: 0;
  padding-block: 0.25rem;
  border: 1px solid oklch(14.5% 0 0deg);
  border-radius: 0;
  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;

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

.Item {
  outline: 0;
  cursor: default;
  -webkit-user-select: none;
  user-select: none;
  padding-block: 0.5rem;
  padding-left: 1rem;
  padding-right: 2rem;
  display: flex;
  font-size: 0.875rem;
  line-height: 1rem;
  color: inherit;

  &[data-highlighted] {
    z-index: 0;
    position: relative;
    color: white;

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

  &[data-highlighted]::before {
    content: '';
    z-index: -1;
    position: absolute;
    inset-block: 0;
    inset-inline: 0.25rem;
    background-color: oklch(14.5% 0 0deg);

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

  &[aria-disabled="true"] {
    color: oklch(55.6% 0 0deg);

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

.Label {
  -webkit-user-select: none;
  user-select: none;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  line-height: 1rem;
  color: oklch(55.6% 0 0deg);

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

.Separator {
  margin: 0.25rem;
  height: 1px;
  background-color: oklch(14.5% 0 0deg);

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

/* The enter-from and leave-to class of the `<Transition>` around the popup. */
.PopupHidden {
  opacity: 0;
  transform: scale(0.98);
}
vue
<script setup lang="ts">
import { shallowRef } from 'vue';
import { Menu } from '@vase-ui/vue/menu';

const itemGroups = {
  library: [
    { label: 'Add to library', onClick: () => console.log('Adding to library') },
    { label: 'Add to favorites', onClick: () => console.log('Adding to favorites') },
  ],
  playback: [
    { label: 'Play', onClick: () => console.log('Playing') },
    { label: 'Add to queue', onClick: () => console.log('Adding to queue') },
  ],
  share: [
    { label: 'Share', onClick: () => console.log('Sharing') },
    { label: 'Copy link', onClick: () => console.log('Copying link') },
  ],
} as const;

type MenuKey = keyof typeof itemGroups;

const demoMenu = Menu.createHandle<MenuKey>();

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

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

function openPlayback() {
  activeTrigger.value = 'menu-trigger-2';
  open.value = true;
}

const itemClass =
  "flex cursor-default py-2 pr-8 pl-4 text-sm leading-4 outline-hidden select-none data-highlighted:relative data-highlighted:z-0 data-highlighted:text-white data-highlighted:before:absolute data-highlighted:before:inset-x-1 data-highlighted:before:inset-y-0 data-highlighted:before:z-[-1] data-highlighted:before:bg-neutral-950 data-highlighted:before:content-[''] aria-disabled:text-neutral-500 dark:data-highlighted:text-neutral-950 dark:data-highlighted:before:bg-white dark:aria-disabled:text-neutral-400";
const triggerClass =
  'flex h-8 items-center justify-center gap-2 rounded-none border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:bg-neutral-100 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white active:bg-neutral-200 data-pressed:bg-neutral-100 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:bg-neutral-800 dark:active:bg-neutral-700 dark:data-pressed:bg-neutral-800';
const popupClass =
  'relative origin-[var(--transform-origin)] border border-neutral-950 bg-white py-1 text-neutral-950 shadow-[0.25rem_0.25rem_0] shadow-black/12 outline-hidden transition-[scale,opacity] duration-100 ease-out dark:border-white dark:bg-neutral-950 dark:text-white dark:shadow-none';

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

<template>
  <div class="flex flex-wrap items-center gap-2">
    <Menu.Trigger :class="triggerClass" :handle="demoMenu" id="menu-trigger-1" payload="library">
      Library
    </Menu.Trigger>

    <Menu.Trigger :class="triggerClass" :handle="demoMenu" id="menu-trigger-2" payload="playback">
      Playback
    </Menu.Trigger>

    <Menu.Trigger :class="triggerClass" :handle="demoMenu" id="menu-trigger-3" payload="share">
      Share
    </Menu.Trigger>

    <button type="button" :class="triggerClass" @click="openPlayback">
      Open playback (controlled)
    </button>
  </div>

  <Menu.Root
    v-slot="{ payload }"
    :handle="demoMenu"
    :open="open"
    :trigger-id="activeTrigger"
    @open-change="handleOpenChange"
  >
    <Menu.Portal>
      <Menu.Positioner class="outline-hidden" :side-offset="8" align="start">
        <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
          <Menu.Popup :class="popupClass">
            <template v-if="payload">
              <Menu.Item
                v-for="item in itemGroups[payload]"
                :key="item.label"
                :class="itemClass"
                @click="item.onClick"
              >
                {{ item.label }}
              </Menu.Item>
            </template>
          </Menu.Popup>
        </Transition>
      </Menu.Positioner>
    </Menu.Portal>
  </Menu.Root>
</template>

Arrow ​

Use <Menu.Arrow> in the popup to connect the menu to its trigger.

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

const CaretDownIcon: FunctionalComponent = () =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'currentColor',
      style: { display: 'block' },
    },
    [h('path', { d: 'M12 6H4l4 4.5z' })],
  );

const popupHiddenClass = styles.PopupHidden;
</script>

<template>
  <Menu.Root>
    <Menu.Trigger :class="styles.Button">
      Song
      <CaretDownIcon />
    </Menu.Trigger>
    <Menu.Portal>
      <Menu.Positioner
        :class="styles.Positioner"
        :side-offset="({ side }) => (side === 'top' ? 12 : 8)"
      >
        <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
          <Menu.Popup :class="styles.Popup">
            <Menu.Arrow :class="styles.Arrow" />
            <Menu.Item :class="styles.Item">Add to Library</Menu.Item>
            <Menu.Item :class="styles.Item">Add to Playlist</Menu.Item>
            <Menu.Separator :class="styles.Separator" />
            <Menu.Item :class="styles.Item">Play Next</Menu.Item>
            <Menu.Item :class="styles.Item">Play Last</Menu.Item>
            <Menu.Separator :class="styles.Separator" />
            <Menu.Item :class="styles.Item">Favorite</Menu.Item>
            <Menu.Item :class="styles.Item">Share</Menu.Item>
          </Menu.Popup>
        </Transition>
      </Menu.Positioner>
    </Menu.Portal>
  </Menu.Root>
</template>
css
.Button {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  height: 2rem;
  padding: 0 0.5rem 0 0.75rem;
  margin: 0;
  outline: 0;
  border: 1px solid oklch(14.5% 0 0deg);
  border-radius: 0;
  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] {
    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;
    }
  }
}

.Positioner {
  outline: 0;
}

.Popup {
  box-sizing: border-box;
  position: relative;
  outline: 0;
  padding-block: 0.25rem;
  border: 1px solid oklch(14.5% 0 0deg);
  border-radius: 0;
  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;

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

.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;
    }
  }
}

.Item {
  outline: 0;
  cursor: default;
  -webkit-user-select: none;
  user-select: none;
  padding-block: 0.5rem;
  padding-left: 1rem;
  padding-right: 2rem;
  display: flex;
  font-size: 0.875rem;
  line-height: 1rem;

  &[data-highlighted] {
    z-index: 0;
    position: relative;
    color: white;

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

  &[data-highlighted]::before {
    content: '';
    z-index: -1;
    position: absolute;
    inset-block: 0;
    inset-inline: 0.25rem;
    background-color: oklch(14.5% 0 0deg);

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

.Separator {
  margin: 0.25rem;
  height: 1px;
  background-color: oklch(14.5% 0 0deg);

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

/* The enter-from and leave-to class of the `<Transition>` around the popup. */
.PopupHidden {
  opacity: 0;
  transform: scale(0.98);
}
vue
<script setup lang="ts">
import { h } from 'vue';
import type { FunctionalComponent } from 'vue';
import { Menu } from '@vase-ui/vue/menu';

const CaretDownIcon: FunctionalComponent = () =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'currentColor',
      style: { display: 'block' },
    },
    [h('path', { d: 'M12 6H4l4 4.5z' })],
  );

const itemClass =
  "flex cursor-default py-2 pr-8 pl-4 text-sm leading-4 outline-hidden select-none data-highlighted:relative data-highlighted:z-0 data-highlighted:text-white data-highlighted:before:absolute data-highlighted:before:inset-x-1 data-highlighted:before:inset-y-0 data-highlighted:before:z-[-1] data-highlighted:before:bg-neutral-950 data-highlighted:before:content-[''] dark:data-highlighted:text-neutral-950 dark:data-highlighted:before:bg-white";

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

<template>
  <Menu.Root>
    <Menu.Trigger
      class="flex h-8 items-center justify-center gap-1.5 rounded-none border border-neutral-950 bg-white pl-3 pr-2 text-sm leading-none whitespace-nowrap font-normal 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:disabled:border-neutral-400 dark:disabled:text-neutral-400 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"
    >
      Song
      <CaretDownIcon />
    </Menu.Trigger>
    <Menu.Portal>
      <Menu.Positioner
        class="outline-hidden"
        :side-offset="({ side }) => (side === 'top' ? 12 : 8)"
      >
        <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
          <Menu.Popup
            class="relative origin-[var(--transform-origin)] border border-neutral-950 bg-white py-1 text-neutral-950 shadow-[0.25rem_0.25rem_0] shadow-black/12 outline-hidden transition-[scale,opacity] duration-100 ease-out dark:border-white dark:bg-neutral-950 dark:text-white dark:shadow-none"
          >
            <Menu.Arrow
              class="relative block h-1.5 w-3 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:absolute before:bottom-0 before:left-1/2 before:h-[calc(6px*sqrt(2))] before:w-[calc(6px*sqrt(2))] before:[transform:translate(-50%,50%)_rotate(45deg)] before:border before:border-neutral-950 before:bg-white before:content-[''] dark:before:border-white dark:before:bg-neutral-950"
            />
            <Menu.Item :class="itemClass">Add to Library</Menu.Item>
            <Menu.Item :class="itemClass">Add to Playlist</Menu.Item>
            <Menu.Separator class="m-1 h-px bg-neutral-950 dark:bg-white" />
            <Menu.Item :class="itemClass">Play Next</Menu.Item>
            <Menu.Item :class="itemClass">Play Last</Menu.Item>
            <Menu.Separator class="m-1 h-px bg-neutral-950 dark:bg-white" />
            <Menu.Item :class="itemClass">Favorite</Menu.Item>
            <Menu.Item :class="itemClass">Share</Menu.Item>
          </Menu.Popup>
        </Transition>
      </Menu.Positioner>
    </Menu.Portal>
  </Menu.Root>
</template>

Animating the Menu ​

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

Position and size ​

To animate the position, add CSS transitions for left, right, top and bottom to the Positioner part. To animate the size, add transitions for width and height to the Popup part.

Content ​

A menu can animate its content when each trigger has a different content.

Put the content in <Menu.Viewport>. Its div has the data-activation-direction attribute, which gives the position of the new trigger relative to the old trigger. The value has at most two tokens, one for each axis: left or right, and up or down, for example right down. Match one token with the ~= attribute selector, such as [data-activation-direction~='right'].

The default slot of <Menu.Viewport> gets triggerId, the id of the active trigger. Put the content in a <Transition>, and give it the triggerId as its key. At a move, Vue keeps the old content for its leave while the new content enters. Select the old content with the leave classes.

Use Menu.Viewport only when one popup has more than one trigger, the content changes with the trigger, and the change is animated. With a viewport, set width: var(--positioner-width) and height: var(--positioner-height) on the Positioner. Its box 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 { Menu } from '@vase-ui/vue/menu';
import styles from '../../_index.module.css';
import transitionStyles from './index.module.css';

type MenuContent = {
  heading: string;
  groups: string[][];
};

const MENUS = {
  library: {
    heading: 'Library',
    groups: [
      ['Add to library', 'Add to favorites'],
      ['Create playlist', 'Create station'],
    ],
  },
  playback: {
    heading: 'Playback',
    groups: [
      ['Play now', 'Add to queue'],
      ['Play next', 'Play last', 'Sleep timer'],
    ],
  },
  share: {
    heading: 'Share',
    groups: [
      ['Copy link', 'Copy embed code'],
      ['Share to contacts', 'Share to social'],
    ],
  },
} as const satisfies Record<string, MenuContent>;

type MenuKey = keyof typeof MENUS;

const demoMenu = Menu.createHandle<MenuKey>();

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

<template>
  <div :class="styles.Container">
    <Menu.Trigger :class="styles.Button" :handle="demoMenu" payload="library">Library</Menu.Trigger>
    <Menu.Trigger :class="styles.Button" :handle="demoMenu" payload="playback">
      Playback
    </Menu.Trigger>
    <Menu.Trigger :class="styles.Button" :handle="demoMenu" payload="share">Share</Menu.Trigger>

    <Menu.Root v-slot="{ payload }" :handle="demoMenu" :modal="false">
      <Menu.Portal>
        <Menu.Positioner
          :side-offset="8"
          align="start"
          :class="[styles.Positioner, transitionStyles.Positioner]"
        >
          <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
            <Menu.Popup :class="[styles.Popup, transitionStyles.Popup]">
              <Menu.Viewport v-slot="{ triggerId }" :class="transitionStyles.Viewport">
                <Transition
                  :enter-from-class="contentEnterFromClass"
                  :leave-active-class="contentLeavingClass"
                  :leave-to-class="contentLeaveToClass"
                >
                  <div :key="triggerId ?? ''" :class="transitionStyles.Content">
                    <template v-if="payload">
                      <template
                        v-for="(group, groupIndex) in MENUS[payload].groups"
                        :key="groupIndex"
                      >
                        <Menu.Group>
                          <Menu.GroupLabel v-if="groupIndex === 0" :class="styles.Label">
                            {{ MENUS[payload].heading }}
                          </Menu.GroupLabel>
                          <Menu.Item v-for="item in group" :key="item" :class="styles.Item">
                            {{ item }}
                          </Menu.Item>
                        </Menu.Group>
                        <Menu.Separator
                          v-if="groupIndex < MENUS[payload].groups.length - 1"
                          :class="styles.Separator"
                        />
                      </template>
                    </template>
                  </div>
                </Transition>
              </Menu.Viewport>
            </Menu.Popup>
          </Transition>
        </Menu.Positioner>
      </Menu.Portal>
    </Menu.Root>
  </div>
</template>
css
.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;
    }
  }
}

.Container {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.Button {
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  height: 2rem;
  padding: 0 0.75rem;
  margin: 0;
  outline: 0;
  border: 1px solid oklch(14.5% 0 0deg);
  border-radius: 0;
  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] {
    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;
    }
  }
}

.Positioner {
  outline: 0;
}

.Popup {
  box-sizing: border-box;
  position: relative;
  outline: 0;
  padding-block: 0.25rem;
  border: 1px solid oklch(14.5% 0 0deg);
  border-radius: 0;
  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;

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

.Item {
  outline: 0;
  cursor: default;
  -webkit-user-select: none;
  user-select: none;
  padding-block: 0.5rem;
  padding-left: 1rem;
  padding-right: 2rem;
  display: flex;
  font-size: 0.875rem;
  line-height: 1rem;
  color: inherit;

  &[data-highlighted] {
    z-index: 0;
    position: relative;
    color: white;

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

  &[data-highlighted]::before {
    content: '';
    z-index: -1;
    position: absolute;
    inset-block: 0;
    inset-inline: 0.25rem;
    background-color: oklch(14.5% 0 0deg);

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

  &[aria-disabled="true"] {
    color: oklch(55.6% 0 0deg);

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

.Label {
  -webkit-user-select: none;
  user-select: none;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  line-height: 1rem;
  color: oklch(55.6% 0 0deg);

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

.Separator {
  margin: 0.25rem;
  height: 1px;
  background-color: oklch(14.5% 0 0deg);

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

/* The enter-from and leave-to class of the `<Transition>` around the popup. */
.PopupHidden {
  opacity: 0;
  transform: scale(0.98);
}
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;
  width: var(--popup-width, auto);
  height: var(--popup-height, auto);

  transition-property: width, height, opacity, transform;
  transition-timing-function: var(--easing);
  transition-duration: var(--animation-duration);

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

.Viewport {
  box-sizing: border-box;
  position: relative;
  overflow: clip;
  width: 100%;
  height: 100%;
  padding: 0;

  .Content {
    width: var(--popup-width);
    transform: translateX(0);
    opacity: 1;
    transition:
      transform var(--animation-duration) var(--easing),
      opacity calc(var(--animation-duration) / 2) var(--easing);
  }

  /* The old content leaves over the new one. */
  .ContentLeaving {
    position: absolute;
    top: 0;
    left: 0;
  }

  &[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;
  }
}

/* The enter-from and leave-to class of the `<Transition>` around the popup. */
.PopupHidden {
  opacity: 0;
  transform: scale(0.9);
}
vue
<script setup lang="ts">
import { Menu } from '@vase-ui/vue/menu';

type MenuContent = {
  heading: string;
  groups: string[][];
};

const MENUS = {
  library: {
    heading: 'Library',
    groups: [
      ['Add to library', 'Add to favorites'],
      ['Create playlist', 'Create station'],
    ],
  },
  playback: {
    heading: 'Playback',
    groups: [
      ['Play now', 'Add to queue'],
      ['Play next', 'Play last', 'Sleep timer'],
    ],
  },
  share: {
    heading: 'Share',
    groups: [
      ['Copy link', 'Copy embed code'],
      ['Share to contacts', 'Share to social'],
    ],
  },
} as const satisfies Record<string, MenuContent>;

type MenuKey = keyof typeof MENUS;

const demoMenu = Menu.createHandle<MenuKey>();

const triggerClass = `
  flex h-8 items-center justify-center
  rounded-none border border-neutral-950 bg-white
  px-3 text-sm font-normal text-neutral-950
  select-none
  hover:bg-neutral-100 active:bg-neutral-200 data-pressed:bg-neutral-100
  dark:border-white dark:bg-neutral-950 dark:text-white
  dark:hover:bg-neutral-800 dark:active:bg-neutral-700 dark:data-pressed:bg-neutral-800
  focus-visible:outline focus-visible:outline-2
  focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white
`;
const itemClass = `
  flex cursor-default py-2 pr-8 pl-4
  text-sm leading-4 outline-none select-none
  data-highlighted:relative data-highlighted:z-0 data-highlighted:text-white
  data-highlighted:before:absolute data-highlighted:before:inset-x-1
  data-highlighted:before:inset-y-0 data-highlighted:before:z-[-1]
  data-highlighted:before:bg-neutral-950 data-highlighted:before:content-['']
  dark:data-highlighted:text-neutral-950 dark:data-highlighted:before:bg-white
`;

const popupHiddenClass = 'scale-90 opacity-0';
// 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-0 left-0';
const contentLeaveToClass =
  'opacity-0 group-data-[activation-direction~=left]:translate-x-1/2 group-data-[activation-direction~=right]:-translate-x-1/2';
</script>

<template>
  <div class="flex flex-wrap items-center gap-2">
    <Menu.Trigger :class="triggerClass" :handle="demoMenu" payload="library">Library</Menu.Trigger>
    <Menu.Trigger :class="triggerClass" :handle="demoMenu" payload="playback">
      Playback
    </Menu.Trigger>
    <Menu.Trigger :class="triggerClass" :handle="demoMenu" payload="share">Share</Menu.Trigger>

    <Menu.Root v-slot="{ payload }" :handle="demoMenu" :modal="false">
      <Menu.Portal>
        <Menu.Positioner
          :side-offset="8"
          align="start"
          class="outline-none 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">
            <Menu.Popup
              class="relative h-[var(--popup-height,auto)] w-[var(--popup-width,auto)] py-1 origin-[var(--transform-origin)] border border-neutral-950 bg-white text-neutral-950 shadow-[0.25rem_0.25rem_0] shadow-black/12 outline-none transition-[width,height,opacity,scale] duration-[0.35s] ease-[cubic-bezier(0.22,1,0.36,1)] data-instant:transition-none dark:border-white dark:bg-neutral-950 dark:text-white dark:shadow-none"
            >
              <Menu.Viewport
                v-slot="{ triggerId }"
                class="group relative h-full w-full overflow-clip p-0"
              >
                <Transition
                  :enter-from-class="contentEnterFromClass"
                  :leave-active-class="contentLeavingClass"
                  :leave-to-class="contentLeaveToClass"
                >
                  <div
                    :key="triggerId ?? ''"
                    class="w-[var(--popup-width)] transition-[translate,opacity] duration-[350ms,175ms] ease-[cubic-bezier(0.22,1,0.36,1)]"
                  >
                    <template v-if="payload">
                      <template
                        v-for="(group, groupIndex) in MENUS[payload].groups"
                        :key="groupIndex"
                      >
                        <Menu.Group>
                          <Menu.GroupLabel
                            v-if="groupIndex === 0"
                            class="px-4 py-2 text-sm leading-4 text-neutral-500 select-none dark:text-neutral-400"
                          >
                            {{ MENUS[payload].heading }}
                          </Menu.GroupLabel>
                          <Menu.Item v-for="item in group" :key="item" :class="itemClass">
                            {{ item }}
                          </Menu.Item>
                        </Menu.Group>
                        <Menu.Separator
                          v-if="groupIndex < MENUS[payload].groups.length - 1"
                          class="mx-1 my-1 h-px bg-neutral-950 dark:bg-white"
                        />
                      </template>
                    </template>
                  </div>
                </Transition>
              </Menu.Viewport>
            </Menu.Popup>
          </Transition>
        </Menu.Positioner>
      </Menu.Portal>
    </Menu.Root>
  </div>
</template>

Filtering Preview ​

Wrap <Menu.Root> in <Menu.FilterProvider>, add <Menu.Input> to the popup, and put the items in <Menu.List>.

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

<template>
  <Menu.FilterProvider>
    <Menu.Root>
      <Menu.Trigger>Actions</Menu.Trigger>
      <Menu.Portal>
        <Menu.Positioner>
          <Menu.Popup>
            <Menu.Input aria-label="Filter actions" />
            <Menu.Clear>Clear</Menu.Clear>
            <Menu.Empty>No results.</Menu.Empty>
            <Menu.List>
              <Menu.Item>Rename</Menu.Item>
              <Menu.Item>Delete</Menu.Item>
            </Menu.List>
          </Menu.Popup>
        </Menu.Positioner>
      </Menu.Portal>
    </Menu.Root>
  </Menu.FilterProvider>
</template>

Label the input with aria-label, aria-labelledby or a visible <label>. Type to narrow the actions, then use the arrow keys to move through the items that match.

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

const sharingOptions = [
  'Email',
  'Messages',
  'AirDrop',
  'Copy link',
  'Invite collaborators',
  'Publish to web',
  'Send a copy',
];

const folderOptions = [
  'Desktop',
  'Documents',
  'Downloads',
  'Projects',
  'Archive',
  'Shared',
  'Trash',
];

const exportOptions = [
  'PDF document',
  'Word document',
  'Plain text',
  'Rich text',
  'Markdown',
  'HTML page',
  'Image',
];

const sortOptions = [
  ['date', 'Date modified'],
  ['name', 'Name'],
  ['size', 'Size'],
] as const;

function getSubmenuOffset({ side }: { side: Menu.Positioner.Props['side'] }) {
  return side === 'top' || side === 'bottom' ? 4 : -4;
}

const CaretDownIcon: FunctionalComponent = () =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'currentColor',
      style: { display: 'block' },
    },
    [h('path', { d: 'M12 6H4l4 4.5z' })],
  );

const ClearIcon: FunctionalComponent = () =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'none',
      stroke: 'currentColor',
      style: { display: 'block' },
    },
    [h('path', { d: 'm3.5 3.5 9 9m0-9-9 9' })],
  );

const CaretRightIcon: FunctionalComponent = () =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'currentColor',
      style: { display: 'block' },
    },
    [h('path', { d: 'M6 12V4l4.5 4z' })],
  );

const CheckIcon: FunctionalComponent = () =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'none',
      stroke: 'currentColor',
      style: { display: 'block' },
    },
    [h('path', { d: 'm2.5 8.5 4 4 7-9' })],
  );

const popupHiddenClass = styles.PopupHidden;
</script>

<template>
  <Menu.FilterProvider>
    <Menu.Root>
      <Menu.Trigger :class="styles.Trigger">
        Actions
        <CaretDownIcon />
      </Menu.Trigger>
      <Menu.Portal>
        <Menu.Positioner :class="styles.Positioner" :side-offset="8" align="start">
          <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
            <Menu.Popup :class="styles.Popup">
              <div :class="styles.InputContainer">
                <Menu.Input
                  :class="styles.Input"
                  aria-label="Filter actions"
                  placeholder="e.g. Save"
                />
                <Menu.Clear :class="styles.Clear">
                  <ClearIcon />
                </Menu.Clear>
              </div>
              <Menu.Empty :class="styles.Empty">No actions found.</Menu.Empty>
              <Menu.List :class="styles.List">
                <Menu.Group :class="styles.Section">
                  <Menu.GroupLabel :class="styles.GroupLabel">File</Menu.GroupLabel>
                  <Menu.Item :class="styles.Item">New file</Menu.Item>
                  <Menu.Item :class="styles.Item">Open file</Menu.Item>
                  <Menu.Item :class="styles.Item">Save</Menu.Item>
                  <Menu.Item :class="styles.Item">Save as</Menu.Item>
                  <Menu.Item :class="styles.Item">Duplicate</Menu.Item>
                  <Menu.Item :class="styles.Item">Rename</Menu.Item>
                </Menu.Group>
                <Menu.Group :class="styles.Section">
                  <Menu.GroupLabel :class="styles.GroupLabel">Organize</Menu.GroupLabel>
                  <FilterableSubmenu
                    label="Move to folder"
                    input-label="Filter folders"
                    placeholder="e.g. Projects"
                    empty-text="No folders found."
                    :options="folderOptions"
                  />
                  <Menu.SubmenuRoot>
                    <Menu.SubmenuTrigger :class="styles.SubmenuTrigger">
                      Share
                      <CaretRightIcon />
                    </Menu.SubmenuTrigger>
                    <Menu.Portal>
                      <Menu.Positioner
                        :class="styles.Positioner"
                        :side-offset="getSubmenuOffset"
                        :align-offset="getSubmenuOffset"
                      >
                        <Transition
                          :enter-from-class="popupHiddenClass"
                          :leave-to-class="popupHiddenClass"
                        >
                          <Menu.Popup :class="styles.Popup">
                            <Menu.List :class="[styles.List, styles.SubmenuList]">
                              <Menu.Item
                                v-for="option in sharingOptions"
                                :key="option"
                                :class="styles.Item"
                              >
                                {{ option }}
                              </Menu.Item>
                            </Menu.List>
                          </Menu.Popup>
                        </Transition>
                      </Menu.Positioner>
                    </Menu.Portal>
                  </Menu.SubmenuRoot>
                  <FilterableSubmenu
                    label="Export"
                    input-label="Filter export formats"
                    placeholder="e.g. PDF"
                    empty-text="No export formats found."
                    :options="exportOptions"
                  />
                  <Menu.Item :class="styles.Item">Download a copy</Menu.Item>
                  <Menu.Item :class="styles.Item">Delete</Menu.Item>
                </Menu.Group>

                <Menu.RadioGroup :class="styles.Section" default-value="date">
                  <Menu.Separator :class="styles.Separator" />
                  <Menu.GroupLabel :class="styles.GroupLabel">Sort by</Menu.GroupLabel>
                  <Menu.RadioItem
                    v-for="[value, label] in sortOptions"
                    :key="value"
                    :class="styles.ChoiceItem"
                    :value="value"
                    v-slot="{ state }"
                  >
                    <span v-if="state.checked" :class="styles.ChoiceIndicator">
                      <CheckIcon />
                    </span>
                    <span :class="styles.ChoiceText">{{ label }}</span>
                  </Menu.RadioItem>
                </Menu.RadioGroup>

                <Menu.Group :class="styles.Section">
                  <Menu.Separator :class="styles.Separator" />
                  <Menu.GroupLabel :class="styles.GroupLabel">View</Menu.GroupLabel>
                  <Menu.CheckboxItem :class="styles.ChoiceItem" default-checked v-slot="{ state }">
                    <span v-if="state.checked" :class="styles.ChoiceIndicator">
                      <CheckIcon />
                    </span>
                    <span :class="styles.ChoiceText">Show details</span>
                  </Menu.CheckboxItem>
                  <Menu.CheckboxItem :class="styles.ChoiceItem" v-slot="{ state }">
                    <span v-if="state.checked" :class="styles.ChoiceIndicator">
                      <CheckIcon />
                    </span>
                    <span :class="styles.ChoiceText">Show sidebar</span>
                  </Menu.CheckboxItem>
                  <Menu.CheckboxItem :class="styles.ChoiceItem" v-slot="{ state }">
                    <span v-if="state.checked" :class="styles.ChoiceIndicator">
                      <CheckIcon />
                    </span>
                    <span :class="styles.ChoiceText">Keep available offline</span>
                  </Menu.CheckboxItem>
                </Menu.Group>
              </Menu.List>
            </Menu.Popup>
          </Transition>
        </Menu.Positioner>
      </Menu.Portal>
    </Menu.Root>
  </Menu.FilterProvider>
</template>
vue
<script setup lang="ts">
import { h } from 'vue';
import type { FunctionalComponent } from 'vue';
import { Menu } from '@vase-ui/vue/menu';
import styles from './index.module.css';

defineProps<{
  label: string;
  inputLabel: string;
  placeholder: string;
  emptyText: string;
  options: readonly string[];
}>();

function getSubmenuOffset({ side }: { side: Menu.Positioner.Props['side'] }) {
  return side === 'top' || side === 'bottom' ? 4 : -4;
}

const ClearIcon: FunctionalComponent = () =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'none',
      stroke: 'currentColor',
      style: { display: 'block' },
    },
    [h('path', { d: 'm3.5 3.5 9 9m0-9-9 9' })],
  );

const CaretRightIcon: FunctionalComponent = () =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'currentColor',
      style: { display: 'block' },
    },
    [h('path', { d: 'M6 12V4l4.5 4z' })],
  );

const popupHiddenClass = styles.PopupHidden;
</script>

<template>
  <Menu.FilterProvider>
    <Menu.SubmenuRoot>
      <Menu.SubmenuTrigger :class="styles.SubmenuTrigger">
        {{ label }}
        <CaretRightIcon />
      </Menu.SubmenuTrigger>
      <Menu.Portal>
        <Menu.Positioner
          :class="styles.Positioner"
          :side-offset="getSubmenuOffset"
          :align-offset="getSubmenuOffset"
        >
          <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
            <Menu.Popup :class="styles.Popup">
              <div :class="styles.InputContainer">
                <Menu.Input
                  :class="styles.Input"
                  :aria-label="inputLabel"
                  :placeholder="placeholder"
                />
                <Menu.Clear :class="styles.Clear">
                  <ClearIcon />
                </Menu.Clear>
              </div>
              <Menu.Empty :class="styles.Empty">{{ emptyText }}</Menu.Empty>
              <Menu.List :class="[styles.List, styles.SubmenuList]">
                <Menu.Item v-for="option in options" :key="option" :class="styles.Item">
                  {{ option }}
                </Menu.Item>
              </Menu.List>
            </Menu.Popup>
          </Transition>
        </Menu.Positioner>
      </Menu.Portal>
    </Menu.SubmenuRoot>
  </Menu.FilterProvider>
</template>
css
.Trigger {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  height: 2rem;
  padding: 0 0.5rem 0 0.75rem;
  margin: 0;
  border: 1px solid oklch(14.5% 0 0deg);
  border-radius: 0;
  outline: 0;
  background-color: white;
  color: oklch(14.5% 0 0deg);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 400;
  line-height: 1;
  white-space: nowrap;
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    border-color: 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 {
    border-color: oklch(55.6% 0 0deg);
    color: oklch(55.6% 0 0deg);

    @media (prefers-color-scheme: dark) {
      border-color: oklch(70.8% 0 0deg);
      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;
    }
  }
}

.Positioner {
  outline: 0;
}

.Popup {
  box-sizing: border-box;
  min-width: max(14rem, var(--anchor-width));
  overflow: hidden;
  border: 1px solid oklch(14.5% 0 0deg);
  border-radius: 0;
  outline: 0;
  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;

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

.InputContainer {
  display: flex;
  align-items: center;
  border-bottom: 1px solid oklch(87% 0 0deg);

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

  &:has(.Input[data-highlighted]) {
    border-color: oklch(14.5% 0 0deg);
    box-shadow: inset 0 0 0 1px oklch(14.5% 0 0deg);

    @media (prefers-color-scheme: dark) {
      border-color: white;
      box-shadow: inset 0 0 0 1px white;
    }
  }
}

.Input {
  flex: 1;
  width: 0;
  min-height: 2rem;
  padding: 0 0.625rem;
  border: 0;
  outline: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 0.875rem;
  line-height: 1;

  @media (any-pointer: coarse) {
    font-size: 1rem;
  }

  &::placeholder {
    color: oklch(55.6% 0 0deg);

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

.Clear {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: inherit;

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

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

.List {
  max-height: min(22rem, var(--available-height));
  padding-block: 0.25rem;
  outline: 0;
  overflow-y: auto;
  scroll-padding-block: 0.25rem;

  /* Filtered groups stay mounted with `hidden`. */
  &:not(:has(> :not([hidden]))) {
    padding-block: 0;
  }
}

.SubmenuList {
  max-height: min(28rem, var(--available-height));
}

/* A filtered item stays mounted with `hidden`, and the `display` of its class would show it. */
.Item[hidden],
.SubmenuTrigger[hidden],
.ChoiceItem[hidden] {
  display: none;
}

.Item,
.SubmenuTrigger,
.ChoiceItem {
  outline: 0;
  cursor: default;
  -webkit-user-select: none;
  user-select: none;
  padding-block: 0.5rem;
  padding-left: 1rem;
  padding-right: 2rem;
  display: flex;
  font-size: 0.875rem;
  line-height: 1rem;

  &[data-highlighted] {
    z-index: 0;
    position: relative;
    color: white;

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

  &[data-highlighted]::before {
    content: '';
    z-index: -1;
    position: absolute;
    inset-block: 0;
    inset-inline: 0.25rem;
    background-color: oklch(14.5% 0 0deg);

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

.ChoiceItem {
  display: grid;
  grid-template-columns: 1rem 1fr;
  align-items: center;
  gap: 0.5rem;
  padding-left: 0.625rem;
}

.ChoiceIndicator {
  grid-column-start: 1;
}

.ChoiceText {
  grid-column-start: 2;
  min-width: 0;
}

.SubmenuTrigger {
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-right: 0.5rem;

  &[data-popup-open] {
    z-index: 0;
    position: relative;
  }

  &[data-popup-open]::before {
    content: '';
    z-index: -1;
    position: absolute;
    inset-block: 0;
    inset-inline: 0.25rem;
    background-color: oklch(97% 0 0deg);

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

  &[data-highlighted][data-popup-open]::before {
    background-color: oklch(14.5% 0 0deg);

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

.Empty {
  padding: 0.75rem;
  color: oklch(55.6% 0 0deg);
  font-size: 0.875rem;
  line-height: 1.25rem;

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

.GroupLabel {
  -webkit-user-select: none;
  user-select: none;
  padding-block: 0.375rem 0.25rem;
  padding-left: 1rem;
  padding-right: 2rem;
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1rem;
  color: oklch(55.6% 0 0deg);

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

.Separator {
  display: none;
  height: 1px;
  margin: 0.25rem;
  background-color: oklch(87% 0 0deg);

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

.Section:not([hidden]) ~ .Section:not([hidden]) > .Separator {
  display: block;
}

/* The enter-from and leave-to class of the `<Transition>` around the popup. */
.PopupHidden {
  opacity: 0;
  transform: scale(0.98);
}
vue
<script setup lang="ts">
import { h } from 'vue';
import type { FunctionalComponent } from 'vue';
import { Menu } from '@vase-ui/vue/menu';
import {
  choiceItemClass,
  clearClass,
  emptyClass,
  groupLabelClass,
  inputClass,
  inputContainerClass,
  itemClass,
  listClass,
  popupClass,
  separatorClass,
  submenuListClass,
  submenuTriggerClass,
} from './classes';
import FilterableSubmenu from './FilterableSubmenu.vue';

const sharingOptions = [
  'Email',
  'Messages',
  'AirDrop',
  'Copy link',
  'Invite collaborators',
  'Publish to web',
  'Send a copy',
];

const folderOptions = [
  'Desktop',
  'Documents',
  'Downloads',
  'Projects',
  'Archive',
  'Shared',
  'Trash',
];

const exportOptions = [
  'PDF document',
  'Word document',
  'Plain text',
  'Rich text',
  'Markdown',
  'HTML page',
  'Image',
];

const sortOptions = [
  ['date', 'Date modified'],
  ['name', 'Name'],
  ['size', 'Size'],
] as const;

function getSubmenuOffset({ side }: { side: Menu.Positioner.Props['side'] }) {
  return side === 'top' || side === 'bottom' ? 4 : -4;
}

const CaretDownIcon: FunctionalComponent = () =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'currentColor',
      style: { display: 'block' },
    },
    [h('path', { d: 'M12 6H4l4 4.5z' })],
  );

const ClearIcon: FunctionalComponent = () =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'none',
      stroke: 'currentColor',
      style: { display: 'block' },
    },
    [h('path', { d: 'm3.5 3.5 9 9m0-9-9 9' })],
  );

const CaretRightIcon: FunctionalComponent = () =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'currentColor',
      style: { display: 'block' },
    },
    [h('path', { d: 'M6 12V4l4.5 4z' })],
  );

const CheckIcon: FunctionalComponent = () =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'none',
      stroke: 'currentColor',
      style: { display: 'block' },
    },
    [h('path', { d: 'm2.5 8.5 4 4 7-9' })],
  );

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

<template>
  <Menu.FilterProvider>
    <Menu.Root>
      <Menu.Trigger
        class="flex h-8 items-center justify-center gap-1.5 rounded-none border border-neutral-950 bg-white pr-2 pl-3 text-sm leading-none font-normal whitespace-nowrap text-neutral-950 select-none hover:not-disabled:bg-neutral-100 active:not-disabled:bg-neutral-200 data-pressed:bg-neutral-100 disabled:border-neutral-500 disabled:text-neutral-500 focus-visible:-outline-offset-1 focus-visible:outline-2 focus-visible:outline-neutral-950 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-disabled:bg-neutral-800 dark:active:not-disabled:bg-neutral-700 dark:data-pressed:bg-neutral-800 dark:disabled:border-neutral-400 dark:disabled:text-neutral-400 dark:focus-visible:outline-white"
      >
        Actions
        <CaretDownIcon />
      </Menu.Trigger>
      <Menu.Portal>
        <Menu.Positioner class="outline-hidden" :side-offset="8" align="start">
          <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
            <Menu.Popup :class="popupClass">
              <div :class="inputContainerClass">
                <Menu.Input
                  :class="inputClass"
                  aria-label="Filter actions"
                  placeholder="e.g. Save"
                />
                <Menu.Clear :class="clearClass">
                  <ClearIcon />
                </Menu.Clear>
              </div>
              <Menu.Empty :class="emptyClass">No actions found.</Menu.Empty>
              <Menu.List :class="listClass">
                <Menu.Group data-filter-section>
                  <Menu.GroupLabel :class="groupLabelClass">File</Menu.GroupLabel>
                  <Menu.Item :class="itemClass">New file</Menu.Item>
                  <Menu.Item :class="itemClass">Open file</Menu.Item>
                  <Menu.Item :class="itemClass">Save</Menu.Item>
                  <Menu.Item :class="itemClass">Save as</Menu.Item>
                  <Menu.Item :class="itemClass">Duplicate</Menu.Item>
                  <Menu.Item :class="itemClass">Rename</Menu.Item>
                </Menu.Group>
                <Menu.Group data-filter-section>
                  <Menu.GroupLabel :class="groupLabelClass">Organize</Menu.GroupLabel>
                  <FilterableSubmenu
                    label="Move to folder"
                    input-label="Filter folders"
                    placeholder="e.g. Projects"
                    empty-text="No folders found."
                    :options="folderOptions"
                  />
                  <Menu.SubmenuRoot>
                    <Menu.SubmenuTrigger :class="submenuTriggerClass">
                      Share
                      <CaretRightIcon />
                    </Menu.SubmenuTrigger>
                    <Menu.Portal>
                      <Menu.Positioner
                        class="outline-hidden"
                        :side-offset="getSubmenuOffset"
                        :align-offset="getSubmenuOffset"
                      >
                        <Transition
                          :enter-from-class="popupHiddenClass"
                          :leave-to-class="popupHiddenClass"
                        >
                          <Menu.Popup :class="popupClass">
                            <Menu.List :class="submenuListClass">
                              <Menu.Item
                                v-for="option in sharingOptions"
                                :key="option"
                                :class="itemClass"
                              >
                                {{ option }}
                              </Menu.Item>
                            </Menu.List>
                          </Menu.Popup>
                        </Transition>
                      </Menu.Positioner>
                    </Menu.Portal>
                  </Menu.SubmenuRoot>
                  <FilterableSubmenu
                    label="Export"
                    input-label="Filter export formats"
                    placeholder="e.g. PDF"
                    empty-text="No export formats found."
                    :options="exportOptions"
                  />
                  <Menu.Item :class="itemClass">Download a copy</Menu.Item>
                  <Menu.Item :class="itemClass">Delete</Menu.Item>
                </Menu.Group>

                <Menu.RadioGroup data-filter-section default-value="date">
                  <Menu.Separator data-filter-separator :class="separatorClass" />
                  <Menu.GroupLabel :class="groupLabelClass">Sort by</Menu.GroupLabel>
                  <Menu.RadioItem
                    v-for="[value, label] in sortOptions"
                    :key="value"
                    :class="choiceItemClass"
                    :value="value"
                    v-slot="{ state }"
                  >
                    <span v-if="state.checked" class="col-start-1">
                      <CheckIcon />
                    </span>
                    <span class="col-start-2 min-w-0">{{ label }}</span>
                  </Menu.RadioItem>
                </Menu.RadioGroup>

                <Menu.Group data-filter-section>
                  <Menu.Separator data-filter-separator :class="separatorClass" />
                  <Menu.GroupLabel :class="groupLabelClass">View</Menu.GroupLabel>
                  <Menu.CheckboxItem :class="choiceItemClass" default-checked v-slot="{ state }">
                    <span v-if="state.checked" class="col-start-1">
                      <CheckIcon />
                    </span>
                    <span class="col-start-2 min-w-0">Show details</span>
                  </Menu.CheckboxItem>
                  <Menu.CheckboxItem :class="choiceItemClass" v-slot="{ state }">
                    <span v-if="state.checked" class="col-start-1">
                      <CheckIcon />
                    </span>
                    <span class="col-start-2 min-w-0">Show sidebar</span>
                  </Menu.CheckboxItem>
                  <Menu.CheckboxItem :class="choiceItemClass" v-slot="{ state }">
                    <span v-if="state.checked" class="col-start-1">
                      <CheckIcon />
                    </span>
                    <span class="col-start-2 min-w-0">Keep available offline</span>
                  </Menu.CheckboxItem>
                </Menu.Group>
              </Menu.List>
            </Menu.Popup>
          </Transition>
        </Menu.Positioner>
      </Menu.Portal>
    </Menu.Root>
  </Menu.FilterProvider>
</template>
vue
<script setup lang="ts">
import { h } from 'vue';
import type { FunctionalComponent } from 'vue';
import { Menu } from '@vase-ui/vue/menu';
import {
  clearClass,
  emptyClass,
  inputClass,
  inputContainerClass,
  itemClass,
  popupClass,
  submenuListClass,
  submenuTriggerClass,
} from './classes';

defineProps<{
  label: string;
  inputLabel: string;
  placeholder: string;
  emptyText: string;
  options: readonly string[];
}>();

function getSubmenuOffset({ side }: { side: Menu.Positioner.Props['side'] }) {
  return side === 'top' || side === 'bottom' ? 4 : -4;
}

const ClearIcon: FunctionalComponent = () =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'none',
      stroke: 'currentColor',
      style: { display: 'block' },
    },
    [h('path', { d: 'm3.5 3.5 9 9m0-9-9 9' })],
  );

const CaretRightIcon: FunctionalComponent = () =>
  h(
    'svg',
    {
      width: '16',
      height: '16',
      viewBox: '0 0 16 16',
      fill: 'currentColor',
      style: { display: 'block' },
    },
    [h('path', { d: 'M6 12V4l4.5 4z' })],
  );

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

<template>
  <Menu.FilterProvider>
    <Menu.SubmenuRoot>
      <Menu.SubmenuTrigger :class="submenuTriggerClass">
        {{ label }}
        <CaretRightIcon />
      </Menu.SubmenuTrigger>
      <Menu.Portal>
        <Menu.Positioner
          class="outline-hidden"
          :side-offset="getSubmenuOffset"
          :align-offset="getSubmenuOffset"
        >
          <Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
            <Menu.Popup :class="popupClass">
              <div :class="inputContainerClass">
                <Menu.Input
                  :class="inputClass"
                  :aria-label="inputLabel"
                  :placeholder="placeholder"
                />
                <Menu.Clear :class="clearClass">
                  <ClearIcon />
                </Menu.Clear>
              </div>
              <Menu.Empty :class="emptyClass">{{ emptyText }}</Menu.Empty>
              <Menu.List :class="submenuListClass">
                <Menu.Item v-for="option in options" :key="option" :class="itemClass">
                  {{ option }}
                </Menu.Item>
              </Menu.List>
            </Menu.Popup>
          </Transition>
        </Menu.Positioner>
      </Menu.Portal>
    </Menu.SubmenuRoot>
  </Menu.FilterProvider>
</template>
ts
export const popupClass =
  'min-w-[max(14rem,var(--anchor-width))] origin-[var(--transform-origin)] overflow-hidden border border-neutral-950 bg-white text-neutral-950 shadow-[0.25rem_0.25rem_0] shadow-black/12 transition-[scale,opacity] duration-100 ease-out outline-hidden dark:border-white dark:bg-neutral-950 dark:text-white dark:shadow-none';
export const inputContainerClass =
  'flex items-center border-b border-neutral-300 has-data-highlighted:border-neutral-950 has-data-highlighted:ring-1 has-data-highlighted:ring-neutral-950 has-data-highlighted:ring-inset dark:border-neutral-700 dark:has-data-highlighted:border-white dark:has-data-highlighted:ring-white';
export const inputClass =
  'min-h-8 w-0 flex-1 bg-transparent px-2.5 text-sm any-pointer-coarse:text-base leading-none outline-hidden placeholder:text-neutral-500 dark:placeholder:text-neutral-400';
export const clearClass =
  'flex size-8 items-center justify-center bg-transparent outline-hidden focus-visible:-outline-offset-2 focus-visible:outline-2 focus-visible:outline-neutral-950 dark:focus-visible:outline-white';
export const emptyClass = 'p-3 text-sm text-neutral-500 dark:text-neutral-400';
// Filtered groups stay mounted with `hidden`.
const listBaseClass =
  'overflow-y-auto py-1 outline-hidden scroll-py-1 not-has-[>:not([hidden])]:py-0';
export const listClass = `${listBaseClass} max-h-[min(22rem,var(--available-height))] [&>[data-filter-section]:not([hidden])~[data-filter-section]:not([hidden])>[data-filter-separator]]:block`;
export const submenuListClass = `${listBaseClass} max-h-[min(28rem,var(--available-height))]`;
const itemBaseClass =
  "cursor-default py-2 pl-4 text-sm leading-4 outline-hidden select-none data-highlighted:relative data-highlighted:z-0 data-highlighted:text-white data-highlighted:before:absolute data-highlighted:before:inset-x-1 data-highlighted:before:inset-y-0 data-highlighted:before:z-[-1] data-highlighted:before:bg-neutral-950 data-highlighted:before:content-[''] dark:data-highlighted:text-neutral-950 dark:data-highlighted:before:bg-white";
export const itemClass = `${itemBaseClass} flex pr-8`;
export const choiceItemClass = `${itemBaseClass} grid grid-cols-[1rem_1fr] items-center gap-2 pr-8 pl-2.5`;
export const submenuTriggerClass = `${itemBaseClass} flex items-center justify-between gap-4 pr-2 data-popup-open:relative data-popup-open:z-0 data-popup-open:before:absolute data-popup-open:before:inset-x-1 data-popup-open:before:inset-y-0 data-popup-open:before:z-[-1] data-popup-open:before:bg-neutral-100 data-popup-open:before:content-[''] data-highlighted:data-popup-open:before:bg-neutral-950 dark:data-popup-open:before:bg-neutral-800 dark:data-highlighted:data-popup-open:before:bg-white`;
export const groupLabelClass =
  'pt-1.5 pr-8 pb-1 pl-4 text-xs leading-4 font-medium text-neutral-500 select-none dark:text-neutral-400';
export const separatorClass = 'mx-1 my-1 hidden h-px bg-neutral-300 dark:bg-neutral-700';

Matching items ​

An item matches its text by default. Use label to change that text.

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

<template>
  <Menu.FilterProvider>
    <Menu.Root>
      <Menu.Trigger>Actions</Menu.Trigger>
      <Menu.Portal>
        <Menu.Positioner>
          <Menu.Popup>
            <Menu.Input aria-label="Filter actions" />
            <Menu.List>
              <Menu.Item label="Move to folder">Move</Menu.Item>
            </Menu.List>
          </Menu.Popup>
        </Menu.Positioner>
      </Menu.Portal>
    </Menu.Root>
  </Menu.FilterProvider>
</template>

An item that does not match, and a group with no matching items, get the hidden attribute and stay mounted with their state. If your styles set display on an item or a group, add a [hidden] rule, so that it still hides. :first-child can match a hidden item: select the first shown item with :nth-child(1 of :not([hidden])).

css
.Group {
  display: flex;
}

.Group[hidden] {
  display: none;
}

<Menu.Empty> shows when no item matches. Its element stays in the DOM with no content while an item shows. Hide its padding with :empty.

By default, an item matches when its text contains the query. The match ignores case, accents and punctuation. Use filter to set your own rule. It gets the text of each item and the trimmed query, and it keeps the item when it returns true. Menu.useFilter gives the same locale-aware comparisons.

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

const { startsWith } = Menu.useFilter();
</script>

<template>
  <Menu.FilterProvider :filter="startsWith">
    <Menu.Root>
      <!-- Menu parts -->
    </Menu.Root>
  </Menu.FilterProvider>
</template>

For external filtering, set filter to null and render the results yourself. Leave out the groups that have no result.

vue
<script setup lang="ts">
import { computed, shallowRef } from 'vue';
import { Menu } from '@vase-ui/vue/menu';

const actions = ['Rename', 'Delete'];

const { contains } = Menu.useFilter();
const query = shallowRef('');
const results = computed(() => actions.filter((action) => contains(action, query.value)));
</script>

<template>
  <Menu.FilterProvider v-model="query" :filter="null">
    <Menu.Root>
      <Menu.Trigger>Actions</Menu.Trigger>
      <Menu.Portal>
        <Menu.Positioner>
          <Menu.Popup>
            <Menu.Input aria-label="Filter actions" />
            <Menu.List>
              <Menu.Item v-for="action in results" :key="action">{{ action }}</Menu.Item>
            </Menu.List>
          </Menu.Popup>
        </Menu.Positioner>
      </Menu.Portal>
    </Menu.Root>
  </Menu.FilterProvider>
</template>

Controlling the query ​

Control the query with v-model on <Menu.FilterProvider>, or with its modelValue prop and its valueChange event. The query resets to an empty string when the popup leaves the DOM, after the leave of its <Transition>. The valueChange event reports that change with the reason 'popup-close'. Call eventDetails.cancel() to keep the query.

Highlighting ​

Set autoHighlight to highlight the first match while the query is not empty. Set it to "always" to highlight the first match when the query is empty too. The highlighted item has the data-highlighted attribute, and the itemHighlighted event of <Menu.Root> reports each change.

Focus and keyboard ​

When a mouse press, a key, defaultOpen or the open prop opens the menu, the input gets the focus. A hover, a touch or a pen does not move the focus to the input, so the on-screen keyboard stays hidden. After a hover open, Up Arrow, Down Arrow or a typed character on the trigger moves the focus to the input. The arrow keys move the highlight while the input keeps the focus. Tab closes the menu, and Shift+Tab returns the focus to the trigger. The popup is a dialog that holds the searchbox input and the menu list.

Wrap each searchable <Menu.SubmenuRoot> in its own <Menu.FilterProvider>. A submenu with no provider stays unfiltered.

Filtering with detached triggers ​

Give the same handle from Menu.createHandle() to the root and to its detached trigger:

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

const handle = Menu.createHandle();
</script>

<template>
  <Menu.Trigger :handle="handle">Actions</Menu.Trigger>

  <Menu.FilterProvider>
    <Menu.Root :handle="handle">
      <!-- Menu parts -->
    </Menu.Root>
  </Menu.FilterProvider>
</template>

API reference ​

Menu.FilterProvider Preview​

Makes the root in it filter its items with a query. Renders no element.

Props

PropTypeDefaultDescription
autoHighlightboolean | "always" | undefinedfalseThe first shown item gets the highlight: true while the query is not empty, 'always' also while it is empty.
defaultValuestring | undefined''The query at the mount of an uncontrolled provider.
filter((text: string, query: string) => boolean) | null | undefinedSays whether an item matches the query. It gets the label of the item, else its text, and the query with no space at the ends. By default, an item matches when it contains the query, with no regard to case, accents and punctuation. null shows each item.
localeIntl.LocalesArgumentThe locale of the default filter. With no value, the nearest LocaleProvider, else en-US.
modelValuestring | undefinedThe query. v-model binds it.

Slots

SlotSlot propsDescription
defaultThe Menu.Root or Menu.SubmenuRoot that filters its items.

Events

EventArgumentsDescription
valueChange[value: string, details: MenuFilterProviderChangeEventDetails]The user changes the query. details.cancel() keeps it as it was.
update:modelValue[value: string]Comes after valueChange, unless a listener cancels the change. v-model uses it.

Menu.Root ​

Groups the parts of the menu. Renders no element.

Props

PropTypeDefaultDescription
closeParentOnEscboolean | undefinedfalseEscape in a submenu also closes its parent menu.
defaultOpenboolean | undefinedfalseThe menu is open at the mount of an uncontrolled root.
defaultTriggerIdstring | null | undefinednullThe id of the active trigger at the mount, with defaultOpen.
disabledboolean | undefinedfalseThe user cannot open the menu or use its items.
handleMenuHandle<Payload> | undefinedConnects the root to triggers outside it and to code.
highlightItemOnHoverboolean | undefinedtrueA move of the pointer highlights its item. With false, CSS :hover and [data-highlighted] differ.
loopFocusboolean | undefinedtrueAn arrow key at the last item goes to the first item, and the other way.
modalboolean | undefinedtrueThe page does not scroll and gets no pointer while the menu is open. A menu that a hover opened is not modal until a press on its trigger. After a touch, the page scrolls unless the popup covers the width of the view.
openboolean | undefinedThe menu is open. v-model:open binds it.
orientationMenuRootOrientation | undefined'vertical'The axis of the arrow keys that move the highlight.
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 menu. payload is the payload of the active trigger.

Events

EventArgumentsDescription
openChange[open: boolean, details: MenuRootChangeEventDetails]The menu 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.
itemHighlighted[element: HTMLElement | undefined, details: MenuRootHighlightEventDetails]The highlighted item changes. It gets the element of the item, or undefined.

Exposed

MemberTypeDescription
close() => voidCloses the menu.

Menu.Trigger ​

A button that opens the menu. 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 | undefined100The time in milliseconds that the mouse rests on the trigger before the open, with openOnHover.
disabledboolean | undefinedfalseThe user cannot press the trigger.
handleMenuHandle<Payload> | undefinedConnects the trigger to a root outside it.
idstring | undefinedThe root names the active trigger by this id in triggerId. With no value, a generated id.
openOnHoverboolean | undefinedA mouse that rests on the trigger also opens the menu. In a menubar, false also stops the open by a hover while another menu of the bar is open. A wrapper component that declares this prop needs the default undefined, because Vue gives an absent Boolean prop the value false.
payloadPayload | undefinedThe payload that the menu 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: MenuTriggerState
The content of the part.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: MenuTriggerState
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 menu is open for this trigger.
[data-pressed]A press of the trigger opened the menu, and the menu is open.
:disabledThe trigger is a native button, and the trigger, the menu or a fieldset around it is disabled.
[aria-disabled="true"]The trigger is another element, and the trigger or the menu is disabled.

Menu.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. Its aria-owns names the popup, so a screen reader reads the popup after its trigger. In a menu or a menubar, the <span> has the role group.

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.

Menu.Backdrop ​

An overlay under the menu. 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: MenuBackdropState
The content of the part.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: MenuBackdropState
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 menu is closed, and keepMounted of the portal keeps the backdrop in the DOM.

Menu.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: MenuPositionerState
The content of the part.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: MenuPositionerState
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, right, inline-start or inline-end. A logical side shows with a logical side prop, and for a submenu or a menu of a vertical menubar with no 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 from the anchor to the edge of the collision boundary, in pixels.
--available-heightThe height from the anchor to the edge of the collision boundary, in pixels.
--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, and at a move to another trigger the width of the new content, in pixels. Only a menu with Menu.Viewport has it.
--positioner-heightThe height of the popup, and at a move to another trigger the height of the new content, in pixels. Only a menu with Menu.Viewport has it.

Menu.Popup ​

The container of the items of the menu. 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.
idstring | undefinedThe trigger names the popup by this id in aria-controls, when the menu has no Menu.List. With no value, a generated id.
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: MenuPopupState
The content of the part.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: MenuPopupState
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: start, center or end.
[data-instant]An animation should not run: click after a key on the trigger, dismiss after Escape, group at a move between the menus of a menubar, or trigger-change after a move to another trigger.
[hidden]The menu is closed, and keepMounted of the portal keeps the popup in the DOM.

CSS variables

VariableDescription
--popup-widthThe width of the popup, in pixels: the old width, then the new width, while Menu.Viewport moves to another trigger.
--popup-heightThe height of the popup, in pixels: the old height, then the new height, while Menu.Viewport moves to another trigger.

Menu.Viewport ​

The container of content that changes when the menu 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: MenuViewportState
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: MenuViewportState
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 side of the new trigger from the old one: left or right, up or down, or one of each, such as right down.
[data-instant]An animation should not run, with the values of the popup.

Menu.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: MenuArrowState
The content of the part.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: MenuArrowState
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: start, center or end.
[data-uncentered]The arrow cannot point to the center of the anchor.

Menu.Input ​

A text input for the query of the filter. Renders an <input> element.

Props

PropTypeDefaultDescription
disabledboolean | undefinedfalseThe user cannot type in the input.
idstring | undefinedA <label> names the input by this id in for. With no value, a generated id.

Slots

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

Exposed

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

Selectors

SelectorDescription
[data-highlighted]The input shows its focus ring: it matched :focus-visible when it got the focus, and no item has the highlight.
:disabledThe input is disabled.

Menu.Clear ​

A button that empties the query. 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: MenuClearState
The content of the part.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: MenuClearState
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 it is disabled.
[aria-disabled="true"]The button is another element, and it is disabled.

Menu.Empty ​

A message while the query shows no item. 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: MenuEmptyState
The content of the part.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: MenuEmptyState
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.

Menu.List ​

The container of the items in a popup that has other content. Renders a <div> element.

Props

PropTypeDefaultDescription
idstring | undefinedThe trigger and Menu.Input name the list by this id in aria-controls. With no value, a generated id.
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: MenuListState
The content of the part.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: MenuListState
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.

Menu.Item ​

An item of the menu. Renders a <div> element.

Props

PropTypeDefaultDescription
closeOnClickboolean | undefinedtrueA click closes the menu.
disabledboolean | undefinedfalseThe item keeps the focus, and does no action.
idstring | undefinedMenu.Input names the highlighted item by this id in aria-activedescendant. With no value, a generated id.
labelstring | undefinedThe text that the typeahead and the filter read. With no value, the text of the item.
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: MenuItemState
The content of the part.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: MenuItemState
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-highlighted]The item has the highlight.
[aria-disabled="true"]The item or the menu is disabled.
[hidden]The item does not match the query of the filter.

Menu.LinkItem ​

A link in the menu. Renders an <a> element.

Props

PropTypeDefaultDescription
closeOnClickboolean | undefinedfalseA click closes the menu.
idstring | undefinedMenu.Input names the highlighted item by this id in aria-activedescendant. With no value, a generated id.
labelstring | undefinedThe text that the typeahead and the filter read. With no value, the text of the item.
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: MenuLinkItemState
The content of the part.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: MenuLinkItemState
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-highlighted]The link has the highlight.
[hidden]The link does not match the query of the filter.

Menu.SubmenuRoot ​

Groups the parts of a submenu. Renders no element.

Props

PropTypeDefaultDescription
closeParentOnEscboolean | undefinedfalseEscape in the submenu also closes its parent menu.
defaultOpenboolean | undefinedfalseThe menu is open at the mount of an uncontrolled root.
disabledboolean | undefinedfalseThe user cannot open the menu or use its items.
highlightItemOnHoverboolean | undefinedtrueA move of the pointer highlights its item. With false, CSS :hover and [data-highlighted] differ.
loopFocusboolean | undefinedtrueAn arrow key at the last item goes to the first item, and the other way.
openboolean | undefinedThe menu is open. v-model:open binds it.
orientationMenuRootOrientation | undefined'vertical'The axis of the arrow keys that move the highlight.

Slots

SlotSlot propsDescription
defaultThe trigger and the portal of the submenu.

Events

EventArgumentsDescription
openChange[open: boolean, details: MenuRootChangeEventDetails]The submenu 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.
itemHighlighted[element: HTMLElement | undefined, details: MenuRootHighlightEventDetails]The highlighted item changes. It gets the element of the item, or undefined.

Exposed

MemberTypeDescription
close() => voidCloses the submenu.

Menu.SubmenuTrigger ​

An item that opens a submenu. Renders a <div> element.

Props

PropTypeDefaultDescription
closeDelaynumber | undefined0The time in milliseconds before the close, after the pointer moved to another item.
delaynumber | undefined100The time in milliseconds from the first move on the item to the open.
disabledboolean | undefinedfalseThe item keeps the focus, and does not open the submenu.
idstring | undefinedMenu.Input names the highlighted item by this id in aria-activedescendant. With no value, a generated id.
labelstring | undefinedThe text that the typeahead and the filter read. With no value, the text of the item.
openOnHoverboolean | undefinedtrueA mouse that moves on the item opens the submenu.
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: MenuSubmenuTriggerState
The content of the part.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: MenuSubmenuTriggerState
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-popup-open]The submenu is open.
[data-highlighted]The item has the highlight.
[aria-disabled="true"]The item, the submenu or the parent menu is disabled.
[hidden]The item does not match the query of the filter.

Menu.Group ​

Groups related items. 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: MenuGroupState
The content of the part.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: MenuGroupState
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]No item of the group matches the query of the filter.

Menu.GroupLabel ​

A label that names its group. Renders a <div> element.

Props

PropTypeDefaultDescription
idstring | undefinedThe group names the label by this id in aria-labelledby. With no value, a generated id.
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: MenuGroupLabelState
The content of the part.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: MenuGroupLabelState
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.

Menu.RadioGroup ​

Groups radio items, of which one is checked. Renders a <div> element.

Props

PropTypeDefaultDescription
defaultValueValue | undefinedThe value of the checked item at the mount of an uncontrolled group.
disabledboolean | undefinedfalseThe user cannot change the value.
modelValueValue | undefinedThe value of the checked item. v-model binds 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: MenuRadioGroupState
The content of the part.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: MenuRadioGroupState
Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref.

Events

EventArgumentsDescription
valueChange[value: Value, details: MenuRadioGroupChangeEventDetails]The user checks an item. details.cancel() keeps the value as it was.
update:modelValue[value: Value]Comes after valueChange, unless a listener cancels the change. v-model uses it.

Exposed

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

Selectors

SelectorDescription
[aria-disabled="true"]The group is disabled.
[hidden]No item of the group matches the query of the filter.

Menu.RadioItem ​

An item of a radio group. Renders a <div> element.

Props

PropTypeDefaultDescription
closeOnClickboolean | undefinedfalseA click closes the menu.
disabledboolean | undefinedfalseThe item keeps the focus, and the user cannot choose it.
idstring | undefinedMenu.Input names the highlighted item by this id in aria-activedescendant. With no value, a generated id.
labelstring | undefinedThe text that the typeahead and the filter read. With no value, the text of the item.
valueValueRequiredThe value that the group gets at a press of the item.
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: MenuRadioItemState
The content of the part.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: MenuRadioItemState
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-checked="true"]The item is checked.
[data-highlighted]The item has the highlight.
[aria-disabled="true"]The item, its group or the menu is disabled.
[hidden]The item does not match the query of the filter.

Menu.CheckboxItem ​

An item that the user checks and unchecks. Renders a <div> element.

Props

PropTypeDefaultDescription
closeOnClickboolean | undefinedfalseA click closes the menu.
defaultCheckedboolean | undefinedfalseThe item is checked at the mount of an uncontrolled item.
disabledboolean | undefinedfalseThe item keeps the focus, and the user cannot change it.
idstring | undefinedMenu.Input names the highlighted item by this id in aria-activedescendant. With no value, a generated id.
labelstring | undefinedThe text that the typeahead and the filter read. With no value, the text of the item.
modelValueboolean | undefinedThe item is checked. v-model binds 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: MenuCheckboxItemState
The content of the part.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: MenuCheckboxItemState
Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref.

Events

EventArgumentsDescription
checkedChange[checked: boolean, details: MenuCheckboxItemChangeEventDetails]The user checks or unchecks the item. details.cancel() keeps it as it was.
update:modelValue[checked: boolean]Comes after checkedChange, unless a listener cancels the change. v-model uses it.

Exposed

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

Selectors

SelectorDescription
[aria-checked="true"]The item is checked.
[data-highlighted]The item has the highlight.
[aria-disabled="true"]The item or the menu is disabled.
[hidden]The item does not match the query of the filter.

Menu.Separator ​

A separator element accessible to screen readers. Renders a <div> element.

Props

PropTypeDefaultDescription
orientation"horizontal" | "vertical" | undefined'horizontal'The orientation of the separator.
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: SeparatorState
Content, such as a glyph between two groups. Assistive technology does not read it.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: SeparatorState
Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref.

Exposed

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

Selectors

SelectorDescription
[aria-orientation]The orientation of the separator: horizontal or vertical.

useFilter ​

Menu.useFilter returns the functions contains, startsWith and endsWith. They compare a text with a query in the locale of the user. Use them when you filter the items yourself.

Parameters

ParameterTypeDescription
options?GetFilterParameters

Return value

Filter

createHandle ​

Creates a handle that connects a <Menu.Root> with detached <Menu.Trigger> parts. The type argument of the function is the type of the payload.

Return value

MenuHandle<Payload>

Handle ​

Menu.createHandle() returns a Menu.Handle. Give it to the handle prop of the root and of each trigger outside the root. While a root is mounted, open() throws when the handle has no trigger with that id.

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 Menu from Base UI 1.9.0.

API ​

Base UIVase UI
Menu.Root prop onOpenChangeComplete@after-enter and @after-leave of a <Transition> around the popup run after its animations.
Menu.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.
Menu.Trigger prop nativeButtonThe part reads the element that it renders, so it has no nativeButton.
Menu.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 render, as and element. The developer writes an element in the portal when they need one.
Menu.Backdrop<Transition> animates the part, so the state has no transitionStatus, and the part has no data-starting-style and data-ending-style. A closed part is out of the DOM, or it has hidden with keepMounted of the portal, so CSS selects [hidden] and the part has no data-open and data-closed.
Menu.PositionerWith a Vue default, the part cannot find out that a prop is absent. side, align, sideOffset, alignOffset and arrowPadding thus have no Vue default, and their default follows the place of the menu, as in Base UI. side is 'inline-end' for a submenu and for a menu of a vertical menubar, else 'bottom'. align is 'center' for a menu outside a menubar, else 'start'. A context menu with no side and an align that is not center has sideOffset -5 and alignOffset 2, else both are 0. arrowPadding is 0 for a context menu, else 5.
Menu.Popup<Transition> animates the part, so the state has no transitionStatus, and the part has no data-starting-style and data-ending-style. A closed part is out of the DOM, or it has hidden with keepMounted of the portal, so CSS selects [hidden] and the part has no data-open and data-closed.
Menu.Clear prop nativeButtonThe part reads the element that it renders, so it has no nativeButton.
Menu.Item prop nativeButtonThe part reads the element that it renders, so it has no nativeButton.
Menu.SubmenuRoot prop onOpenChangeComplete@after-enter and @after-leave of a <Transition> around the popup run after its animations.
Menu.SubmenuRoot 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.
Menu.SubmenuTrigger prop nativeButtonThe part reads the element that it renders, so it has no nativeButton.
Menu.RadioGroupThe change event of the part has the one reason that it sends, item-press, in place of the union of the reasons of the root.
Menu.RadioItem prop nativeButtonThe part reads the element that it renders, so it has no nativeButton.
Menu.RadioItemIndicatorThe default slot of the item gives state.checked, so the developer writes v-if or v-show on an element of their own, with <Transition> for an enter and a leave. CSS alone selects [aria-checked="true"]. The family thus has no indicator part.
Menu.CheckboxItemThe change event of the part has the one reason that it sends, item-press, in place of the union of the reasons of the root. The part reads the element that it renders, so it has no nativeButton.
Menu.CheckboxItemIndicatorThe default slot of the item gives state.checked, so the developer writes v-if or v-show on an element of their own, with <Transition> for an enter and a leave. CSS alone selects [aria-checked="true"]. The family thus has no indicator part.

Added in Vase UI ​

PartMemberWhy
Menu.Portaldisabled propA disabled portal renders at its source, also on the server (VUE-128).
Menu.Rootupdate:triggerId eventv-model:trigger-id binds the active trigger: Vue binds a second state of a component with a named v-model.
Menu.Portaldefer propThe portal is a <Teleport>, and it takes the props of <Teleport>: defer waits for the other content of the same update.

Return types ​

FunctionVase UI returnsWhy
Menu.createHandleMenuHandle<Payload>Menu.Handle is the class MenuHandle. The declaration of the function names the class, and Base UI documents the same class by its name in the namespace.
Menu.useFilterFilterBase UI documents the return type as MenuFilter. The function returns Filter, and MenuFilter is that type under another name.

Behavior ​

Vase UIEvidence
A press can open the popup of Menu.Trigger, Select.Trigger or Combobox.Trigger. The popup then stays open when the release comes within 8 px of the point of the press on each axis. This is also true when the trigger moved. The trigger opens its popup in the frame after the press, and a layout change in that frame can move the trigger. The release of a press that did not move then lands on another element. Base UI closes the popup for that release with the reason cancel-open. Base UI also closes the popup for a release more than 5 px off a trigger that did not move. Vase UI keeps the popup open for such a release when it is within 8 px of the press. A move of 8 px or less on each axis is not a drag. Select.Item of Base UI takes 8 px of vertical travel as the start of a drag. 8 px is less than half of the 24 px target of WCAG 2.2. A person whose hand moves 8 px or less on each axis thus keeps the popup. A release still closes the popup when it is more than 8 px from the point of the press on one axis. The release must also be off the popup and more than 5 px off the trigger.
Shift+Tab in the popup of a menu or a select asks for the close with the reason focus-out. When a handler cancels the close, the popup stays open, and the focus still goes to the trigger. In a submenu, the focus goes to the submenu trigger, or to the input of a filterable parent menu. From the input of a filterable menu, the focus goes to the trigger. A root context menu has no trigger element, so a canceled close for Tab or Shift+Tab keeps the focus in its modal popup. In Base UI, Shift+Tab does nothing when the close is canceled: the list stops the key and moves no focus. Tab still leaves the popup, so the focus can leave in one direction only.
A press can open the popup of Menu, Select, Combobox or Autocomplete. The press can be on the trigger. In a Combobox or Autocomplete it can also be on the input, the input group or the chips, with the input in the popup or outside it. An item does not activate when the release of that press comes within 8 px of the point of the press on each axis. The open can put an item under a pointer that does not move: a layout change can move the trigger, and alignItemWithTrigger puts the selected item of Select, or its first item, under the pointer. Base UI activates that item when the release comes 200 ms or more after the press (Menu), or 400 ms or more after the open (Select): the menu runs the action of the item, and the select commits the value of the item. A Combobox or Autocomplete item of Base UI commits on a release with no delay when it has the highlight, also after a short click. The rule applies in each mode of Select, also when the popup aligns the selected item with the trigger. A native pop-up button of macOS commits the selected item and closes for a release with no move after a hold. Vase UI keeps the popup open, so one gesture has one result in each mode and for each duration of the press. Context Menu opens at the point of a right press. An item of a context menu does not activate when the release comes within 8 px of that point on each axis. By default, the popup starts 2 px right of that point and 5 px above it, so its first item can start a few pixels from the pointer. Base UI ignores only a release within 1 px of that point, at any time after the open. With that rule, a right click on macOS that moves 3 px onto the first item of the demo on the Context Menu page runs the action of that item. On other platforms, an item ignores the release of the right button. A move of 8 px or less on each axis is not a drag. Select.Item of Base UI takes 8 px of vertical travel as the start of a drag across its items. 8 px is less than half of the 24 px target of WCAG 2.2. A hand that moves 8 px or less on each axis during a long press thus activates no item. A release more than 8 px from the point of the press on one axis still activates the item under it.
A menu of a menubar that closes because another menu of the menubar opened gives the focus to the trigger of the open menu. Base UI gives the focus to the trigger of the menu that closed, when the closed popup unmounts before another element takes the focus, as with no exit animation. While the menubar has an open menu, that focus can open the closed menu again, and the menu that opened then closes. An open of a menu by its open prop or by its handle is then lost.
Tab in a submenu of a context menu closes each menu of the context menu with the reason focus-out. The focus then goes where Tab in the root sends it: to the element that had it before the menu opened. The WAI-ARIA menu pattern asks for this, and Tab in a submenu of a menu with a trigger does it in both libraries. In Base UI, a submenu of a context menu does not handle Tab, so the key moves the focus out of the submenu. A focus guard of the modal popup of the root then focuses the first tabbable element of that popup: the submenu trigger. Each submenu thus closes, but the root stays open. Shift+Tab in a submenu still closes only that submenu, as in Base UI.
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.
The highlight of a filterable menu belongs to an item, not to an index of the list. When an item mounts before the highlighted item, the highlight stays on its item. aria-activedescendant of the input keeps the id of that item, and itemHighlighted reports nothing. Base UI keeps the highlight as an index. The new item takes that index, so Base UI removes the highlight and reports undefined.
While a submenu of a filterable menu is open, its trigger keeps the highlight in the parent menu, for an open by an arrow key, by Enter and by the pointer. The highlighted trigger shows the path to the open submenu, and itemHighlighted of the parent reports no change at the open and at the close. Base UI keeps the highlight of the trigger only for an open by the pointer. For an open by a key, it removes the highlight and aria-activedescendant of the parent input until the submenu closes.
openChange reports a close only for an open menu. When a controlled root does not apply an open by hover, the menu stays closed, and a pointer that leaves the trigger reports nothing. A listener thus gets no close of a menu that it did not open. details.cancel() declines an open in both libraries. Base UI reports a close with the reason trigger-hover then, because its store does not know if the parent applies the open later.
Menu.Empty keeps its element with role="status" in the DOM while the popup is open, and adds its content when no item shows. A screen reader reads a live region that is in the DOM before its text changes, and Combobox.Empty has the same form. The element with no content matches :empty, so a style can hide it. Base UI renders the element only while no item shows, and it changes the text of the element for 200 ms after the mount to make a screen reader read it.
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.