Menubar
A menu bar that provides commands and options for your application.
vue
<script setup lang="ts">
import { h } from 'vue';
import type { FunctionalComponent } from 'vue';
import { Menu } from '@vase-ui/vue/menu';
import { Menubar } from '@vase-ui/vue/menubar';
import styles from './index.module.css';
function handleClick(event: MouseEvent) {
if (event.currentTarget instanceof HTMLElement) {
console.log(`${event.currentTarget.textContent} clicked`);
}
}
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>
<Menubar :class="styles.Menubar">
<Menu.Root>
<Menu.Trigger :class="styles.MenuTrigger">File</Menu.Trigger>
<Menu.Portal>
<Menu.Positioner :class="styles.MenuPositioner" :side-offset="4">
<Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
<Menu.Popup :class="styles.MenuPopup">
<Menu.Item :class="styles.MenuItem" @click="handleClick">New</Menu.Item>
<Menu.Item :class="styles.MenuItem" @click="handleClick">Open</Menu.Item>
<Menu.Item :class="styles.MenuItem" @click="handleClick">Save</Menu.Item>
<Menu.SubmenuRoot>
<Menu.SubmenuTrigger :class="styles.SubmenuTrigger">
Export
<CaretRightIcon />
</Menu.SubmenuTrigger>
<Menu.Portal>
<Menu.Positioner
:class="styles.MenuPositioner"
:side-offset="-4"
:align-offset="-4"
>
<Transition
:enter-from-class="popupHiddenClass"
:leave-to-class="popupHiddenClass"
>
<Menu.Popup :class="styles.MenuPopup">
<Menu.Item :class="styles.MenuItem" @click="handleClick">PDF</Menu.Item>
<Menu.Item :class="styles.MenuItem" @click="handleClick">PNG</Menu.Item>
<Menu.Item :class="styles.MenuItem" @click="handleClick">SVG</Menu.Item>
</Menu.Popup>
</Transition>
</Menu.Positioner>
</Menu.Portal>
</Menu.SubmenuRoot>
<Menu.Separator :class="styles.MenuSeparator" />
<Menu.Item :class="styles.MenuItem" @click="handleClick">Print</Menu.Item>
</Menu.Popup>
</Transition>
</Menu.Positioner>
</Menu.Portal>
</Menu.Root>
<Menu.Root>
<Menu.Trigger :class="styles.MenuTrigger">Edit</Menu.Trigger>
<Menu.Portal>
<Menu.Positioner :class="styles.MenuPositioner" :side-offset="4">
<Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
<Menu.Popup :class="styles.MenuPopup">
<Menu.Item :class="styles.MenuItem" @click="handleClick">Cut</Menu.Item>
<Menu.Item :class="styles.MenuItem" @click="handleClick">Copy</Menu.Item>
<Menu.Item :class="styles.MenuItem" @click="handleClick">Paste</Menu.Item>
</Menu.Popup>
</Transition>
</Menu.Positioner>
</Menu.Portal>
</Menu.Root>
<Menu.Root>
<Menu.Trigger :class="styles.MenuTrigger">View</Menu.Trigger>
<Menu.Portal>
<Menu.Positioner :class="styles.MenuPositioner" :side-offset="4">
<Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
<Menu.Popup :class="styles.MenuPopup">
<Menu.Item :class="styles.MenuItem" @click="handleClick">Zoom In</Menu.Item>
<Menu.Item :class="styles.MenuItem" @click="handleClick">Zoom Out</Menu.Item>
<Menu.SubmenuRoot>
<Menu.SubmenuTrigger :class="styles.SubmenuTrigger">
Layout
<CaretRightIcon />
</Menu.SubmenuTrigger>
<Menu.Portal>
<Menu.Positioner
:class="styles.MenuPositioner"
:side-offset="-4"
:align-offset="-4"
>
<Transition
:enter-from-class="popupHiddenClass"
:leave-to-class="popupHiddenClass"
>
<Menu.Popup :class="styles.MenuPopup">
<Menu.Item :class="styles.MenuItem" @click="handleClick"
>Single Page</Menu.Item
>
<Menu.Item :class="styles.MenuItem" @click="handleClick"
>Two Pages</Menu.Item
>
<Menu.Item :class="styles.MenuItem" @click="handleClick"
>Continuous</Menu.Item
>
</Menu.Popup>
</Transition>
</Menu.Positioner>
</Menu.Portal>
</Menu.SubmenuRoot>
<Menu.Separator :class="styles.MenuSeparator" />
<Menu.Item :class="styles.MenuItem" @click="handleClick">Full Screen</Menu.Item>
</Menu.Popup>
</Transition>
</Menu.Positioner>
</Menu.Portal>
</Menu.Root>
<Menu.Root disabled>
<Menu.Trigger :class="styles.MenuTrigger">Help</Menu.Trigger>
</Menu.Root>
</Menubar>
</template>css
.Menubar {
display: flex;
align-items: center;
}
.MenuTrigger {
box-sizing: border-box;
height: 2rem;
padding: 0 0.75rem;
margin: 0;
border: 0;
background-color: transparent;
color: oklch(14.5% 0 0deg);
font-family: inherit;
font-size: 0.875rem;
font-weight: 400;
line-height: 1.25rem;
-webkit-user-select: none;
user-select: none;
@media (prefers-color-scheme: dark) {
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);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
&:focus-visible {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
position: relative;
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
outline-color: white;
}
}
}
.MenuPositioner {
outline: 0;
}
.MenuPopup {
box-sizing: border-box;
outline: 0;
padding-block: 0.25rem;
border: 1px solid oklch(14.5% 0 0deg);
background-color: white;
color: oklch(14.5% 0 0deg);
box-shadow: 0.25rem 0.25rem 0 rgb(0 0 0 / 12%);
transform-origin: var(--transform-origin);
transition:
transform 100ms ease-out,
opacity 100ms ease-out;
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
box-shadow: none;
}
&[data-instant] {
transition: none;
}
}
.MenuItem,
.SubmenuTrigger {
outline: 0;
cursor: default;
-webkit-user-select: none;
user-select: none;
padding-block: 0.5rem;
padding-left: 1rem;
padding-right: 1rem;
display: flex;
font-size: 0.875rem;
line-height: 1rem;
font-weight: 400;
align-items: center;
justify-content: space-between;
gap: 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;
}
}
}
.SubmenuTrigger {
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;
}
}
}
.MenuSeparator {
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';
import { Menubar } from '@vase-ui/vue/menubar';
function handleClick(event: MouseEvent) {
if (event.currentTarget instanceof HTMLElement) {
console.log(`${event.currentTarget.textContent} clicked`);
}
}
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>
<Menubar class="flex items-center">
<Menu.Root>
<Menu.Trigger
class="h-8 border-0 bg-transparent px-3 font-[inherit] text-sm font-normal text-neutral-950 select-none data-pressed:bg-neutral-100 disabled:text-neutral-500 dark:text-white dark:focus-visible:bg-neutral-800 dark:data-pressed:bg-neutral-800 dark:disabled:text-neutral-400 focus-visible:bg-neutral-100 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 focus-visible:relative dark:focus-visible:outline-white"
>File</Menu.Trigger
>
<Menu.Portal>
<Menu.Positioner class="outline-none" :side-offset="4">
<Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
<Menu.Popup
class="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-none transition-[scale,opacity] duration-100 ease-out data-instant:transition-none dark:border-white dark:bg-neutral-950 dark:text-white dark:shadow-none"
>
<Menu.Item
class="flex cursor-default items-center justify-between gap-4 py-2 pr-4 pl-4 text-sm leading-4 font-normal 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"
@click="handleClick"
>New</Menu.Item
>
<Menu.Item
class="flex cursor-default items-center justify-between gap-4 py-2 pr-4 pl-4 text-sm leading-4 font-normal 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"
@click="handleClick"
>Open</Menu.Item
>
<Menu.Item
class="flex cursor-default items-center justify-between gap-4 py-2 pr-4 pl-4 text-sm leading-4 font-normal 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"
@click="handleClick"
>Save</Menu.Item
>
<Menu.SubmenuRoot>
<Menu.SubmenuTrigger
class="flex cursor-default items-center justify-between gap-4 py-2 pr-2 pl-4 text-sm leading-4 font-normal outline-none 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 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"
>
Export
<CaretRightIcon />
</Menu.SubmenuTrigger>
<Menu.Portal>
<Menu.Positioner class="outline-none" :side-offset="-4" :align-offset="-4">
<Transition
:enter-from-class="popupHiddenClass"
:leave-to-class="popupHiddenClass"
>
<Menu.Popup
class="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-none transition-[scale,opacity] duration-100 ease-out data-instant:transition-none dark:border-white dark:bg-neutral-950 dark:text-white dark:shadow-none"
>
<Menu.Item
class="flex cursor-default items-center justify-between gap-4 py-2 pr-4 pl-4 text-sm leading-4 font-normal 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"
@click="handleClick"
>PDF</Menu.Item
>
<Menu.Item
class="flex cursor-default items-center justify-between gap-4 py-2 pr-4 pl-4 text-sm leading-4 font-normal 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"
@click="handleClick"
>PNG</Menu.Item
>
<Menu.Item
class="flex cursor-default items-center justify-between gap-4 py-2 pr-4 pl-4 text-sm leading-4 font-normal 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"
@click="handleClick"
>SVG</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="flex cursor-default items-center justify-between gap-4 py-2 pr-4 pl-4 text-sm leading-4 font-normal 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"
@click="handleClick"
>Print</Menu.Item
>
</Menu.Popup>
</Transition>
</Menu.Positioner>
</Menu.Portal>
</Menu.Root>
<Menu.Root>
<Menu.Trigger
class="h-8 border-0 bg-transparent px-3 font-[inherit] text-sm font-normal text-neutral-950 select-none data-pressed:bg-neutral-100 disabled:text-neutral-500 dark:text-white dark:focus-visible:bg-neutral-800 dark:data-pressed:bg-neutral-800 dark:disabled:text-neutral-400 focus-visible:bg-neutral-100 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 focus-visible:relative dark:focus-visible:outline-white"
>Edit</Menu.Trigger
>
<Menu.Portal>
<Menu.Positioner class="outline-none" :side-offset="4">
<Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
<Menu.Popup
class="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-none transition-[scale,opacity] duration-100 ease-out data-instant:transition-none dark:border-white dark:bg-neutral-950 dark:text-white dark:shadow-none"
>
<Menu.Item
class="flex cursor-default items-center justify-between gap-4 py-2 pr-4 pl-4 text-sm leading-4 font-normal 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"
@click="handleClick"
>Cut</Menu.Item
>
<Menu.Item
class="flex cursor-default items-center justify-between gap-4 py-2 pr-4 pl-4 text-sm leading-4 font-normal 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"
@click="handleClick"
>Copy</Menu.Item
>
<Menu.Item
class="flex cursor-default items-center justify-between gap-4 py-2 pr-4 pl-4 text-sm leading-4 font-normal 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"
@click="handleClick"
>Paste</Menu.Item
>
</Menu.Popup>
</Transition>
</Menu.Positioner>
</Menu.Portal>
</Menu.Root>
<Menu.Root>
<Menu.Trigger
class="h-8 border-0 bg-transparent px-3 font-[inherit] text-sm font-normal text-neutral-950 select-none data-pressed:bg-neutral-100 disabled:text-neutral-500 dark:text-white dark:focus-visible:bg-neutral-800 dark:data-pressed:bg-neutral-800 dark:disabled:text-neutral-400 focus-visible:bg-neutral-100 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 focus-visible:relative dark:focus-visible:outline-white"
>View</Menu.Trigger
>
<Menu.Portal>
<Menu.Positioner class="outline-none" :side-offset="4">
<Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
<Menu.Popup
class="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-none transition-[scale,opacity] duration-100 ease-out data-instant:transition-none dark:border-white dark:bg-neutral-950 dark:text-white dark:shadow-none"
>
<Menu.Item
class="flex cursor-default items-center justify-between gap-4 py-2 pr-4 pl-4 text-sm leading-4 font-normal 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"
@click="handleClick"
>Zoom In</Menu.Item
>
<Menu.Item
class="flex cursor-default items-center justify-between gap-4 py-2 pr-4 pl-4 text-sm leading-4 font-normal 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"
@click="handleClick"
>Zoom Out</Menu.Item
>
<Menu.SubmenuRoot>
<Menu.SubmenuTrigger
class="flex cursor-default items-center justify-between gap-4 py-2 pr-2 pl-4 text-sm leading-4 font-normal outline-none 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 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"
>
Layout
<CaretRightIcon />
</Menu.SubmenuTrigger>
<Menu.Portal>
<Menu.Positioner class="outline-none" :side-offset="-4" :align-offset="-4">
<Transition
:enter-from-class="popupHiddenClass"
:leave-to-class="popupHiddenClass"
>
<Menu.Popup
class="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-none transition-[scale,opacity] duration-100 ease-out data-instant:transition-none dark:border-white dark:bg-neutral-950 dark:text-white dark:shadow-none"
>
<Menu.Item
class="flex cursor-default items-center justify-between gap-4 py-2 pr-4 pl-4 text-sm leading-4 font-normal 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"
@click="handleClick"
>Single Page</Menu.Item
>
<Menu.Item
class="flex cursor-default items-center justify-between gap-4 py-2 pr-4 pl-4 text-sm leading-4 font-normal 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"
@click="handleClick"
>Two Pages</Menu.Item
>
<Menu.Item
class="flex cursor-default items-center justify-between gap-4 py-2 pr-4 pl-4 text-sm leading-4 font-normal 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"
@click="handleClick"
>Continuous</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="flex cursor-default items-center justify-between gap-4 py-2 pr-4 pl-4 text-sm leading-4 font-normal 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"
@click="handleClick"
>Full Screen</Menu.Item
>
</Menu.Popup>
</Transition>
</Menu.Positioner>
</Menu.Portal>
</Menu.Root>
<Menu.Root disabled>
<Menu.Trigger
class="h-8 border-0 bg-transparent px-3 font-[inherit] text-sm font-normal text-neutral-950 select-none data-pressed:bg-neutral-100 disabled:text-neutral-500 dark:text-white dark:focus-visible:bg-neutral-800 dark:data-pressed:bg-neutral-800 dark:disabled:text-neutral-400 focus-visible:bg-neutral-100 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 focus-visible:relative dark:focus-visible:outline-white"
>Help</Menu.Trigger
>
</Menu.Root>
</Menubar>
</template>Anatomy
Import the component and assemble its parts:
vue
<script setup lang="ts">
import { Menu } from '@vase-ui/vue/menu';
import { Menubar } from '@vase-ui/vue/menubar';
</script>
<template>
<Menubar>
<Menu.Root>
<Menu.Trigger />
<Menu.Portal>
<Menu.Backdrop />
<Menu.Positioner>
<Menu.Popup>
<Menu.Arrow />
<Menu.Item />
<Menu.LinkItem />
<Menu.Separator />
<Menu.SubmenuRoot>
<Menu.SubmenuTrigger />
</Menu.SubmenuRoot>
<Menu.Group>
<Menu.GroupLabel />
</Menu.Group>
<Menu.RadioGroup>
<Menu.RadioItem value="" />
</Menu.RadioGroup>
<Menu.CheckboxItem />
<Menu.Viewport />
</Menu.Popup>
</Menu.Positioner>
</Menu.Portal>
</Menu.Root>
</Menubar>
</template>API reference
Menubar
The container for menus.
Renders a <div> element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
disabled | boolean | undefined | false | The user cannot open the menus of the bar. |
id | string | undefined | The id of the element. | |
loopFocus | boolean | undefined | true | An arrow key at the last trigger goes to the first trigger, and the other way. |
modal | boolean | undefined | true | The page does not scroll and gets no pointer while a menu of the bar is open. |
orientation | "horizontal" | "vertical" | undefined | 'horizontal' | The axis of the bar: its arrow keys move between the triggers. |
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A 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
| Slot | Slot props | Description |
|---|---|---|
default | state: MenubarState | The content of the part. |
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: MenubarState | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLElement | null | The element of the part, or null while it is not mounted. |
Selectors
| Selector | Description |
|---|---|
[aria-orientation] | The axis of the menubar: horizontal or vertical. |
:has([aria-expanded="true"]) | A menu of the menubar is open. |
Differences from Base UI
Vase UI ports Menubar from Base UI 1.9.0.
Behavior
| Vase UI | Evidence |
|---|---|
| In Safari on a Mac, a focus with no related target opens the popup of a trigger only when the last input of the window was a key. Each trigger records that input while it is mounted, also while it is not enabled. Base UI records it only while the trigger is enabled, and it assumes a key before the first record. A trigger of a menubar is enabled only while a menu of the menubar is open, so it misses the press that opened the menu. A hover on the next trigger then opens the next menu, the first menu gives the focus back to its trigger, and that focus opens the first menu again. Both menus then close. |
|
When the item that has the tab stop of a composite becomes disabled while the focus is outside the composite, and the arrow keys skip that item, the tab stop moves to the active item when the arrow keys reach it, or else to the first item that they reach. When the item becomes disabled while it has the focus, the tab stop moves when the focus leaves. At the mount, a checked radio that is a disabled native button also gives the tab stop to the first radio that the arrow keys reach. The arrow keys skip a natively disabled item. They also skip an aria-disabled item, unless the root gives disabledIndices and the item is not in it. Thus the Tab key does not focus a radio that the arrow keys skip in a Radio Group with no checked radio, and a Toggle Group or a Menubar stays in the order of the Tab key. Toolbar.Root keeps the tab stop on a disabled item that stays focusable. An active item that becomes disabled keeps the tab stop while it can get focus, as at the mount. In Base UI, an item that becomes disabled keeps the tab stop, and at the mount a checked radio keeps it also when it is a disabled native button. The Tab key then focuses a disabled radio, or it skips a whole Radio Group, Toggle Group or Menubar, because the item with the tab stop has the disabled attribute. A native control also follows its fieldset when it or its wrapper moves. Controls in the first legend keep the native exemption. |
|
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. | |
--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 handbook gives the differences that all components share: Styling, Animation, Composition, Customization, Forms and TypeScript.