@ui-sdk/react 0.0.0-stage → 0.1.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +10 -2
- package/dist/accordion.d.ts +331 -0
- package/dist/accordion.js +25 -0
- package/dist/agent.d.ts +2 -0
- package/dist/agent.js +8 -0
- package/dist/alert-dialog.d.ts +56 -0
- package/dist/alert-dialog.js +45 -0
- package/dist/async-options.d.ts +22 -0
- package/dist/async-options.js +56 -0
- package/dist/autocomplete.d.ts +102 -0
- package/dist/autocomplete.js +195 -0
- package/dist/avatar.d.ts +301 -0
- package/dist/avatar.js +17 -0
- package/dist/button.d.ts +21 -0
- package/dist/button.js +45 -0
- package/dist/calendar-context.d.ts +10 -0
- package/dist/calendar-context.js +9 -0
- package/dist/calendar.d.ts +80 -0
- package/dist/calendar.js +257 -0
- package/dist/carousel.d.ts +52 -0
- package/dist/carousel.js +151 -0
- package/dist/checkbox.d.ts +24 -0
- package/dist/checkbox.js +98 -0
- package/dist/children.d.ts +38 -0
- package/dist/children.js +63 -0
- package/dist/collapsible.d.ts +302 -0
- package/dist/collapsible.js +19 -0
- package/dist/color-picker.d.ts +72 -0
- package/dist/color-picker.js +133 -0
- package/dist/color.d.ts +2 -0
- package/dist/color.js +22 -0
- package/dist/combobox.d.ts +152 -0
- package/dist/combobox.js +338 -0
- package/dist/command.d.ts +88 -0
- package/dist/command.js +233 -0
- package/dist/controller-target.d.ts +3 -0
- package/dist/controller-target.js +59 -0
- package/dist/date-input.d.ts +19 -0
- package/dist/date-input.js +58 -0
- package/dist/date-picker.d.ts +47 -0
- package/dist/date-picker.js +310 -0
- package/dist/date.d.ts +2 -0
- package/dist/date.js +60 -0
- package/dist/dialog-parts.d.ts +23 -0
- package/dist/dialog-parts.js +142 -0
- package/dist/dialog.d.ts +57 -0
- package/dist/dialog.js +32 -0
- package/dist/drawer.d.ts +70 -0
- package/dist/drawer.js +158 -0
- package/dist/editor-context.d.ts +4 -0
- package/dist/editor-context.js +9 -0
- package/dist/field-context.d.ts +47 -0
- package/dist/field-context.js +87 -0
- package/dist/field.d.ts +49 -0
- package/dist/field.js +169 -0
- package/dist/file-input.d.ts +46 -0
- package/dist/file-input.js +170 -0
- package/dist/form-inputs.d.ts +5 -0
- package/dist/form-inputs.js +22 -0
- package/dist/gesture.d.ts +1 -0
- package/dist/gesture.js +16 -0
- package/dist/history.d.ts +2 -0
- package/dist/history.js +12 -0
- package/dist/hover-card.d.ts +33 -0
- package/dist/hover-card.js +84 -0
- package/dist/image-cropper.d.ts +333 -0
- package/dist/image-cropper.js +37 -0
- package/dist/image.d.ts +2 -0
- package/dist/image.js +6 -0
- package/dist/input.d.ts +22 -0
- package/dist/input.js +51 -0
- package/dist/label.d.ts +294 -0
- package/dist/label.js +9 -0
- package/dist/list-items.d.ts +15 -0
- package/dist/list-items.js +39 -0
- package/dist/list-text.d.ts +4 -0
- package/dist/list-text.js +15 -0
- package/dist/listbox.d.ts +56 -0
- package/dist/listbox.js +122 -0
- package/dist/menu.d.ts +116 -0
- package/dist/menu.js +426 -0
- package/dist/menubar-context.d.ts +4 -0
- package/dist/menubar-context.js +7 -0
- package/dist/menubar.d.ts +11 -0
- package/dist/menubar.js +32 -0
- package/dist/meter.d.ts +312 -0
- package/dist/meter.js +30 -0
- package/dist/navigation-menu.d.ts +61 -0
- package/dist/navigation-menu.js +169 -0
- package/dist/number-input.d.ts +44 -0
- package/dist/number-input.js +185 -0
- package/dist/number.d.ts +2 -0
- package/dist/number.js +40 -0
- package/dist/observe.d.ts +2 -0
- package/dist/observe.js +8 -0
- package/dist/otp-input.d.ts +29 -0
- package/dist/otp-input.js +94 -0
- package/dist/overlays.d.ts +26 -0
- package/dist/overlays.js +82 -0
- package/dist/pagination.d.ts +336 -0
- package/dist/pagination.js +71 -0
- package/dist/password-input.d.ts +23 -0
- package/dist/password-input.js +65 -0
- package/dist/popover.d.ts +54 -0
- package/dist/popover.js +151 -0
- package/dist/popup.d.ts +41 -0
- package/dist/popup.js +180 -0
- package/dist/preferences.d.ts +35 -0
- package/dist/preferences.js +93 -0
- package/dist/primitive.d.ts +2 -0
- package/dist/primitive.js +14 -0
- package/dist/progress.d.ts +312 -0
- package/dist/progress.js +30 -0
- package/dist/radio.d.ts +22 -0
- package/dist/radio.js +86 -0
- package/dist/rating.d.ts +20 -0
- package/dist/rating.js +94 -0
- package/dist/render-element.d.ts +35 -0
- package/dist/render-element.js +103 -0
- package/dist/resizable.d.ts +302 -0
- package/dist/resizable.js +23 -0
- package/dist/scroll-area.d.ts +324 -0
- package/dist/scroll-area.js +49 -0
- package/dist/segmented-control.d.ts +24 -0
- package/dist/segmented-control.js +78 -0
- package/dist/segmented-input.d.ts +15 -0
- package/dist/segmented-input.js +48 -0
- package/dist/select.d.ts +125 -0
- package/dist/select.js +330 -0
- package/dist/separator.d.ts +290 -0
- package/dist/separator.js +9 -0
- package/dist/shortcuts.d.ts +32 -0
- package/dist/shortcuts.js +61 -0
- package/dist/slider.d.ts +38 -0
- package/dist/slider.js +163 -0
- package/dist/switch.d.ts +15 -0
- package/dist/switch.js +39 -0
- package/dist/tabs.d.ts +331 -0
- package/dist/tabs.js +28 -0
- package/dist/text-control.d.ts +22 -0
- package/dist/text-control.js +24 -0
- package/dist/text-match.d.ts +2 -0
- package/dist/text-match.js +8 -0
- package/dist/textarea.d.ts +10 -0
- package/dist/textarea.js +48 -0
- package/dist/time-input.d.ts +19 -0
- package/dist/time-input.js +63 -0
- package/dist/timeline.d.ts +327 -0
- package/dist/timeline.js +31 -0
- package/dist/toast-parts.d.ts +63 -0
- package/dist/toast-parts.js +144 -0
- package/dist/toast.d.ts +2 -0
- package/dist/toast.js +22 -0
- package/dist/toggle.d.ts +23 -0
- package/dist/toggle.js +76 -0
- package/dist/token-input.d.ts +35 -0
- package/dist/token-input.js +100 -0
- package/dist/toolbar-context.d.ts +6 -0
- package/dist/toolbar-context.js +16 -0
- package/dist/toolbar.d.ts +38 -0
- package/dist/toolbar.js +63 -0
- package/dist/tooltip.d.ts +39 -0
- package/dist/tooltip.js +108 -0
- package/dist/tree.d.ts +51 -0
- package/dist/tree.js +150 -0
- package/dist/trigger-menu.d.ts +83 -0
- package/dist/trigger-menu.js +167 -0
- package/dist/use-primitive.d.ts +178 -0
- package/dist/use-primitive.js +674 -0
- package/dist/waterfall.d.ts +80 -0
- package/dist/waterfall.js +108 -0
- package/docs/README.md +89 -0
- package/docs/agents.md +1523 -0
- package/docs/components/accordion.md +1391 -0
- package/docs/components/alert-dialog.md +850 -0
- package/docs/components/autocomplete.md +1963 -0
- package/docs/components/avatar.md +252 -0
- package/docs/components/button.md +444 -0
- package/docs/components/calendar.md +1687 -0
- package/docs/components/carousel.md +1244 -0
- package/docs/components/checkbox.md +1069 -0
- package/docs/components/collapsible.md +567 -0
- package/docs/components/color-picker.md +736 -0
- package/docs/components/combobox.md +3647 -0
- package/docs/components/command.md +1573 -0
- package/docs/components/date-input.md +608 -0
- package/docs/components/date-picker.md +1266 -0
- package/docs/components/dialog.md +1469 -0
- package/docs/components/drawer.md +1197 -0
- package/docs/components/field.md +549 -0
- package/docs/components/file-input.md +609 -0
- package/docs/components/hover-card.md +514 -0
- package/docs/components/image-cropper.md +579 -0
- package/docs/components/input.md +301 -0
- package/docs/components/label.md +217 -0
- package/docs/components/listbox.md +1130 -0
- package/docs/components/menu.md +1286 -0
- package/docs/components/menubar.md +455 -0
- package/docs/components/meter.md +304 -0
- package/docs/components/navigation-menu.md +1581 -0
- package/docs/components/number-input.md +1086 -0
- package/docs/components/otp-input.md +565 -0
- package/docs/components/pagination.md +648 -0
- package/docs/components/password-input.md +737 -0
- package/docs/components/popover.md +1552 -0
- package/docs/components/preferences.md +220 -0
- package/docs/components/progress.md +443 -0
- package/docs/components/radio.md +846 -0
- package/docs/components/rating.md +458 -0
- package/docs/components/resizable.md +982 -0
- package/docs/components/scroll-area.md +980 -0
- package/docs/components/segmented-control.md +465 -0
- package/docs/components/select.md +2133 -0
- package/docs/components/separator.md +243 -0
- package/docs/components/slider.md +1169 -0
- package/docs/components/switch.md +613 -0
- package/docs/components/tabs.md +1014 -0
- package/docs/components/textarea.md +318 -0
- package/docs/components/time-input.md +231 -0
- package/docs/components/timeline.md +677 -0
- package/docs/components/toast.md +1395 -0
- package/docs/components/toggle.md +541 -0
- package/docs/components/token-input.md +1007 -0
- package/docs/components/toolbar.md +787 -0
- package/docs/components/tooltip.md +884 -0
- package/docs/components/tree.md +1346 -0
- package/docs/components/trigger-menu.md +1257 -0
- package/docs/components/waterfall.md +754 -0
- package/docs/controllers.md +89 -0
- package/docs/core.md +8027 -0
- package/docs/custom-parts.md +120 -0
- package/docs/first-component.md +83 -0
- package/docs/forms.md +148 -0
- package/docs/hooks/async-options.md +366 -0
- package/docs/hooks/shortcuts.md +221 -0
- package/docs/installation.md +45 -0
- package/docs/introduction.md +32 -0
- package/docs/lists-and-menus.md +170 -0
- package/docs/llms.txt +1844 -0
- package/docs/parts-and-composition.md +93 -0
- package/docs/popups.md +117 -0
- package/docs/rendering.md +121 -0
- package/docs/server-rendering.md +253 -0
- package/docs/state-and-events.md +105 -0
- package/docs/styling-and-animation.md +176 -0
- package/package.json +333 -3
|
@@ -0,0 +1,455 @@
|
|
|
1
|
+
# Menubar
|
|
2
|
+
|
|
3
|
+
Move between an application’s menus with one tab stop.
|
|
4
|
+
|
|
5
|
+
Wrap a few [Menus](./menu.md) in a Menubar to connect their triggers. Tab enters the bar once; arrow keys move between menus, and pointing at another trigger switches an open menu.
|
|
6
|
+
|
|
7
|
+
```tsx title="demo.tsx"
|
|
8
|
+
import {
|
|
9
|
+
Menu,
|
|
10
|
+
MenuCheckboxItem,
|
|
11
|
+
MenuContent,
|
|
12
|
+
MenuGroupLabel,
|
|
13
|
+
MenuItem,
|
|
14
|
+
MenuItemIndicator,
|
|
15
|
+
MenuRadioGroup,
|
|
16
|
+
MenuRadioItem,
|
|
17
|
+
MenuSeparator,
|
|
18
|
+
MenuSub,
|
|
19
|
+
MenuSubContent,
|
|
20
|
+
MenuSubTrigger,
|
|
21
|
+
MenuTrigger,
|
|
22
|
+
} from "@ui-sdk/react/menu"
|
|
23
|
+
import { Menubar } from "@ui-sdk/react/menubar"
|
|
24
|
+
import { CheckIcon, ChevronRightIcon } from "lucide-react"
|
|
25
|
+
import { useLog } from "./log"
|
|
26
|
+
|
|
27
|
+
const recent = ["Q3 roadmap", "Launch checklist", "Offsite notes"]
|
|
28
|
+
const formats = ["PDF", "Markdown", "HTML"]
|
|
29
|
+
const appearances = ["Light", "Dark", "System"]
|
|
30
|
+
|
|
31
|
+
function Example() {
|
|
32
|
+
const log = useLog()
|
|
33
|
+
const chose = (value: string) => log(`Chose ${value}`)
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<Menubar>
|
|
37
|
+
<Menu onAction={chose}>
|
|
38
|
+
<MenuTrigger>File</MenuTrigger>
|
|
39
|
+
<MenuContent>
|
|
40
|
+
<MenuItem value="New document" shortcut="mod+n">
|
|
41
|
+
New Document
|
|
42
|
+
</MenuItem>
|
|
43
|
+
<MenuItem value="Open" shortcut="mod+o">
|
|
44
|
+
Open…
|
|
45
|
+
</MenuItem>
|
|
46
|
+
<MenuSub>
|
|
47
|
+
<MenuSubTrigger>
|
|
48
|
+
Open Recent
|
|
49
|
+
<ChevronRightIcon aria-hidden="true" />
|
|
50
|
+
</MenuSubTrigger>
|
|
51
|
+
<MenuSubContent>
|
|
52
|
+
{recent.map((name) => (
|
|
53
|
+
<MenuItem key={name} value={name}>
|
|
54
|
+
{name}
|
|
55
|
+
</MenuItem>
|
|
56
|
+
))}
|
|
57
|
+
</MenuSubContent>
|
|
58
|
+
</MenuSub>
|
|
59
|
+
<MenuSeparator />
|
|
60
|
+
<MenuSub>
|
|
61
|
+
<MenuSubTrigger>
|
|
62
|
+
Export
|
|
63
|
+
<ChevronRightIcon aria-hidden="true" />
|
|
64
|
+
</MenuSubTrigger>
|
|
65
|
+
<MenuSubContent>
|
|
66
|
+
{formats.map((format) => (
|
|
67
|
+
<MenuItem key={format} value={`Export as ${format}`}>
|
|
68
|
+
{format}
|
|
69
|
+
</MenuItem>
|
|
70
|
+
))}
|
|
71
|
+
</MenuSubContent>
|
|
72
|
+
</MenuSub>
|
|
73
|
+
<MenuItem value="Print" shortcut="mod+p">
|
|
74
|
+
Print…
|
|
75
|
+
</MenuItem>
|
|
76
|
+
</MenuContent>
|
|
77
|
+
</Menu>
|
|
78
|
+
<Menu onAction={chose}>
|
|
79
|
+
<MenuTrigger>Edit</MenuTrigger>
|
|
80
|
+
<MenuContent>
|
|
81
|
+
<MenuItem value="Undo" shortcut="mod+z" disabled>
|
|
82
|
+
Undo
|
|
83
|
+
</MenuItem>
|
|
84
|
+
<MenuItem value="Redo" shortcut="mod+shift+z">
|
|
85
|
+
Redo
|
|
86
|
+
</MenuItem>
|
|
87
|
+
<MenuSeparator />
|
|
88
|
+
<MenuItem value="Cut" shortcut="mod+x">
|
|
89
|
+
Cut
|
|
90
|
+
</MenuItem>
|
|
91
|
+
<MenuItem value="Copy" shortcut="mod+c">
|
|
92
|
+
Copy
|
|
93
|
+
</MenuItem>
|
|
94
|
+
<MenuItem value="Paste" shortcut="mod+v">
|
|
95
|
+
Paste
|
|
96
|
+
</MenuItem>
|
|
97
|
+
<MenuSeparator />
|
|
98
|
+
<MenuItem value="Find" shortcut="mod+f">
|
|
99
|
+
Find…
|
|
100
|
+
</MenuItem>
|
|
101
|
+
</MenuContent>
|
|
102
|
+
</Menu>
|
|
103
|
+
<Menu
|
|
104
|
+
onCheckedChange={(checked, details) =>
|
|
105
|
+
log(`${details.value} ${checked ? "on" : "off"}`)
|
|
106
|
+
}
|
|
107
|
+
onValueChange={(value) => log(`${value} appearance`)}
|
|
108
|
+
>
|
|
109
|
+
<MenuTrigger>View</MenuTrigger>
|
|
110
|
+
<MenuContent>
|
|
111
|
+
<MenuCheckboxItem value="Ruler">
|
|
112
|
+
<MenuItemIndicator>
|
|
113
|
+
<CheckIcon aria-hidden="true" />
|
|
114
|
+
</MenuItemIndicator>
|
|
115
|
+
Show Ruler
|
|
116
|
+
</MenuCheckboxItem>
|
|
117
|
+
<MenuCheckboxItem value="Word count" defaultChecked>
|
|
118
|
+
<MenuItemIndicator>
|
|
119
|
+
<CheckIcon aria-hidden="true" />
|
|
120
|
+
</MenuItemIndicator>
|
|
121
|
+
Show Word Count
|
|
122
|
+
</MenuCheckboxItem>
|
|
123
|
+
<MenuSeparator />
|
|
124
|
+
<MenuRadioGroup defaultValue="System">
|
|
125
|
+
<MenuGroupLabel>Appearance</MenuGroupLabel>
|
|
126
|
+
{appearances.map((appearance) => (
|
|
127
|
+
<MenuRadioItem key={appearance} value={appearance}>
|
|
128
|
+
<MenuItemIndicator />
|
|
129
|
+
{appearance}
|
|
130
|
+
</MenuRadioItem>
|
|
131
|
+
))}
|
|
132
|
+
</MenuRadioGroup>
|
|
133
|
+
</MenuContent>
|
|
134
|
+
</Menu>
|
|
135
|
+
</Menubar>
|
|
136
|
+
)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export { Example }
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Tab into the bar and use Left and Right to choose a menu, or point at another trigger once one is open. File has submenus, Edit has shortcuts, and View has checkboxes and an appearance choice. The console logs each one.
|
|
143
|
+
|
|
144
|
+
## Installation
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
npm install @ui-sdk/react @ui-sdk/core
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## Composition
|
|
151
|
+
|
|
152
|
+
Use the following composition to build a `Menubar`:
|
|
153
|
+
|
|
154
|
+
```text
|
|
155
|
+
Menubar
|
|
156
|
+
├── Menu
|
|
157
|
+
│ ├── MenuTrigger
|
|
158
|
+
│ └── MenuContent
|
|
159
|
+
│ ├── MenuItem
|
|
160
|
+
│ └── MenuItem
|
|
161
|
+
└── Menu
|
|
162
|
+
├── MenuTrigger
|
|
163
|
+
└── MenuContent
|
|
164
|
+
├── MenuItem
|
|
165
|
+
└── MenuItem
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Each Menu joins its surrounding Menubar automatically. There are no separate menubar trigger or item components. Name the bar with `aria-label` when people need to distinguish it from another one.
|
|
169
|
+
|
|
170
|
+
## Usage
|
|
171
|
+
|
|
172
|
+
Import the parts and put them together:
|
|
173
|
+
|
|
174
|
+
```tsx
|
|
175
|
+
import { Menu, MenuContent, MenuItem, MenuTrigger } from "@ui-sdk/react/menu"
|
|
176
|
+
import { Menubar } from "@ui-sdk/react/menubar"
|
|
177
|
+
|
|
178
|
+
function Example() {
|
|
179
|
+
return (
|
|
180
|
+
<Menubar aria-label="Application">
|
|
181
|
+
<Menu>
|
|
182
|
+
<MenuTrigger>File</MenuTrigger>
|
|
183
|
+
<MenuContent>
|
|
184
|
+
<MenuItem>New file</MenuItem>
|
|
185
|
+
<MenuItem>Open file</MenuItem>
|
|
186
|
+
</MenuContent>
|
|
187
|
+
</Menu>
|
|
188
|
+
<Menu>
|
|
189
|
+
<MenuTrigger>Edit</MenuTrigger>
|
|
190
|
+
<MenuContent>
|
|
191
|
+
<MenuItem>Undo</MenuItem>
|
|
192
|
+
<MenuItem>Redo</MenuItem>
|
|
193
|
+
</MenuContent>
|
|
194
|
+
</Menu>
|
|
195
|
+
</Menubar>
|
|
196
|
+
)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export { Example }
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## Submenu
|
|
203
|
+
|
|
204
|
+
A submenu still uses Menu’s Sub, SubTrigger, and SubContent. The arrow toward it enters that level. On an ordinary item, the same arrow can move to the next top-level menu instead.
|
|
205
|
+
|
|
206
|
+
```tsx title="submenu.tsx"
|
|
207
|
+
import {
|
|
208
|
+
Menu,
|
|
209
|
+
MenuContent,
|
|
210
|
+
MenuItem,
|
|
211
|
+
MenuSub,
|
|
212
|
+
MenuSubContent,
|
|
213
|
+
MenuSubTrigger,
|
|
214
|
+
MenuTrigger,
|
|
215
|
+
} from "@ui-sdk/react/menu"
|
|
216
|
+
import { Menubar } from "@ui-sdk/react/menubar"
|
|
217
|
+
import { ChevronRightIcon } from "lucide-react"
|
|
218
|
+
|
|
219
|
+
function Example() {
|
|
220
|
+
return (
|
|
221
|
+
<Menubar>
|
|
222
|
+
<Menu>
|
|
223
|
+
<MenuTrigger>File</MenuTrigger>
|
|
224
|
+
<MenuContent>
|
|
225
|
+
<MenuItem>New File</MenuItem>
|
|
226
|
+
<MenuSub>
|
|
227
|
+
<MenuSubTrigger>
|
|
228
|
+
Share
|
|
229
|
+
<ChevronRightIcon aria-hidden="true" />
|
|
230
|
+
</MenuSubTrigger>
|
|
231
|
+
<MenuSubContent>
|
|
232
|
+
<MenuItem>Email link</MenuItem>
|
|
233
|
+
<MenuItem>Messages</MenuItem>
|
|
234
|
+
</MenuSubContent>
|
|
235
|
+
</MenuSub>
|
|
236
|
+
</MenuContent>
|
|
237
|
+
</Menu>
|
|
238
|
+
<Menu>
|
|
239
|
+
<MenuTrigger>Edit</MenuTrigger>
|
|
240
|
+
<MenuContent>
|
|
241
|
+
<MenuItem>Undo</MenuItem>
|
|
242
|
+
<MenuSub>
|
|
243
|
+
<MenuSubTrigger>
|
|
244
|
+
Find
|
|
245
|
+
<ChevronRightIcon aria-hidden="true" />
|
|
246
|
+
</MenuSubTrigger>
|
|
247
|
+
<MenuSubContent>
|
|
248
|
+
<MenuItem>Find…</MenuItem>
|
|
249
|
+
<MenuItem>Find Next</MenuItem>
|
|
250
|
+
</MenuSubContent>
|
|
251
|
+
</MenuSub>
|
|
252
|
+
</MenuContent>
|
|
253
|
+
</Menu>
|
|
254
|
+
</Menubar>
|
|
255
|
+
)
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export { Example }
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
Open File and enter Share with the arrow key. Go back to File, then move to Edit without leaving the menubar.
|
|
262
|
+
|
|
263
|
+
## Vertical
|
|
264
|
+
|
|
265
|
+
Set `orientation="vertical"` to move between triggers with Up and Down. The arrow toward the popup opens it; the arrow back closes it and returns to the trigger.
|
|
266
|
+
|
|
267
|
+
```tsx title="vertical.tsx"
|
|
268
|
+
import { Menu, MenuContent, MenuItem, MenuTrigger } from "@ui-sdk/react/menu"
|
|
269
|
+
import { Menubar } from "@ui-sdk/react/menubar"
|
|
270
|
+
|
|
271
|
+
function Example() {
|
|
272
|
+
return (
|
|
273
|
+
<Menubar orientation="vertical">
|
|
274
|
+
{["Inbox", "Drafts", "Archive"].map((label) => (
|
|
275
|
+
<Menu key={label}>
|
|
276
|
+
<MenuTrigger>{label}</MenuTrigger>
|
|
277
|
+
<MenuContent>
|
|
278
|
+
<MenuItem>Open {label}</MenuItem>
|
|
279
|
+
<MenuItem>Mark all as read</MenuItem>
|
|
280
|
+
</MenuContent>
|
|
281
|
+
</Menu>
|
|
282
|
+
))}
|
|
283
|
+
</Menubar>
|
|
284
|
+
)
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
export { Example }
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
Use Up and Down to choose Inbox, Drafts, or Archive. Right opens its menu in left-to-right text; Left returns to its trigger.
|
|
291
|
+
|
|
292
|
+
## Menus as Data
|
|
293
|
+
|
|
294
|
+
Each Menu can take `items` and register its shortcuts while closed. The [Menu data example](./menu.md#menus-as-data) explains the item shapes and callbacks.
|
|
295
|
+
|
|
296
|
+
```tsx
|
|
297
|
+
const file: MenuData = [
|
|
298
|
+
{ value: "new", label: "New File", shortcut: "mod+alt+n" },
|
|
299
|
+
{ value: "open", label: "Open…" },
|
|
300
|
+
{ type: "separator" },
|
|
301
|
+
{ type: "submenu", label: "Share", items: [{ value: "email", label: "Email link" }] },
|
|
302
|
+
]
|
|
303
|
+
|
|
304
|
+
<Menubar>
|
|
305
|
+
<Menu items={file} onAction={(value) => run(value)}>
|
|
306
|
+
<MenuTrigger>File</MenuTrigger>
|
|
307
|
+
<MenuContent />
|
|
308
|
+
</Menu>
|
|
309
|
+
</Menubar>
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
## Disabled
|
|
313
|
+
|
|
314
|
+
A disabled trigger stays focusable with `aria-disabled`, so people can discover it, but cannot open its menu. Set `disabled` on the bar to disable all its triggers while preserving the tab stop.
|
|
315
|
+
|
|
316
|
+
```tsx
|
|
317
|
+
<Menubar>
|
|
318
|
+
<Menu>
|
|
319
|
+
<MenuTrigger disabled>Share</MenuTrigger>
|
|
320
|
+
<MenuContent />
|
|
321
|
+
</Menu>
|
|
322
|
+
</Menubar>
|
|
323
|
+
|
|
324
|
+
<Menubar disabled />
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
## Modal
|
|
328
|
+
|
|
329
|
+
The bar supplies `modal` to menus that do not set their own value. The default, `"pointer"`, consumes an outside press while closing. With `true`, the page also becomes inert and stops scrolling, but the menubar stays usable so you can switch menus.
|
|
330
|
+
|
|
331
|
+
```tsx
|
|
332
|
+
<Menubar modal />
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
## Loop
|
|
336
|
+
|
|
337
|
+
Arrow keys wrap between triggers and open menus by default. Set `loop` false to stop at the ends.
|
|
338
|
+
|
|
339
|
+
```tsx
|
|
340
|
+
<Menubar loop={false} />
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
## Controller
|
|
344
|
+
|
|
345
|
+
Create a `createMenubarController()` and pass it to the bar. `focus()` moves focus to it; `close()` closes its active menu. Each menu still owns its own open state and controller. Connect a shortcut like Alt+M to `focus()`, like an application command that moves focus into its menus.
|
|
346
|
+
|
|
347
|
+
```tsx
|
|
348
|
+
const [menubar] = React.useState(() => createMenubarController())
|
|
349
|
+
useShortcut("alt+m", () => menubar.focus())
|
|
350
|
+
|
|
351
|
+
<Menubar controller={menubar} />
|
|
352
|
+
<button onClick={() => menubar.focus()}>Focus Menubar</button>
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
## Shared Menu Features
|
|
356
|
+
|
|
357
|
+
[Checkboxes](./menu.md#checkboxes), [radio groups](./menu.md#radio-group), [icons](./menu.md#icons), [shortcuts](./menu.md#shortcuts), and [links](./menu.md#links-and-custom-rendering) work as they do in Menu. The first example combines settings and actions in one bar. Menus inside a menubar always use the popover presentation.
|
|
358
|
+
|
|
359
|
+
## Styling
|
|
360
|
+
|
|
361
|
+
The bar gets `data-open` while any menu is open; a trigger gets it only for its own menu. Use `data-orientation` for row or column layout. Style the popups and their items through the same [Menu attributes and CSS variables](./menu.md#styling).
|
|
362
|
+
|
|
363
|
+
Each part has a `data-slot`, such as `menubar`, and its state attributes are listed under [Data Attributes](#data-attributes).
|
|
364
|
+
|
|
365
|
+
## Data Attributes
|
|
366
|
+
|
|
367
|
+
### Menubar
|
|
368
|
+
`[data-slot="menubar"]`
|
|
369
|
+
|
|
370
|
+
- `data-orientation` (`horizontal`, `vertical`): Which arrow keys move between menus.
|
|
371
|
+
- `data-disabled`: Present when the whole menubar is disabled.
|
|
372
|
+
- `data-open`: Present while one of its menus is open.
|
|
373
|
+
|
|
374
|
+
## API Reference
|
|
375
|
+
|
|
376
|
+
### Menubar
|
|
377
|
+
|
|
378
|
+
- `orientation?` (`MenubarOrientation`): Which arrow keys move between menus: left and right, or up and down. A vertical menubar opens its menus to the side.
|
|
379
|
+
- `loop?` (`boolean`): Whether arrow keys wrap from the last menu to the first, between triggers and between open menus.
|
|
380
|
+
- `disabled?` (`boolean`): Stops every menu from opening. Triggers stay focusable with `aria-disabled`, so the menubar keeps its tab stop and stays discoverable.
|
|
381
|
+
- `modal?` (`"pointer" | boolean`): The `modal` setting of every menu in the menubar that doesn't set its own. `"pointer"`: an outside press only closes the open menu. `true`: also locks scroll, traps focus and makes the rest of the page inert, except the menubar. `false`: outside presses reach what they hit.
|
|
382
|
+
- `controller?` (`{ focus: () => void; isOpen: () => boolean; close: (options?: ChangeOptions<MenuOpenChangeReason>) => boolean; }`): Opens, closes and focuses the menubar from anywhere. Create one with `createMenubarController()`.
|
|
383
|
+
- `debug?` (`boolean`): Logs every state change with its reason to the console, in development builds.
|
|
384
|
+
|
|
385
|
+
Menus, items and their icons take the props on the Menu page, like [`MenuItemIcon`](./menu.md#menuitemicon).
|
|
386
|
+
|
|
387
|
+
### State
|
|
388
|
+
|
|
389
|
+
- `orientation` (`MenubarOrientation`): Which arrow keys move between menus, from the `orientation` option. A vertical menubar opens its menus to the side.
|
|
390
|
+
- `disabled` (`boolean`): Whether the whole menubar is disabled.
|
|
391
|
+
- `open` (`boolean`): Whether one of its menus is open.
|
|
392
|
+
- `modal` (`boolean | "pointer"`): The modal setting its menus inherit.
|
|
393
|
+
|
|
394
|
+
### Reasons
|
|
395
|
+
|
|
396
|
+
A menu that another menu in the menubar takes over closes with `submenu-switch`, one opened by pointing at its trigger opens with `trigger-hover`, and one opened with an arrow key opens with `trigger-press`. See [Menu](./menu.md#reasons) for every reason.
|
|
397
|
+
|
|
398
|
+
### Controller
|
|
399
|
+
|
|
400
|
+
- `focus()` (`() => void`): Moves focus to the trigger that holds the menubar's tab stop: the one used last, or the first.
|
|
401
|
+
- `isOpen()` (`() => boolean`): Whether one of its menus is open.
|
|
402
|
+
- `close(options?)` (`(options?: ChangeOptions<MenuOpenChangeReason> | undefined) => boolean`): Closes the open menu, if any, and its submenus. Returns false when the close was canceled or it was already closed.
|
|
403
|
+
|
|
404
|
+
## Accessibility
|
|
405
|
+
|
|
406
|
+
The menubar follows the [WAI-ARIA menubar pattern](https://www.w3.org/WAI/ARIA/apg/patterns/menubar/).
|
|
407
|
+
|
|
408
|
+
### Keyboard
|
|
409
|
+
|
|
410
|
+
Tab first lands on the first trigger, then remembers the last one used. While a menu is open, moving the pointer onto another enabled trigger opens its menu, unless the pointer is only passing over it on the way into the open menu. Pressing that trigger keeps it open. Moving to a disabled trigger closes the current menu without opening another.
|
|
411
|
+
|
|
412
|
+
| Key | On a Trigger | In an Open Menu |
|
|
413
|
+
| --------------- | ------------------------- | ------------------------------------------------ |
|
|
414
|
+
| Left / Right | Previous or next trigger. | Previous or next menu, or enter/leave a submenu. |
|
|
415
|
+
| Down | Open at the first item. | Next item. |
|
|
416
|
+
| Up | Open at the last item. | Previous item. |
|
|
417
|
+
| Enter / Space | Open at the first item. | Choose the focused item. |
|
|
418
|
+
| Home / End | First or last trigger. | First or last item. |
|
|
419
|
+
| A letter | Find a trigger by name. | Find an item by name. |
|
|
420
|
+
| Escape | — | Close and return to the trigger. |
|
|
421
|
+
| Tab / Shift+Tab | Leave the bar. | Close and leave the bar. |
|
|
422
|
+
|
|
423
|
+
These directions describe a horizontal bar in left-to-right text. Right-to-left text reverses the horizontal keys and submenu side; vertical bars use Up and Down between triggers.
|
|
424
|
+
|
|
425
|
+
### Tested Behavior
|
|
426
|
+
|
|
427
|
+
Every line below is an automated test.
|
|
428
|
+
|
|
429
|
+
- The menubar is named, and its triggers are menu items that open menus.
|
|
430
|
+
- The menubar is one tab stop, on its first trigger.
|
|
431
|
+
- Left and Right move between triggers, and Home goes to the first.
|
|
432
|
+
- Tab comes back to the trigger used last.
|
|
433
|
+
- ArrowDown opens a menu and focuses its first item.
|
|
434
|
+
- Enter opens a menu and focuses its first item.
|
|
435
|
+
- Space opens a menu and focuses its first item.
|
|
436
|
+
- Escape closes the menu and focuses its trigger.
|
|
437
|
+
- Tab in an open menu closes it and moves past the menubar.
|
|
438
|
+
- A press opens a menu, and a press on its trigger closes it.
|
|
439
|
+
- While a menu is open, pointing at another trigger opens its menu instead.
|
|
440
|
+
- Crossing another trigger on the way to the open menu keeps the menu.
|
|
441
|
+
- Resting on another trigger on the way to the open menu switches to it.
|
|
442
|
+
- While a menu is open, pointing at a disabled trigger closes it and opens nothing.
|
|
443
|
+
- After pointing at a disabled trigger, pointing at another trigger opens its menu.
|
|
444
|
+
- Pointing at a trigger while every menu is closed opens nothing.
|
|
445
|
+
- A press outside closes the open menu.
|
|
446
|
+
- Choosing an item runs it, closes the menu and focuses its trigger.
|
|
447
|
+
- Checkbox and radio items work in a menubar's menus.
|
|
448
|
+
- A disabled item in a menubar's menu is focusable and does nothing.
|
|
449
|
+
- With loop off, arrows stop at the ends.
|
|
450
|
+
|
|
451
|
+
**Vertical**
|
|
452
|
+
|
|
453
|
+
- Up and Down move between triggers, and Right opens a menu to the side.
|
|
454
|
+
|
|
455
|
+
Runs in React, Vue and web components.
|