Menu
Navigation with submenu, select, collapse, themes, keyboard and native links.
When to use
Menu organizes sections of the application, shows the selected item and expands nested navigation. Dropdown is suitable for a short list of actions for a button; Menu - for a stable section structure. Page transitions must remain real links.
Menu CSS prefixes show global ConfigProvider.prefixCls and local prefixCls without resetting state. All modes, items, groups and submenus use a local prefix. The theme and link settings are independent; selection and disclosure are preserved.
Navigation modes and structure
In Svelte, the tree defines items. A regular item has a stable key and label, a submenu - children, a group - type:group, a separator - type:divider. Event keys are cast to strings. label and icon accept snippets; place the link inside the label-snippet, since MenuItem does not have a separate href.
| Script | Setting | Example |
|---|---|---|
| Header panel | mode="horizontal" |
Horizontal list |
| Tree inside sidebar | mode="inline" |
Nested Sections |
| Submenu on the side | mode="vertical" |
Vertical list |
| Narrow sidebar | inlineCollapsed, LayoutSider |
Menu in Sider |
| Multiple selected items | multiple |
Choices and commands |
Inline submenus expand within the list. vertical and horizontal submenus open in a separate panel. Hover over a collapsed item to see its label in a tooltip.
Selecting, opening and application status
defaultSelectedKeys and defaultOpenKeys set the initial local state. selectedKeys and openKeys - controlled props: handle onSelect/onDeselect and onOpenChange, then pass the updated arrays back. bind is not provided for these props.
onClick reports key, keyPath, domEvent and itemData. Selectable:false allows commands to be left without selectable state. multiple allows multiple selected keys. Selecting an item should not itself replace application routing: the corresponding selectedKeys are usually derived from the current address.
For "one branch at a time" mode, the application stores openKeys and saves the ancestors of the new submenu. A regular inline allows several expanded branches. Accordion shows this logic without changing the menu data.
Popup, keyboard and responsiveness
triggerSubMenuAction selects hover or click; opening and closing delays are measured in seconds. The missing getPopupContainer inherits ConfigProvider, and the own undefined disables inheritance. This is different from Dropdown, where undefined saves the fallback. forceSubMenuRender creates hidden branches in advance; SSR does not call the container's getter.
Arrows, Home/End and Enter move focus and open branches; horizontal navigation and RTL take direction into account. Escape closes the popup. Space does not serve as a universal activation of the li clause. Through bind:this focus(options?) and findItem({key}); searching for a DOM node does not reveal the hidden branch.
When you quickly open a second nested popup, focus can stay on the branch title. Enter then activates the title and leaves the child item unselected.
Narrow the horizontal menu to move the last sections into More. Widen it to bring them back.
In the styling example, ConfigProvider.menu supplies a shared class and the list sets its padding through styles. Design tokens control theme colors and sizes.
Examples
Reports section. Selected Key:
Horizontal navigation
When space runs out, the last items move into the More submenu.
<script lang="ts">
import { Menu } from '@woodger/antd';
let selected = $state<string[]>(['overview']);
</script>
{#snippet reports()}
<a href={('#menu-horizontal-report')}>{("Reports")}</a>
{/snippet}
<nav aria-label={("Project sections")}>
<Menu
mode="horizontal"
style="
min-width: 0;
flex: 1;
"
aria-label={("Horizontal project menu")}
overflowedIndicator={("More")}
selectedKeys={selected}
onSelect={info => selected = info.selectedKeys}
items={([
{ key: 'overview', label: "Overview" },
{ key: 'archive', label: "Archive", disabled: true },
{
key: 'settings', label: "Settings", children: [
{ key: 'team', label: "Team" }, { key: 'access', label: "Access" }
]
},
{ key: 'reports', label: reports }
])}
/>
</nav>
<p id="menu-horizontal-report">
{("Reports section. Selected Key: ")}
<output aria-label={("Select horizontal Menu")}>{selected.join(', ')}</output>
</p>
<style>
nav {
display: flex;
min-width: 0;
}
p {
margin: 16px 0 0;
scroll-margin-top: 160px;
}
</style>
-
- Home
- Connection
- Theme
- Help
Nested navigation
In inline mode, the submenu opens inside the list. defaultOpenKeys/defaultSelectedKeys set the initial state; Nested groups combine related items.
<script lang="ts">
import { Menu } from '@woodger/antd';
let chosen = $state('install');
</script>
<style>
.preview {
max-width: 280px;
}
output {
display: block;
margin-top: 16px;
}
</style>
<div class="preview">
<Menu mode="inline" aria-label={("Nested navigation")} defaultOpenKeys={['guides']}
defaultSelectedKeys={['install']} onSelect={info => chosen = info.key}
items={([
{ key: 'guides', label: "Manuals", children: [
{ type: 'group', key: 'start', label: "Home", children: [
{ key: 'install', label: "Connection" }, { key: 'theme', label: "Theme" }
] },
{ key: 'examples', label: "Examples", children: [
{ key: 'forms', label: "Forms" }, { key: 'tables', label: "Tables" }
] }
] },
{ key: 'help', label: "Help" }
])} />
</div>
<output aria-label={("Select submenu")}>{chosen}</output>
- Overview
-
- Documents
- Files
- Archive
Collapsed menu
inlineCollapsed leaves the icons and opens the submenu as a popup. After expanding, the local menu restores previously expanded inline sections.
<script lang="ts">
import { Button, Menu } from '@woodger/antd';
let collapsed = $state(false);
</script>
<style>
.controls {
margin-bottom: 16px;
}
.preview {
max-width: 280px;
}
</style>
{#snippet icon()}
<svg
width="1em"
height="1em"
viewBox="0 0 16 16"
fill="none"
stroke="currentColor"
aria-hidden="true"
>
<rect x="2" y="2" width="12" height="12" rx="2" />
<path d="M5 6h6M5 10h6" />
</svg>
{/snippet}
<div class="controls"><Button onclick={() => collapsed = !collapsed}>{(collapsed ? "Expand menu" : "Collapse menu")}</Button></div>
<div class="preview">
<Menu mode="inline" inlineCollapsed={collapsed} aria-label={("Collapsible menu")}
defaultSelectedKeys={['docs']} defaultOpenKeys={['project']}
items={([
{ key: 'home', label: "Overview", icon },
{
key: 'project', label: "Project", icon, children: [
{ key: 'docs', label: "Documents" }, { key: 'files', label: "Files" }
]
},
{ key: 'archive', label: "Archive", icon, disabled: true }
])} />
</div>
- Tasks
- Calendar
Label of the folded item
In a collapsed menu, the tooltip shows the item label. Set title to supply different text.
<script lang="ts">
import { Checkbox, Menu } from '@woodger/antd';
let custom = $state(true);
</script>
<style>.controls { margin-bottom:16px; }</style>
{#snippet icon()}
<svg
width="1em"
height="1em"
viewBox="0 0 16 16"
fill="none"
stroke="currentColor"
aria-hidden="true"
>
<rect x="2" y="2" width="12" height="12" rx="2" />
<path d="M5 6h6M5 10h6" />
</svg>
{/snippet}
<div
class="controls"
><Checkbox
bind:checked={custom}
>{("Own item label")}</Checkbox></div>
<Menu
mode="inline"
inlineCollapsed
tooltip={{ placement: 'right' }}
aria-label={("Menu with tooltip")}
items={([
{ key: 'tasks', label: "Tasks", icon, title: custom ? "Open task list" : undefined },
{ key: 'calendar', label: "Calendar", icon }
])}
/>
-
-
- Input fields
-
One branch at a time
The application controls openKeys and leaves only the path to the new submenu. Opening an adjacent branch closes the previous one along with its child sections.
<script lang="ts">
import { Menu } from '@woodger/antd';
let opened = $state<string[]>(['guides', 'forms']);
const parents: Record<string, string | undefined> = {
guides: undefined, forms: 'guides', data: 'guides', project: undefined
};
function changeOpen(keys: string[]) {
const added = keys.find(key => !opened.includes(key));
if (added) {
const path: string[] = [];
for (let key: string | undefined = added; key; key = parents[key]) path.unshift(key);
opened = path;
return;
}
opened = keys.filter(key => !parents[key] || keys.includes(parents[key]!));
}
</script>
<style>
.preview {
max-width: 280px;
}
output {
display: block;
margin-top: 16px;
}
</style>
<div
class="preview"
><Menu
mode="inline"
aria-label={("Menu of one branch")}
openKeys={opened}
onOpenChange={changeOpen}
items={([
{
key: 'guides', label: "Manuals", children: [
{ key: 'forms', label: "Forms", children: [{ key: 'inputs', label: "Input fields" }] },
{ key: 'data', label: "Data", children: [{ key: 'table', label: "Table" }] }
]
},
{ key: 'project', label: "Project", children: [{ key: 'team', label: "Team" }] }
])}
/></div>
<output aria-label={("Expanded Menu branches")}>{(opened.join(' → ')
|| ("No open branches"))}</output>
- Home
Vertical popup menu
Unlike inline, the child list appears next to the item. triggerSubMenuAction selects hover or click; The keyboard opens and closes nested levels.
<script lang="ts">
import { Checkbox, Menu } from '@woodger/antd';
let click = $state(true);
let chosen = $state('');
</script>
<style>.controls {
margin-bottom:16px;
} .preview {
max-width:280px;
} output {
display:block;
margin-top:16px;
}</style>
<div
class="controls"
><Checkbox
bind:checked={click}
>{("Open by pressing")}</Checkbox></div>
<div class="preview"><Menu mode="vertical" aria-label={("Vertical sections")}
triggerSubMenuAction={click ? 'click' : 'hover'} onSelect={info => chosen = info.key}
items={([
{ key: 'home', label: "Home" },
{
key: 'workspace', label: "Work area", children: [
{ key: 'tasks', label: "Tasks" },
{ key: 'settings', label: "Parameters", children: [{ key: 'access', label: "Access" }] }
]
}
])} /></div>
<output aria-label={("Vertical Menu Select")}>{(chosen
|| ("Nothing selected"))}</output>
- Inbox8
- Sent
- Cart
Light and dark themes
theme switches between light and dark Menu palettes. The selection is stored in the application and persists when changing themes.
<script lang="ts">
import { Checkbox, Menu } from '@woodger/antd';
let dark = $state(true);
let selected = $state<string[]>(['inbox']);
</script>
<style>
.controls {
margin-bottom: 16px;
}
.preview {
max-width: 280px;
}
</style>
<div class="controls"><Checkbox bind:checked={dark}>{("Dark menu")}</Checkbox></div>
<div class="preview"><Menu mode="inline" theme={dark ? 'dark' : 'light'}
aria-label={("Menu with theme change")} selectedKeys={selected}
onSelect={info => selected = info.selectedKeys} items={([
{ key: 'inbox', label: "Inbox", extra: '8' },
{ key: 'sent', label: "Sent" }, { key: 'trash', label: "Cart", danger: true }
])} /></div>
- Home
Submenu theme
subMenu.theme refines the palette of a separate branch. Here the root remains dark, but the popup can be made light.
<script lang="ts">
import { Checkbox, Menu } from '@woodger/antd';
let light = $state(true);
</script>
<style>
.controls {
margin-bottom: 16px;
}
.preview {
max-width: 280px;
}
</style>
<div
class="controls"
><Checkbox
bind:checked={light}
>{("Light submenu")}</Checkbox></div>
<div class="preview"><Menu mode="vertical" theme="dark" triggerSubMenuAction="click"
aria-label={("Menu with a separate thread topic")} items={([
{ key: 'home', label: "Home" },
{
key: 'project', label: "Project sections", theme: light ? 'light' : 'dark', children: [
{ key: 'docs', label: "Documents" }, { key: 'files', label: "Files" }
]
}
])} /></div>
- Home
-
- Documents
- Files
Mode switching
The selected keys remain the state of the application. When switching between inline and popup mode, open submenus may be closed; the current openKeys is shown separately.
<script lang="ts">
import { Menu, type MenuMode } from '@woodger/antd';
let mode = $state<MenuMode>('inline');
let selected = $state<string[]>(['docs']);
let opened = $state<string[]>(['project']);
</script>
<style>
label {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
margin-bottom: 16px;
}
.scroll {
max-width: 100%;
overflow-x: auto;
}
output {
display: block;
margin-top: 16px;
}
select {
max-width: 100%;
font: inherit;
}
</style>
<label>{("Menu Mode ")}<select bind:value={mode}>
<option value="inline">inline</option><option value="vertical">vertical</option>
<option value="horizontal">horizontal</option>
</select></label>
<div class="scroll">
<Menu {mode} triggerSubMenuAction="click" aria-label={("Menu with mode change")}
selectedKeys={selected} openKeys={opened} onSelect={info => selected = info.selectedKeys}
onOpenChange={keys => opened = keys} items={([
{ key: 'home', label: "Home" },
{
key: 'project', label: "Project", children: [
{ key: 'docs', label: "Documents" }, { key: 'files', label: "Files" }
]
}
])} />
</div>
<output aria-label={("Menu mode status")}>{mode}: {selected.join(', ')}{("; open: ")}{(opened
.join(', ')
|| ("no"))}</output>
- Work
- Tasks2
- Archive
- Delete project
Point structure
items combines groups, separators, icons, extra and item states. label and extra accept text, number or Snippet; disabled excludes the action from selection.
<script lang="ts">
import { Menu } from '@woodger/antd';
</script>
<style>.preview { max-width:280px; }</style>
{#snippet icon()}
<svg
width="1em"
height="1em"
viewBox="0 0 16 16"
fill="none"
stroke="currentColor"
aria-hidden="true"
>
<rect x="2" y="2" width="12" height="12" rx="2" />
<path d="M5 6h6M5 10h6" />
</svg>
{/snippet}
{#snippet selectedIcon({ isSelected }: { isSelected: boolean })}
{#if isSelected}<span aria-hidden="true">✓</span>{/if}
{/snippet}
{#snippet extra()}<span aria-label={("Two new entries")}>2</span>{/snippet}
<div class="preview">
<Menu
itemIcon={selectedIcon}
aria-label={("Menu groups and states")}
items={([
{
type: 'group', key: 'work', label: "Work", children: [
{ key: 'tasks', label: "Tasks", icon, extra },
{ key: 'archive', label: "Archive", disabled: true }
]
},
{ type: 'divider', key: 'separator', dashed: true },
{ key: 'delete', label: "Delete project", danger: true }
])} />
</div>
- Documents
- Files
- Notes
Multiple selection and commands
multiple controls the set of selected items. selectable=false leaves onClick but stops changing the selection; already selected keys are retained until reset.
<script lang="ts">
import { Button, Checkbox, Menu } from '@woodger/antd';
let selectable = $state(true);
let selected = $state<string[]>(['docs']);
let clicked = $state('');
</script>
<style>
.controls {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 12px;
margin-bottom: 16px;
}
.preview {
max-width: 280px;
}
output {
display: block;
margin-top: 12px;
}
</style>
<div
class="controls"
><Checkbox
bind:checked={selectable}
>{("Allow selection")}</Checkbox>
<Button onclick={() => selected = []}>{("Reset selection")}</Button></div>
<div class="preview"><Menu mode="inline" multiple {selectable}
aria-label={("Multiple selection menu")} selectedKeys={selected}
onSelect={info => selected = info.selectedKeys} onDeselect={info => selected = info.selectedKeys}
onClick={info => clicked = info.keyPath.join(' / ')} items={([
{ key: 'docs', label: "Documents" }, { key: 'files', label: "Files" },
{ key: 'notes', label: "Notes" }
])} /></div>
<output aria-label={("Multiple Select Menu")}>{(selected.join(', ')
|| ("No items selected"))}</output>
<output
aria-label={("Press Menu")}
>{(clicked || ("No clicks"))}</output>
Submenu container
The general getter specifies the ConfigProvider. A custom getter replaces it, and an explicitly passed undefined disables inheritance - this is different from fallback Dropdown.
<script lang="ts">
import type { Snippet } from 'svelte';
import { ConfigProvider, Menu, type MenuProps } from '@woodger/antd';
let target = $state<'provider' | 'local' | 'native'>('provider');
let providerTarget = $state<HTMLDivElement>();
let localTarget = $state<HTMLDivElement>();
let popupProps = $derived<Pick<MenuProps, 'getPopupContainer'>>(
target === 'provider'
? {}
: target === 'local'
? { getPopupContainer: () => localTarget! }
: { getPopupContainer: undefined }
);
</script>
<style>
label {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
margin-bottom: 16px;
}
.preview {
max-width: 280px;
}
.targets {
display: grid;
gap: 12px;
margin-top: 16px;
}
.branch-popup { background: var(--ant-color-bg-elevated); }
.branch-popup strong {
display: block;
padding: 8px 16px;
}
.target {
min-height:44px;
padding:12px;
border:1px dashed var(--ant-color-border);
border-radius:6px;
}
select {
max-width: 100%;
font: inherit;
}
</style>
{#snippet popupRender(origin: Snippet<[children?: Snippet]>)}
<div class="branch-popup">
<strong>{("Project")}</strong>
{@render origin()}
</div>
{/snippet}
<label>{("Menu Container ")}<select bind:value={target}>
<option
value="provider"
>ConfigProvider</option><option
value="local"
>{("Local")}</option>
<option value="native">{("Without getter")}</option>
</select></label>
<ConfigProvider getPopupContainer={() => providerTarget!}>
<div class="preview"><Menu {...popupProps} {popupRender} mode="vertical" triggerSubMenuAction="click"
aria-label={("Menu with container selection")} items={([
{
key: 'project', label: "Project menu", popupOffset: [4, 0], children: [
{ key: 'docs', label: "Documents" }, { key: 'files', label: "Files" }
]
}
])} /></div>
<div class="targets">
<div class="target provider-target" bind:this={providerTarget}>
{("ConfigProvider Container")}
</div>
<div
class="target local-target"
bind:this={localTarget}
>{("Local container")}</div>
</div>
</ConfigProvider>
- Documents
- Files
Component tokens
The local theme sets the height, rounding and colors of the selected item. colorSuccess values respond to the overall theme; adjacent Menus retain their settings.
<script lang="ts">
import { ConfigProvider, Menu, theme } from '@woodger/antd';
const tokens = theme.useToken();
let height = $state(44);
</script>
<style>
label {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
margin-bottom: 16px;
}
.preview { max-width:280px; }
</style>
<label>{("Menu item height ")}<input
type="range"
min="32"
max="56"
bind:value={height}
/>
<output>{height}px</output></label>
<ConfigProvider theme={{
cssVar: {}, components: {
Menu: {
itemHeight: height, itemBorderRadius: 12,
itemSelectedColor: tokens.token.colorSuccess, itemSelectedBg: tokens.token.colorSuccessBg
}
}
}}>
<div class="preview"><Menu mode="inline" aria-label={("Menu with its own theme")}
defaultSelectedKeys={['docs']} items={([
{ key: 'docs', label: "Documents" }, { key: 'files', label: "Files" }
])} /></div>
</ConfigProvider>
- Documents
- Files
Formatting of root and clause
ConfigProvider.menu sets the shared root class. Local styles set the list padding.
<script lang="ts">
import { Checkbox, ConfigProvider, Menu } from '@woodger/antd';
let accent = $state(true);
</script>
<style>
.controls {
margin-bottom: 16px;
}
.preview {
max-width: 280px;
}
.preview :global(.example-menu-root) {
border:1px solid var(--ant-color-border);
border-radius:8px;
}
.preview :global(.example-menu-accent) { font-weight:600; }
</style>
<div
class="controls"
><Checkbox
bind:checked={accent}
>{("Select item")}</Checkbox></div>
<div class="preview">
<ConfigProvider menu={{ classNames: { root: 'example-menu-root' } }}>
<Menu
aria-label={("Designed menu")}
styles={() => ({ root: 'padding:8px' })}
items={([
{ key: 'docs', label: "Documents", class: accent ? 'example-menu-accent' : undefined },
{ key: 'files', label: "Files", style: 'font-style:italic' }
])}
/>
</ConfigProvider>
</div>
- Overview
- Archive
- Access
Native element and focus
bind:nativeElement returns ul after mount. Public focus and findItem allow you to direct focus to an accessible item without searching through private CSS classes.
<script lang="ts">
import { Button, Menu } from '@woodger/antd';
let menu = $state<ReturnType<typeof Menu>>();
let element = $state<HTMLUListElement>();
</script>
<style>
.controls {
display: flex;
flex-wrap: wrap;
gap: 12px;
margin-bottom: 16px;
}
.preview {
max-width: 280px;
}
output {
display: block;
margin-top: 16px;
}
</style>
<div class="controls">
<Button onclick={() => menu?.focus()}>{("Menu focus")}</Button>
<Button onclick={() => menu?.findItem({ key: 'access' })?.focus()}>
{("Find “Access”")}
</Button>
</div>
<div class="preview"><Menu bind:this={menu} bind:nativeElement={element}
aria-label={("Menu with native ref")} items={([
{ key: 'home', label: "Overview" }, { key: 'archive', label: "Archive", disabled: true },
{ key: 'access', label: "Access" }
])} /></div>
<output aria-label={("Native Menu element")}>{(element?.tagName || "Waiting mount")}</output>
- Home
Direction and keyboard
direction is inherited from ConfigProvider. In a vertical popup menu, RTL changes the opening sides: ArrowLeft enters the submenu, ArrowRight returns to the parent.
<script lang="ts">
import { Checkbox, ConfigProvider, Menu } from '@woodger/antd';
let rtl = $state(true);
let chosen = $state('');
</script>
<style>.controls {
margin-bottom:16px;
} .preview {
max-width:280px;
} output {
display:block;
margin-top:16px;
}</style>
<div class="controls"><Checkbox bind:checked={rtl}>RTL Menu</Checkbox></div>
<ConfigProvider direction={rtl ? 'rtl' : 'ltr'}>
<div class="preview"><Menu
mode="vertical"
triggerSubMenuAction="click"
aria-label={("Menu with direction")}
onSelect={info => chosen = info.key}
items={([
{ key: 'home', label: "Home" },
{
key: 'sections', label: "Sections", children: [
{ key: 'docs', label: "Documents" }, { key: 'files', label: "Files" }
]
}
])}
/></div>
</ConfigProvider>
<output
aria-label={("Select RTL Menu")}
>{(chosen || ("Nothing selected"))}</output>
Menu inside Sider
Menu inherits the collapse of LayoutSider. The general collapsedWidth=80 leaves space for icons; The example is isolated within its own frame.
<script lang="ts">
import { Layout, LayoutSider, LayoutContent, Menu } from '@woodger/antd';
let collapsed = $state(false);
</script>
<style>
.preview {
min-width:0;
overflow:hidden;
border:1px solid var(--ant-color-border);
border-radius:8px;
isolation:isolate;
transform:translate(0);
}
.preview :global(.ant-layout-content) {
min-width: 0;
padding: 16px;
overflow-wrap: anywhere;
}
</style>
{#snippet icon()}
<svg
width="1em"
height="1em"
viewBox="0 0 16 16"
fill="none"
stroke="currentColor"
aria-hidden="true"
>
<rect x="2" y="2" width="12" height="12" rx="2" />
<path d="M5 6h6M5 10h6" />
</svg>
{/snippet}
<div class="preview">
<Layout hasSider style="min-height:240px">
<LayoutSider width={180} collapsedWidth={80} collapsible bind:collapsed theme="light"
expandLabel={("Expand Sider menu")} collapseLabel={("Collapse Sider menu")}>
<Menu
mode="inline"
aria-label={("Menu inside the sidebar")}
defaultSelectedKeys={['docs']}
items={([{ key: 'docs', label: "Documents", icon }, {
key: 'files',
label: "Files",
icon
}])}
/>
</LayoutSider>
<LayoutContent><output aria-label={("Collapse Sider Menu")}>{(collapsed ? "Panel folded" : "Panel open")}</output></LayoutContent>
</Layout>
</div>
- Library review
-
- Home
- Connection
- Forms
- Archive
Documentation section navigation
The menu remembers the selected item and expanded branches until you reset it.
<script lang="ts">
import { Menu, Button, type MenuItemType } from '@woodger/antd';
let selected = $state<string[]>(['overview']);
let opened = $state<string[]>(['guides']);
let result = $state('');
const items: MenuItemType[] = [
{ key: 'overview', label: overview },
{
key: 'guides',
label: "Manuals",
children: [
{
type: 'group',
key: 'start',
label: "Home",
children: [{ key: 'setup', label: "Connection" }, { key: 'forms', label: "Forms" }]
},
{
key: 'advanced',
label: "Additional",
children: [{ key: 'theme', label: "Themes" }, { key: 'locale', label: "Localization" }]
}
]
},
{ type: 'divider', key: 'divider' },
{ key: 'archive', label: "Archive", disabled: true }
];
</script>
<style>
output {
display: block;
margin-top: 16px;
}
</style>
{#snippet overview()}
<a href={("/ant-design#overview")}>
{("Library review")}
</a>
{/snippet}
<div style="max-width:400px">
<Menu
aria-label={("Example navigation")}
items={(items)}
mode="inline"
selectedKeys={selected}
openKeys={opened}
onOpenChange={keys => { opened = keys; }}
onSelect={info => {
selected = info.selectedKeys;
result = info.keyPath.join(' / ');
}}
onDeselect={info => {
selected = info.selectedKeys;
result = info.keyPath.join(' / ');
}}
/>
<Button
style="margin-top:16px"
onclick={() => {
selected = ['overview'];
opened = ['guides'];
result = '';
}}
>{("Reset menu")}</Button>
<output aria-label={("Selected menu item")}>{result}</output>
</div>
-
- Documentation
- Examples
All modes, items, groups and submenus use a local prefix. The theme and link settings are independent; selection and disclosure are preserved.
Menu CSS prefixes
Common namespace ConfigProvider and local prefixCls; the state of the component is preserved when the name is changed.
<script lang="ts">
import { Checkbox, ConfigProvider, Menu } from '@woodger/antd';
let custom = $state(true);
let local = $state(true);
const prefix = $derived(custom ? 'suite' : 'ant');
const localPrefix = $derived(local ? 'project-menu' : '');
let selectedKeys = $state(['docs']);
</script>
<style>
.example,
.prefix-stage {
display: grid;
grid-template-columns: minmax(0, 1fr);
gap: 16px;
min-width: 0;
}
.controls {
display: flex;
flex-wrap: wrap;
gap: 12px;
}
p { margin: 0; }
output { overflow-wrap: anywhere; }
</style>
<div class="example">
<div class="controls">
<Checkbox bind:checked={custom}>{("General prefix Menu suite")}</Checkbox>
<Checkbox bind:checked={local}>{("Local prefix Menu")}</Checkbox>
</div>
<ConfigProvider prefixCls={prefix} theme={{ cssVar: { prefix: 'menu-theme' } }}>
<div class="prefix-stage">
<Menu prefixCls={localPrefix} mode="inline" {selectedKeys} onSelect={info => selectedKeys = [
...info.selectedKeys
]} defaultOpenKeys={['project']}
aria-label={("Menu with prefix")} items={([
{
key: 'project', label: "Project", children: [
{ key: 'docs', label: "Documentation" }, { key: 'examples', label: "Examples" }
]
}
])} />
<output
aria-label={("Menu selection with prefix")}
>{selectedKeys.join(', ')}</output>
</div>
</ConfigProvider>
<output aria-label={("Menu CSS prefix")}>{("General: ")}{prefix}{("; local: ")}{(localPrefix
|| ("from the provider"))}</output>
<p>
{("All modes, items, groups and submenus use a local prefix. The theme and link settings are independent; selection and disclosure are preserved.")}
</p>
</div>
API
Examples are checked against the current ant.design page and the public API of the installed package. Full definitions of Props are in @woodger/antd.
| Theme | Example or limitation |
|---|---|
| Top Navigation | When space runs out, the last items move into the More submenu. |
| Inline menu | Nested sections and groups, initial open/selected keys. |
| Collapsed inline menu | Inline folding and separate composition with LayoutSider. |
| Menu tooltip | In a collapsed menu, the tooltip shows the item label. Set title to supply different text. |
| Open current submenu only | Controlled path of one opened branch; the adjacent branch replaces the old one. |
| Vertical menu | Popup submenu with hover/click, attachment and keyboard. |
| Menu Themes | Light and dark palettes with saved selection. |
| Sub-menu theme | Separate palette of a branch on a dark root. |
| Switch the menu type | Switching of all three modes with controlled keys. |
| Custom semantic dom styling | ConfigProvider.menu sets the shared root class. Local styles set the list padding. |
| Custom Submenu Render | popupRender adds a heading above the original submenu list. |
| Property | Description | Type | Default |
|---|---|---|---|
overflowedIndicator | Label for the submenu that holds items that no longer fit in the row. | MenuContent | false | null | … |
popupRender | Wraps or replaces a submenu. A branch can supply its own snippet. | MenuPopupRender | — |
builtinPlacements | Sets positions for submenus and the overflow list. Set popupOffset on a single branch to offset it. | Record<string, MenuPopupAlign> | — |
tooltip | Tooltip options for collapsed items. Set false to turn tooltips off. | MenuTooltip | — |
motion | Configures transitions for inline lists and popup submenus. | MenuMotion | — |
itemIcon | Icon after the label and extra. Its snippet receives the item selection state. | MenuItemIcon | — |
prefixCls | Full CSS prefix of the component and its parts. A non-empty local prop takes precedence; empty string and undefined inherit ConfigProvider. The namespace of the topic is set separately. | string | ConfigProvider.prefixCls + "-menu" |
items | Items, submenus, groups, separators and null. label/icon/extra use Snippet instead of JSX. | readonly MenuItemType[] | [] |
mode | Arranges sections horizontally, vertically or in an inline tree. | 'vertical' | 'horizontal' | 'inline' | vertical |
theme | Palette Menu; subMenu.theme refines it for the branch. | 'light' | 'dark' | light |
selectedKeys | Guided selection; update the array from onSelect/onDeselect. bind is not supported. | readonly string[] | Local state |
defaultSelectedKeys | Initial selection; subsequent changes to prop do not reset the state. | readonly string[] | [] |
openKeys | Controlled submenu list; update from onOpenChange. | readonly string[] | Local state |
defaultOpenKeys | Initially expanded sections. | readonly string[] | [] |
onOpenChange | Disclosure request; a single branch rule belongs to the application. | (keys: string[]) => void | — |
multiple | Allows multiple selections. | boolean | false |
selectable | Controls selection changes; onClick remains available. | boolean | true |
disabled | Unavailability of the entire Menu. Explicitly pass prop; ConfigProvider.componentDisabled is not read by Menu. | boolean | false |
inlineCollapsed | Explicit prop specifies inherited folding. Does not apply to horizontal. | boolean | From LayoutSider |
inlineIndent | Level indent in inline, taking into account direction. | number | 24 |
triggerSubMenuAction | For popup submenu. Inline opens by pressing. | 'hover' | 'click' | hover |
subMenuOpenDelay | Hover opening delay in seconds. | number | 0.1 |
subMenuCloseDelay | Hover closing delay in seconds. | number | 0.1 |
forceSubMenuRender | Creates hidden content before first opening. | boolean | false |
onClick | key, keyPath, domEvent and itemData. keyPath goes from the item up. | (info: MenuClickInfo) => void | — |
onSelect | Transmits selectedKeys along with the data of the clicked item. | (info: MenuSelectInfo) => void | — |
onDeselect | The multiple example updates the selected keys from the callback. | (info: MenuSelectInfo) => void | — |
getPopupContainer | Own undefined disables getter inheritance. When force render zero-arity the getter may first be undefined. | (trigger: HTMLElement) => HTMLElement | ShadowRoot | From ConfigProvider |
nativeElement | bind:nativeElement returns the root ul and is cleared when unmounted. | HTMLUListElement | undefined | After mount |
rootClassName | Additional root list class, next to class. | string | — |
style | CSS root ul. Native HTML and aria/data attributes are passed to the root. | string | — |
Item and submenu structure
Items support label, icon, extra and a trailing itemIcon. A branch can set children, popupOffset and expandIcon. Rows and branch titles have hover callbacks. Rows also accept data attributes.
Semantic DOM
Root - ul role=menu. The items create li role=menuitem, the submenu title is a native button with aria-expanded/aria-controls. Pass the link as a inside label-snippet. Groups and separators remain separate structural units.
Inline uses ArrowUp/ArrowDown, Home/End and Enter for expansion and selection. In horizontal ArrowLeft/ArrowRight moves focus between the top items, ArrowDown opens a submenu. In a vertical popup, left/right arrows enter and exit branches based on RTL; Escape closes the popup. Space is not a universal selection key li.
Use bind:this to access focus and findItem. Looking up a key returns its mounted DOM node or null.
Registration tokens
Menu is connected to ConfigProvider theme.components.Menu. The card checks the height and rounding of the items, color and background of the selection; The overall colors and typography follow the theme of the section. The main modern token names are listed below, the full set is in the package types.
| Token | Purpose |
|---|---|
itemHeight | Point height. |
itemBorderRadius | Point rounding. |
itemSelectedColor | Color of the selected item. |
itemSelectedBg | Background of the selected item. |
itemColor | Normal text color. |
itemHoverColor | Hover color. |
itemHoverBg | Background when hovering. |
itemDisabledColor | Color of the inaccessible item. |
itemPaddingInline | Horizontal offset. |
itemMarginInline | External horizontal indent. |
itemMarginBlock | External vertical indent. |
collapsedWidth | Collapsed menu width. |
dropdownWidth | Popup submenu width. |
activeBarHeight | Height of the active indicator horizontal. |
darkItemBg | Dark Menu background. |
darkItemSelectedBg | Dark Menu selection background. |
zIndexPopup | CSS z-index popup. |
| Token | Current value |
|---|---|
colorBgContainer | #ffffff |
colorBgElevated | #ffffff |
colorText | rgba(0,0,0,0.88) |
colorPrimary | #2f54eb |
colorTextDisabled | rgba(0,0,0,0.25) |
fontSize | 14 |
lineHeight | 1.5714285714285714 |
borderRadiusLG | 8 |
FAQ
How do I customize the overflow button?
Set the label with overflowedIndicator. In a flex container, let Menu shrink with min-width: 0. To keep every item in the row, pass disabledOverflow.
Why doesn't selectedKeys change itself?
This is a controlled prop. Update the array in callback; defaultSelectedKeys is only needed for the initial local selection.
How to expand only one branch?
Manage openKeys in the application and save the ancestors of the new branch.
How do I change a collapsed item’s tooltip?
Set the item’s title for its text. Set tooltip on the menu for shared Tooltip options, or pass false to disable tooltips.
Why is the container not inherited when undefined?
For Menu, its own undefined disables the generic getPopupContainer. To inherit getter, don't pass prop.
Do Menu.Item and subMenu need to be in the markup?
No. In this Svelte API, the structure is specified by items, and complex content is specified by snippets.