@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,787 @@
|
|
|
1
|
+
# Toolbar
|
|
2
|
+
|
|
3
|
+
Give buttons, toggles, menus and fields one tab stop with arrow-key navigation.
|
|
4
|
+
|
|
5
|
+
Use a Toolbar to group the controls of an editor, a canvas or a table. Tab enters it once, and the arrow keys move between its buttons, toggles, menus and fields.
|
|
6
|
+
|
|
7
|
+
```tsx title="demo.tsx"
|
|
8
|
+
"use client"
|
|
9
|
+
|
|
10
|
+
import { Toggle, ToggleIcon } from "@ui-sdk/react/toggle"
|
|
11
|
+
import { Toolbar, ToolbarButton, ToolbarSeparator } from "@ui-sdk/react/toolbar"
|
|
12
|
+
import { BoldIcon, ItalicIcon, LinkIcon, UnderlineIcon } from "lucide-react"
|
|
13
|
+
import { useLog } from "./log"
|
|
14
|
+
|
|
15
|
+
const styles = [
|
|
16
|
+
{ label: "Bold", icon: BoldIcon },
|
|
17
|
+
{ label: "Italic", icon: ItalicIcon },
|
|
18
|
+
{ label: "Underline", icon: UnderlineIcon },
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
function Example() {
|
|
22
|
+
const log = useLog()
|
|
23
|
+
return (
|
|
24
|
+
<Toolbar aria-label="Formatting">
|
|
25
|
+
{styles.map(({ label, icon: Icon }) => (
|
|
26
|
+
<Toggle
|
|
27
|
+
key={label}
|
|
28
|
+
aria-label={label}
|
|
29
|
+
onPressedChange={(pressed) =>
|
|
30
|
+
log(`${label} ${pressed ? "on" : "off"}`)
|
|
31
|
+
}
|
|
32
|
+
>
|
|
33
|
+
<ToggleIcon>
|
|
34
|
+
<Icon />
|
|
35
|
+
</ToggleIcon>
|
|
36
|
+
</Toggle>
|
|
37
|
+
))}
|
|
38
|
+
<ToolbarSeparator />
|
|
39
|
+
<ToolbarButton
|
|
40
|
+
aria-label="Insert link"
|
|
41
|
+
onClick={() => log("Insert link")}
|
|
42
|
+
>
|
|
43
|
+
<LinkIcon aria-hidden="true" />
|
|
44
|
+
</ToolbarButton>
|
|
45
|
+
</Toolbar>
|
|
46
|
+
)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { Example }
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Tab into the toolbar, then use Left and Right to move between Bold, Italic, Underline and Insert link. Press Space to toggle the focused style. The console logs each change.
|
|
53
|
+
|
|
54
|
+
## Installation
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
npm install @ui-sdk/react @ui-sdk/core
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Composition
|
|
61
|
+
|
|
62
|
+
Use the following composition to build a `Toolbar`:
|
|
63
|
+
|
|
64
|
+
```text
|
|
65
|
+
Toolbar
|
|
66
|
+
├── ToolbarButton
|
|
67
|
+
├── ToolbarSeparator
|
|
68
|
+
├── ToolbarGroup
|
|
69
|
+
│ ├── ToolbarButton
|
|
70
|
+
│ └── ToolbarButton
|
|
71
|
+
├── ToolbarLink
|
|
72
|
+
└── ToolbarInput
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Put buttons, links and fields straight inside the toolbar. `ToolbarGroup` names a set of related items, and `ToolbarSeparator` draws a line between sets. Toggles and toggle groups join the toolbar on their own, and menu and select triggers join through `ToolbarButton`.
|
|
76
|
+
|
|
77
|
+
## Usage
|
|
78
|
+
|
|
79
|
+
Import the parts and put them together:
|
|
80
|
+
|
|
81
|
+
```tsx
|
|
82
|
+
import { Toolbar, ToolbarButton, ToolbarSeparator } from "@ui-sdk/react/toolbar"
|
|
83
|
+
|
|
84
|
+
function Example() {
|
|
85
|
+
return (
|
|
86
|
+
<Toolbar aria-label="Formatting">
|
|
87
|
+
<ToolbarButton>Undo</ToolbarButton>
|
|
88
|
+
<ToolbarButton>Redo</ToolbarButton>
|
|
89
|
+
<ToolbarSeparator />
|
|
90
|
+
<ToolbarButton>Insert Link</ToolbarButton>
|
|
91
|
+
</Toolbar>
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export { Example }
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Name the toolbar with `aria-label`, and give every icon-only control its own.
|
|
99
|
+
|
|
100
|
+
## Toggle Groups
|
|
101
|
+
|
|
102
|
+
A [Toggle](./toggle.md) group inside a toolbar joins its navigation instead of adding another tab stop. Arrow keys move focus without pressing anything; Enter or Space presses the focused toggle.
|
|
103
|
+
|
|
104
|
+
```tsx title="toggle-group.tsx"
|
|
105
|
+
"use client"
|
|
106
|
+
|
|
107
|
+
import { Toggle, ToggleGroup, ToggleIcon } from "@ui-sdk/react/toggle"
|
|
108
|
+
import { Toolbar, ToolbarSeparator } from "@ui-sdk/react/toolbar"
|
|
109
|
+
import {
|
|
110
|
+
AlignCenterIcon,
|
|
111
|
+
AlignLeftIcon,
|
|
112
|
+
AlignRightIcon,
|
|
113
|
+
ListIcon,
|
|
114
|
+
ListOrderedIcon,
|
|
115
|
+
} from "lucide-react"
|
|
116
|
+
import { useLog } from "./log"
|
|
117
|
+
|
|
118
|
+
const alignments = [
|
|
119
|
+
{ value: "left", label: "Align left", icon: AlignLeftIcon },
|
|
120
|
+
{ value: "center", label: "Align center", icon: AlignCenterIcon },
|
|
121
|
+
{ value: "right", label: "Align right", icon: AlignRightIcon },
|
|
122
|
+
]
|
|
123
|
+
|
|
124
|
+
const lists = [
|
|
125
|
+
{ value: "bulleted", label: "Bulleted list", icon: ListIcon },
|
|
126
|
+
{ value: "numbered", label: "Numbered list", icon: ListOrderedIcon },
|
|
127
|
+
]
|
|
128
|
+
|
|
129
|
+
function Example() {
|
|
130
|
+
const log = useLog()
|
|
131
|
+
return (
|
|
132
|
+
<Toolbar aria-label="Paragraph">
|
|
133
|
+
<ToggleGroup
|
|
134
|
+
defaultValue={["left"]}
|
|
135
|
+
deselectable={false}
|
|
136
|
+
aria-label="Alignment"
|
|
137
|
+
onValueChange={([value]) => log(`Align ${value}`)}
|
|
138
|
+
>
|
|
139
|
+
{alignments.map(({ value, label, icon: Icon }) => (
|
|
140
|
+
<Toggle key={value} value={value} aria-label={label}>
|
|
141
|
+
<ToggleIcon>
|
|
142
|
+
<Icon />
|
|
143
|
+
</ToggleIcon>
|
|
144
|
+
</Toggle>
|
|
145
|
+
))}
|
|
146
|
+
</ToggleGroup>
|
|
147
|
+
<ToolbarSeparator />
|
|
148
|
+
<ToggleGroup
|
|
149
|
+
aria-label="List"
|
|
150
|
+
onValueChange={([value]) =>
|
|
151
|
+
log(lists.find((list) => list.value === value)?.label ?? "No list")
|
|
152
|
+
}
|
|
153
|
+
>
|
|
154
|
+
{lists.map(({ value, label, icon: Icon }) => (
|
|
155
|
+
<Toggle key={value} value={value} aria-label={label}>
|
|
156
|
+
<ToggleIcon>
|
|
157
|
+
<Icon />
|
|
158
|
+
</ToggleIcon>
|
|
159
|
+
</Toggle>
|
|
160
|
+
))}
|
|
161
|
+
</ToggleGroup>
|
|
162
|
+
</Toolbar>
|
|
163
|
+
)
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export { Example }
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Arrow from the alignment group to the list group, then press Space on Align center or Numbered list. The console logs each choice.
|
|
170
|
+
|
|
171
|
+
## Groups
|
|
172
|
+
|
|
173
|
+
Use `ToolbarGroup` to name related controls. Set `disabled` on the group to disable them together; they stay focusable with `aria-disabled`.
|
|
174
|
+
|
|
175
|
+
```tsx title="group.tsx"
|
|
176
|
+
"use client"
|
|
177
|
+
|
|
178
|
+
import {
|
|
179
|
+
Toolbar,
|
|
180
|
+
ToolbarButton,
|
|
181
|
+
ToolbarGroup,
|
|
182
|
+
ToolbarSeparator,
|
|
183
|
+
} from "@ui-sdk/react/toolbar"
|
|
184
|
+
import {
|
|
185
|
+
ClipboardIcon,
|
|
186
|
+
CopyIcon,
|
|
187
|
+
RedoIcon,
|
|
188
|
+
ScissorsIcon,
|
|
189
|
+
UndoIcon,
|
|
190
|
+
} from "lucide-react"
|
|
191
|
+
import { useLog } from "./log"
|
|
192
|
+
|
|
193
|
+
const clipboard = [
|
|
194
|
+
{ label: "Cut", icon: ScissorsIcon },
|
|
195
|
+
{ label: "Copy", icon: CopyIcon },
|
|
196
|
+
{ label: "Paste", icon: ClipboardIcon },
|
|
197
|
+
]
|
|
198
|
+
|
|
199
|
+
function Example() {
|
|
200
|
+
const log = useLog()
|
|
201
|
+
return (
|
|
202
|
+
<Toolbar aria-label="Edit">
|
|
203
|
+
<ToolbarGroup aria-label="Clipboard">
|
|
204
|
+
{clipboard.map(({ label, icon: Icon }) => (
|
|
205
|
+
<ToolbarButton
|
|
206
|
+
key={label}
|
|
207
|
+
aria-label={label}
|
|
208
|
+
onClick={() => log(label)}
|
|
209
|
+
>
|
|
210
|
+
<Icon aria-hidden="true" />
|
|
211
|
+
</ToolbarButton>
|
|
212
|
+
))}
|
|
213
|
+
</ToolbarGroup>
|
|
214
|
+
<ToolbarSeparator />
|
|
215
|
+
<ToolbarGroup disabled aria-label="History">
|
|
216
|
+
<ToolbarButton aria-label="Undo">
|
|
217
|
+
<UndoIcon aria-hidden="true" />
|
|
218
|
+
</ToolbarButton>
|
|
219
|
+
<ToolbarButton aria-label="Redo">
|
|
220
|
+
<RedoIcon aria-hidden="true" />
|
|
221
|
+
</ToolbarButton>
|
|
222
|
+
</ToolbarGroup>
|
|
223
|
+
</Toolbar>
|
|
224
|
+
)
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export { Example }
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
Move through Cut, Copy and Paste into History with the arrow keys. Undo and Redo stay focusable but do nothing.
|
|
231
|
+
|
|
232
|
+
## Menus
|
|
233
|
+
|
|
234
|
+
Render a [Menu](./menu.md) trigger through `ToolbarButton`. In a horizontal toolbar, Down opens the menu while Left and Right keep moving between toolbar items.
|
|
235
|
+
|
|
236
|
+
```tsx
|
|
237
|
+
<Menu>
|
|
238
|
+
<ToolbarButton render={<MenuTrigger />}>Share</ToolbarButton>
|
|
239
|
+
<MenuContent>…</MenuContent>
|
|
240
|
+
</Menu>
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
```tsx title="menu.tsx"
|
|
244
|
+
"use client"
|
|
245
|
+
|
|
246
|
+
import { Menu, MenuContent, MenuItem, MenuTrigger } from "@ui-sdk/react/menu"
|
|
247
|
+
import { Toolbar, ToolbarButton } from "@ui-sdk/react/toolbar"
|
|
248
|
+
import { ChevronDownIcon } from "lucide-react"
|
|
249
|
+
import { useLog } from "./log"
|
|
250
|
+
|
|
251
|
+
function Example() {
|
|
252
|
+
const log = useLog()
|
|
253
|
+
return (
|
|
254
|
+
<Toolbar aria-label="Document">
|
|
255
|
+
<ToolbarButton onClick={() => log("Saved")}>Save</ToolbarButton>
|
|
256
|
+
<Menu onAction={(value) => log(`Shared by ${value}`)}>
|
|
257
|
+
<ToolbarButton render={<MenuTrigger />}>
|
|
258
|
+
Share
|
|
259
|
+
<ChevronDownIcon aria-hidden="true" />
|
|
260
|
+
</ToolbarButton>
|
|
261
|
+
<MenuContent>
|
|
262
|
+
<MenuItem value="email">Email</MenuItem>
|
|
263
|
+
<MenuItem value="link">Copy Link</MenuItem>
|
|
264
|
+
</MenuContent>
|
|
265
|
+
</Menu>
|
|
266
|
+
<ToolbarButton onClick={() => log("Printed")}>Print</ToolbarButton>
|
|
267
|
+
</Toolbar>
|
|
268
|
+
)
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export { Example }
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
Focus Share and press Down, then choose Email or Copy Link. Escape closes the menu and returns focus to Share.
|
|
275
|
+
|
|
276
|
+
## Selects
|
|
277
|
+
|
|
278
|
+
A [Select](./select.md) trigger joins the same way. It keeps its select behavior while it takes part in the toolbar's focus order.
|
|
279
|
+
|
|
280
|
+
```tsx title="select.tsx"
|
|
281
|
+
"use client"
|
|
282
|
+
|
|
283
|
+
import {
|
|
284
|
+
Select,
|
|
285
|
+
SelectContent,
|
|
286
|
+
SelectItem,
|
|
287
|
+
SelectItemIndicator,
|
|
288
|
+
SelectTrigger,
|
|
289
|
+
SelectValue,
|
|
290
|
+
} from "@ui-sdk/react/select"
|
|
291
|
+
import { Toolbar, ToolbarButton } from "@ui-sdk/react/toolbar"
|
|
292
|
+
import {
|
|
293
|
+
CheckIcon,
|
|
294
|
+
ChevronsUpDownIcon,
|
|
295
|
+
ZoomInIcon,
|
|
296
|
+
ZoomOutIcon,
|
|
297
|
+
} from "lucide-react"
|
|
298
|
+
import * as React from "react"
|
|
299
|
+
import { useLog } from "./log"
|
|
300
|
+
|
|
301
|
+
const zooms = ["50%", "75%", "100%", "150%", "200%"]
|
|
302
|
+
|
|
303
|
+
function Example() {
|
|
304
|
+
const log = useLog()
|
|
305
|
+
const [zoom, setZoom] = React.useState("100%")
|
|
306
|
+
const index = zooms.indexOf(zoom)
|
|
307
|
+
const change = (value: string) => {
|
|
308
|
+
setZoom(value)
|
|
309
|
+
log(`Zoom ${value}`)
|
|
310
|
+
}
|
|
311
|
+
return (
|
|
312
|
+
<Toolbar aria-label="View">
|
|
313
|
+
<ToolbarButton
|
|
314
|
+
aria-label="Zoom out"
|
|
315
|
+
disabled={index === 0}
|
|
316
|
+
onClick={() => change(zooms[index - 1])}
|
|
317
|
+
>
|
|
318
|
+
<ZoomOutIcon aria-hidden="true" />
|
|
319
|
+
</ToolbarButton>
|
|
320
|
+
<Select value={zoom} onValueChange={(value) => value && change(value)}>
|
|
321
|
+
<ToolbarButton render={<SelectTrigger />} aria-label="Zoom">
|
|
322
|
+
<SelectValue />
|
|
323
|
+
<ChevronsUpDownIcon aria-hidden="true" />
|
|
324
|
+
</ToolbarButton>
|
|
325
|
+
<SelectContent>
|
|
326
|
+
{zooms.map((zoom) => (
|
|
327
|
+
<SelectItem key={zoom} value={zoom}>
|
|
328
|
+
{zoom}
|
|
329
|
+
<SelectItemIndicator>
|
|
330
|
+
<CheckIcon aria-hidden="true" />
|
|
331
|
+
</SelectItemIndicator>
|
|
332
|
+
</SelectItem>
|
|
333
|
+
))}
|
|
334
|
+
</SelectContent>
|
|
335
|
+
</Select>
|
|
336
|
+
<ToolbarButton
|
|
337
|
+
aria-label="Zoom in"
|
|
338
|
+
disabled={index === zooms.length - 1}
|
|
339
|
+
onClick={() => change(zooms[index + 1])}
|
|
340
|
+
>
|
|
341
|
+
<ZoomInIcon aria-hidden="true" />
|
|
342
|
+
</ToolbarButton>
|
|
343
|
+
</Toolbar>
|
|
344
|
+
)
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
export { Example }
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
Open Zoom and choose a value, or step it with Zoom out and Zoom in. Each button turns off at the end of the range.
|
|
351
|
+
|
|
352
|
+
## Fields
|
|
353
|
+
|
|
354
|
+
Use `ToolbarInput` for a text field, or render another field through it, like a [Number Input](./number-input.md) control. A field keeps Home, End and the arrow keys while they move its caret. At the matching end, with no text selected, an arrow moves to the next item.
|
|
355
|
+
|
|
356
|
+
Entering a field with an arrow puts its caret at the far end in that direction: press the same arrow again to leave, or the other arrow to edit. A number input keeps Up and Down for stepping its value.
|
|
357
|
+
|
|
358
|
+
```tsx title="input.tsx"
|
|
359
|
+
"use client"
|
|
360
|
+
|
|
361
|
+
import {
|
|
362
|
+
NumberInput,
|
|
363
|
+
NumberInputControl,
|
|
364
|
+
NumberInputDecrement,
|
|
365
|
+
NumberInputGroup,
|
|
366
|
+
NumberInputIncrement,
|
|
367
|
+
} from "@ui-sdk/react/number-input"
|
|
368
|
+
import { Toolbar, ToolbarInput, ToolbarSeparator } from "@ui-sdk/react/toolbar"
|
|
369
|
+
import { MinusIcon, PlusIcon } from "lucide-react"
|
|
370
|
+
|
|
371
|
+
function Example() {
|
|
372
|
+
return (
|
|
373
|
+
<Toolbar aria-label="Text">
|
|
374
|
+
<NumberInput defaultValue={14} min={8} max={72}>
|
|
375
|
+
<NumberInputGroup>
|
|
376
|
+
<NumberInputDecrement aria-label="Decrease font size">
|
|
377
|
+
<MinusIcon aria-hidden="true" />
|
|
378
|
+
</NumberInputDecrement>
|
|
379
|
+
<ToolbarInput
|
|
380
|
+
render={<NumberInputControl aria-label="Font size" />}
|
|
381
|
+
/>
|
|
382
|
+
<NumberInputIncrement aria-label="Increase font size">
|
|
383
|
+
<PlusIcon aria-hidden="true" />
|
|
384
|
+
</NumberInputIncrement>
|
|
385
|
+
</NumberInputGroup>
|
|
386
|
+
</NumberInput>
|
|
387
|
+
<ToolbarSeparator />
|
|
388
|
+
<ToolbarInput aria-label="Find" placeholder="Find…" />
|
|
389
|
+
</Toolbar>
|
|
390
|
+
)
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
export { Example }
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
Move into Font size and press Up or Down to change it. In Find, type a word, then move the caret to an edge before that arrow leaves the field.
|
|
397
|
+
|
|
398
|
+
## Links
|
|
399
|
+
|
|
400
|
+
`ToolbarLink` joins the same focus order and keeps its link behavior. The demo handles a plain click itself and leaves modified clicks, like opening in a new tab, to the browser.
|
|
401
|
+
|
|
402
|
+
```tsx title="link.tsx"
|
|
403
|
+
"use client"
|
|
404
|
+
|
|
405
|
+
import {
|
|
406
|
+
Toolbar,
|
|
407
|
+
ToolbarButton,
|
|
408
|
+
ToolbarLink,
|
|
409
|
+
ToolbarSeparator,
|
|
410
|
+
} from "@ui-sdk/react/toolbar"
|
|
411
|
+
import { CheckIcon, MessageSquareIcon } from "lucide-react"
|
|
412
|
+
import type * as React from "react"
|
|
413
|
+
import { useLog } from "./log"
|
|
414
|
+
|
|
415
|
+
function Example() {
|
|
416
|
+
const log = useLog()
|
|
417
|
+
const follow = (event: React.MouseEvent<HTMLAnchorElement>) => {
|
|
418
|
+
if (
|
|
419
|
+
event.button !== 0 ||
|
|
420
|
+
event.metaKey ||
|
|
421
|
+
event.ctrlKey ||
|
|
422
|
+
event.shiftKey ||
|
|
423
|
+
event.altKey
|
|
424
|
+
) {
|
|
425
|
+
return
|
|
426
|
+
}
|
|
427
|
+
event.preventDefault()
|
|
428
|
+
log(`Opened ${event.currentTarget.textContent}`)
|
|
429
|
+
}
|
|
430
|
+
return (
|
|
431
|
+
<Toolbar aria-label="Pull request">
|
|
432
|
+
<ToolbarButton aria-label="Approve" onClick={() => log("Approved")}>
|
|
433
|
+
<CheckIcon aria-hidden="true" />
|
|
434
|
+
</ToolbarButton>
|
|
435
|
+
<ToolbarButton aria-label="Comment" onClick={() => log("Comment")}>
|
|
436
|
+
<MessageSquareIcon aria-hidden="true" />
|
|
437
|
+
</ToolbarButton>
|
|
438
|
+
<ToolbarSeparator />
|
|
439
|
+
<ToolbarLink href="#files" onClick={follow}>
|
|
440
|
+
Files Changed
|
|
441
|
+
</ToolbarLink>
|
|
442
|
+
<ToolbarLink href="#checks" onClick={follow}>
|
|
443
|
+
Checks
|
|
444
|
+
</ToolbarLink>
|
|
445
|
+
</Toolbar>
|
|
446
|
+
)
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
export { Example }
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
Arrow to Files Changed and press Enter. The console logs the page it opened.
|
|
453
|
+
|
|
454
|
+
## Vertical
|
|
455
|
+
|
|
456
|
+
Set `orientation="vertical"` to move with Up and Down, like a canvas tool palette. Separators turn to run across the toolbar.
|
|
457
|
+
|
|
458
|
+
```tsx title="vertical.tsx"
|
|
459
|
+
"use client"
|
|
460
|
+
|
|
461
|
+
import { Toggle, ToggleGroup, ToggleIcon } from "@ui-sdk/react/toggle"
|
|
462
|
+
import { Toolbar, ToolbarButton, ToolbarSeparator } from "@ui-sdk/react/toolbar"
|
|
463
|
+
import {
|
|
464
|
+
MousePointer2Icon,
|
|
465
|
+
PencilIcon,
|
|
466
|
+
SquareIcon,
|
|
467
|
+
Trash2Icon,
|
|
468
|
+
TypeIcon,
|
|
469
|
+
} from "lucide-react"
|
|
470
|
+
import { useLog } from "./log"
|
|
471
|
+
|
|
472
|
+
const tools = [
|
|
473
|
+
{ value: "select", label: "Select", icon: MousePointer2Icon },
|
|
474
|
+
{ value: "draw", label: "Draw", icon: PencilIcon },
|
|
475
|
+
{ value: "shape", label: "Shape", icon: SquareIcon },
|
|
476
|
+
{ value: "text", label: "Text", icon: TypeIcon },
|
|
477
|
+
]
|
|
478
|
+
|
|
479
|
+
function Example() {
|
|
480
|
+
const log = useLog()
|
|
481
|
+
return (
|
|
482
|
+
<Toolbar orientation="vertical" aria-label="Canvas">
|
|
483
|
+
<ToggleGroup
|
|
484
|
+
defaultValue={["select"]}
|
|
485
|
+
deselectable={false}
|
|
486
|
+
orientation="vertical"
|
|
487
|
+
aria-label="Tool"
|
|
488
|
+
onValueChange={([value]) =>
|
|
489
|
+
log(`${tools.find((tool) => tool.value === value)?.label} tool`)
|
|
490
|
+
}
|
|
491
|
+
>
|
|
492
|
+
{tools.map(({ value, label, icon: Icon }) => (
|
|
493
|
+
<Toggle key={value} value={value} aria-label={label}>
|
|
494
|
+
<ToggleIcon>
|
|
495
|
+
<Icon />
|
|
496
|
+
</ToggleIcon>
|
|
497
|
+
</Toggle>
|
|
498
|
+
))}
|
|
499
|
+
</ToggleGroup>
|
|
500
|
+
<ToolbarSeparator />
|
|
501
|
+
<ToolbarButton
|
|
502
|
+
aria-label="Delete"
|
|
503
|
+
onClick={() => log("Deleted selection")}
|
|
504
|
+
>
|
|
505
|
+
<Trash2Icon aria-hidden="true" />
|
|
506
|
+
</ToolbarButton>
|
|
507
|
+
</Toolbar>
|
|
508
|
+
)
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
export { Example }
|
|
512
|
+
```
|
|
513
|
+
|
|
514
|
+
Use Up and Down to move between the tools and Delete. Space picks the focused tool.
|
|
515
|
+
|
|
516
|
+
## Disabled
|
|
517
|
+
|
|
518
|
+
A disabled item stays reachable with `aria-disabled`, so people can find it, but it ignores presses, including keys meant for a component rendered through it. Set `focusableWhenDisabled` to `false` to skip it instead.
|
|
519
|
+
|
|
520
|
+
```tsx title="disabled.tsx"
|
|
521
|
+
"use client"
|
|
522
|
+
|
|
523
|
+
import { Toolbar, ToolbarButton } from "@ui-sdk/react/toolbar"
|
|
524
|
+
import { useLog } from "./log"
|
|
525
|
+
|
|
526
|
+
function Example() {
|
|
527
|
+
const log = useLog()
|
|
528
|
+
return (
|
|
529
|
+
<Toolbar aria-label="Message">
|
|
530
|
+
<ToolbarButton onClick={() => log("Reply")}>Reply</ToolbarButton>
|
|
531
|
+
<ToolbarButton disabled onClick={() => log("Archive")}>
|
|
532
|
+
Archive
|
|
533
|
+
</ToolbarButton>
|
|
534
|
+
<ToolbarButton
|
|
535
|
+
disabled
|
|
536
|
+
focusableWhenDisabled={false}
|
|
537
|
+
onClick={() => log("Delete")}
|
|
538
|
+
>
|
|
539
|
+
Delete
|
|
540
|
+
</ToolbarButton>
|
|
541
|
+
</Toolbar>
|
|
542
|
+
)
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
export { Example }
|
|
546
|
+
```
|
|
547
|
+
|
|
548
|
+
Arrow from Reply to Archive, which is disabled but focusable. Delete is skipped. Only Reply logs a press.
|
|
549
|
+
|
|
550
|
+
Set `disabled` on the toolbar to disable every item. The toolbar keeps its tab stop, and its fields can't be edited.
|
|
551
|
+
|
|
552
|
+
```tsx
|
|
553
|
+
<Toolbar disabled aria-label="Formatting">
|
|
554
|
+
<ToolbarButton>Bold</ToolbarButton>
|
|
555
|
+
<ToolbarInput aria-label="Find" />
|
|
556
|
+
</Toolbar>
|
|
557
|
+
```
|
|
558
|
+
|
|
559
|
+
## Loop
|
|
560
|
+
|
|
561
|
+
Arrow keys wrap from the last item to the first by default. Set `loop` to `false` to stop at the ends.
|
|
562
|
+
|
|
563
|
+
```tsx title="loop.tsx"
|
|
564
|
+
"use client"
|
|
565
|
+
|
|
566
|
+
import { Toolbar, ToolbarButton } from "@ui-sdk/react/toolbar"
|
|
567
|
+
import { useLog } from "./log"
|
|
568
|
+
|
|
569
|
+
function Example() {
|
|
570
|
+
const log = useLog()
|
|
571
|
+
return (
|
|
572
|
+
<Toolbar loop={false} aria-label="Pages">
|
|
573
|
+
{["First", "Previous", "Next", "Last"].map((label) => (
|
|
574
|
+
<ToolbarButton key={label} onClick={() => log(`${label} page`)}>
|
|
575
|
+
{label}
|
|
576
|
+
</ToolbarButton>
|
|
577
|
+
))}
|
|
578
|
+
</Toolbar>
|
|
579
|
+
)
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
export { Example }
|
|
583
|
+
```
|
|
584
|
+
|
|
585
|
+
Focus Last and press Right. Focus stays there; Home still moves to First.
|
|
586
|
+
|
|
587
|
+
## Controller
|
|
588
|
+
|
|
589
|
+
Create a controller with `createToolbarController` and pass it as `controller`. Its `focus()` moves focus to the item focused last, like the Alt+F10 shortcut editors give their toolbars. Create one controller per toolbar.
|
|
590
|
+
|
|
591
|
+
```tsx title="controller.tsx"
|
|
592
|
+
"use client"
|
|
593
|
+
|
|
594
|
+
import { useShortcut } from "@ui-sdk/react/shortcuts"
|
|
595
|
+
import {
|
|
596
|
+
createToolbarController,
|
|
597
|
+
Toolbar,
|
|
598
|
+
ToolbarButton,
|
|
599
|
+
} from "@ui-sdk/react/toolbar"
|
|
600
|
+
import { BoldIcon, ItalicIcon, LinkIcon } from "lucide-react"
|
|
601
|
+
import * as React from "react"
|
|
602
|
+
import { useLog } from "./log"
|
|
603
|
+
|
|
604
|
+
const actions = [
|
|
605
|
+
{ label: "Bold", icon: BoldIcon },
|
|
606
|
+
{ label: "Italic", icon: ItalicIcon },
|
|
607
|
+
{ label: "Insert link", icon: LinkIcon },
|
|
608
|
+
]
|
|
609
|
+
|
|
610
|
+
function Example() {
|
|
611
|
+
const log = useLog()
|
|
612
|
+
const [toolbar] = React.useState(createToolbarController)
|
|
613
|
+
useShortcut("alt+f10", () => toolbar.focus(), { allowInInput: true })
|
|
614
|
+
return (
|
|
615
|
+
<div data-slot="stack">
|
|
616
|
+
<div data-slot="controls">
|
|
617
|
+
<button type="button" onClick={() => toolbar.focus()}>
|
|
618
|
+
Focus Toolbar
|
|
619
|
+
</button>
|
|
620
|
+
</div>
|
|
621
|
+
<Toolbar controller={toolbar} aria-label="Notes formatting">
|
|
622
|
+
{actions.map(({ label, icon: Icon }) => (
|
|
623
|
+
<ToolbarButton
|
|
624
|
+
key={label}
|
|
625
|
+
aria-label={label}
|
|
626
|
+
onClick={() => log(label)}
|
|
627
|
+
>
|
|
628
|
+
<Icon aria-hidden="true" />
|
|
629
|
+
</ToolbarButton>
|
|
630
|
+
))}
|
|
631
|
+
</Toolbar>
|
|
632
|
+
<textarea aria-label="Notes" placeholder="Type, then press Alt+F10" />
|
|
633
|
+
</div>
|
|
634
|
+
)
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
export { Example }
|
|
638
|
+
```
|
|
639
|
+
|
|
640
|
+
Type in Notes, then press Alt+F10 or choose Focus Toolbar. Press a toolbar button and the console logs it.
|
|
641
|
+
|
|
642
|
+
## Custom Rendering
|
|
643
|
+
|
|
644
|
+
Render a component through `ToolbarButton` or `ToolbarInput` to combine their behavior, as the menu, select and number input examples do. A render function must spread the toolbar props onto the inner component. [Parts and Composition](../parts-and-composition.md) explains the rendering contract.
|
|
645
|
+
|
|
646
|
+
## Styling
|
|
647
|
+
|
|
648
|
+
Use `data-orientation` on the root for a row or a column, and on a separator for the way its line runs, across the toolbar. Use `data-disabled` to style unavailable items and groups. Toggles inside keep their own `data-pressed`.
|
|
649
|
+
|
|
650
|
+
Each part has a `data-slot`, such as `toolbar-button`, and its state attributes are listed under [Data Attributes](#data-attributes).
|
|
651
|
+
|
|
652
|
+
## Data Attributes
|
|
653
|
+
|
|
654
|
+
### Toolbar
|
|
655
|
+
`[data-slot="toolbar"]`
|
|
656
|
+
|
|
657
|
+
- `data-orientation` (`horizontal`, `vertical`): The toolbar's orientation. On a separator, which way the line runs: across the toolbar.
|
|
658
|
+
- `data-disabled`: Present when disabled, by the item itself, its group or the toolbar.
|
|
659
|
+
|
|
660
|
+
### ToolbarButton
|
|
661
|
+
`[data-slot="toolbar-button"]`
|
|
662
|
+
|
|
663
|
+
- `data-disabled`: Present when disabled, by the item itself, its group or the toolbar.
|
|
664
|
+
- `data-orientation` (`horizontal`, `vertical`): The toolbar's orientation. On a separator, which way the line runs: across the toolbar.
|
|
665
|
+
|
|
666
|
+
### ToolbarLink
|
|
667
|
+
`[data-slot="toolbar-link"]`
|
|
668
|
+
|
|
669
|
+
- `data-disabled`: Present when disabled, by the item itself, its group or the toolbar.
|
|
670
|
+
- `data-orientation` (`horizontal`, `vertical`): The toolbar's orientation. On a separator, which way the line runs: across the toolbar.
|
|
671
|
+
|
|
672
|
+
### ToolbarInput
|
|
673
|
+
`[data-slot="toolbar-input"]`
|
|
674
|
+
|
|
675
|
+
- `data-disabled`: Present when disabled, by the item itself, its group or the toolbar.
|
|
676
|
+
- `data-orientation` (`horizontal`, `vertical`): The toolbar's orientation. On a separator, which way the line runs: across the toolbar.
|
|
677
|
+
|
|
678
|
+
### ToolbarGroup
|
|
679
|
+
`[data-slot="toolbar-group"]`
|
|
680
|
+
|
|
681
|
+
- `data-disabled`: Present when disabled, by the item itself, its group or the toolbar.
|
|
682
|
+
- `data-orientation` (`horizontal`, `vertical`): The toolbar's orientation. On a separator, which way the line runs: across the toolbar.
|
|
683
|
+
|
|
684
|
+
### ToolbarSeparator
|
|
685
|
+
`[data-slot="toolbar-separator"]`
|
|
686
|
+
|
|
687
|
+
- `data-orientation` (`horizontal`, `vertical`): The toolbar's orientation. On a separator, which way the line runs: across the toolbar.
|
|
688
|
+
|
|
689
|
+
## API Reference
|
|
690
|
+
|
|
691
|
+
### Toolbar
|
|
692
|
+
|
|
693
|
+
- `orientation?` (`ToolbarOrientation`): Which arrow keys move between items: left and right, or up and down.
|
|
694
|
+
- `loop?` (`boolean`): Whether arrow keys wrap from the last item to the first.
|
|
695
|
+
- `disabled?` (`boolean`): Stops every item from being used. Items stay focusable with `aria-disabled`, so the toolbar keeps its tab stop and stays discoverable.
|
|
696
|
+
- `controller?` (`{ focus: () => void; }`): Focuses the toolbar from anywhere. Create one with `createToolbarController()`.
|
|
697
|
+
- `debug?` (`boolean`): Logs every state change with its reason to the console, in development builds.
|
|
698
|
+
|
|
699
|
+
### ToolbarButton
|
|
700
|
+
|
|
701
|
+
- `disabled?` (`boolean`): Stops the item from being used. It stays focusable with `aria-disabled`, so arrow keys still reach it and a tooltip can say why.
|
|
702
|
+
- `focusableWhenDisabled?` (`boolean`): Whether a disabled item stays reachable with arrow keys. Turn it off to skip it, natively disabled.
|
|
703
|
+
|
|
704
|
+
### ToolbarInput
|
|
705
|
+
|
|
706
|
+
- `disabled?` (`boolean`): Stops the item from being used. It stays focusable with `aria-disabled`, so arrow keys still reach it and a tooltip can say why.
|
|
707
|
+
- `focusableWhenDisabled?` (`boolean`): Whether a disabled item stays reachable with arrow keys. Turn it off to skip it, natively disabled.
|
|
708
|
+
|
|
709
|
+
### ToolbarGroup
|
|
710
|
+
|
|
711
|
+
- `disabled?` (`boolean`): Disables every item in the group. They stay focusable with `aria-disabled`.
|
|
712
|
+
|
|
713
|
+
`ToolbarLink` and `ToolbarSeparator` take no props of their own.
|
|
714
|
+
|
|
715
|
+
### State
|
|
716
|
+
|
|
717
|
+
What render functions and state-based class names receive on `ToolbarButton` and `ToolbarInput`:
|
|
718
|
+
|
|
719
|
+
- `disabled` (`boolean`): Whether the item is disabled, by itself, its group or the toolbar.
|
|
720
|
+
- `orientation` (`ToolbarOrientation`): The toolbar's `orientation` option: `"vertical"`, or `"horizontal"` for anything else.
|
|
721
|
+
|
|
722
|
+
On `ToolbarLink`:
|
|
723
|
+
|
|
724
|
+
- `disabled` (`boolean`): Whether the link is disabled, by its group or the toolbar.
|
|
725
|
+
- `orientation` (`ToolbarOrientation`): The toolbar's `orientation` option: `"vertical"`, or `"horizontal"` for anything else.
|
|
726
|
+
|
|
727
|
+
On `ToolbarSeparator`:
|
|
728
|
+
|
|
729
|
+
- `orientation` (`ToolbarOrientation`): Which way the line runs: across the toolbar, so vertical in a horizontal toolbar.
|
|
730
|
+
|
|
731
|
+
### Controller
|
|
732
|
+
|
|
733
|
+
- `focus()` (`() => void`): Moves focus to the item that holds the toolbar's tab stop: the one focused last, or the first.
|
|
734
|
+
|
|
735
|
+
## Accessibility
|
|
736
|
+
|
|
737
|
+
The toolbar follows the [WAI-ARIA toolbar pattern](https://www.w3.org/WAI/ARIA/apg/patterns/toolbar/). The root has the `toolbar` role and `aria-orientation`, and separators have the `separator` role.
|
|
738
|
+
|
|
739
|
+
### Keyboard
|
|
740
|
+
|
|
741
|
+
The toolbar has one tab stop, a roving focus. Tab enters on the first enabled item, then returns to the item focused last. The next Tab leaves the toolbar.
|
|
742
|
+
|
|
743
|
+
| Key | Action |
|
|
744
|
+
| -------------------------- | ----------------------------------------------- |
|
|
745
|
+
| `ArrowRight` / `ArrowLeft` | Move focus in a horizontal toolbar |
|
|
746
|
+
| `ArrowDown` / `ArrowUp` | Move focus in a vertical toolbar |
|
|
747
|
+
| `Home` / `End` | Focus the first or last item, except in a field |
|
|
748
|
+
| `Enter` / `Space` | Activate a button or toggle, or open its popup |
|
|
749
|
+
|
|
750
|
+
Controls keep the keys they use: Down opens a menu, and Up and Down step a number input. Moving focus never presses a toggle. In right-to-left text, Left and Right swap.
|
|
751
|
+
|
|
752
|
+
### Tested Behavior
|
|
753
|
+
|
|
754
|
+
Every line below is an automated test.
|
|
755
|
+
|
|
756
|
+
- The toolbar is named and has a horizontal orientation.
|
|
757
|
+
- Tab lands on the first item, and Tab again leaves the toolbar.
|
|
758
|
+
- Shift+Tab from after the toolbar lands on its tab stop.
|
|
759
|
+
- ArrowRight moves through every item, into toggle groups and out of fields.
|
|
760
|
+
- ArrowRight on the last item wraps to the first, and ArrowLeft back.
|
|
761
|
+
- Arrow keys never press a toggle, and Space and Enter do.
|
|
762
|
+
- Tab comes back to the item focused last.
|
|
763
|
+
- A toggle group in the toolbar is no tab stop of its own.
|
|
764
|
+
- A disabled button stays reachable, says it's disabled and does nothing.
|
|
765
|
+
- A button runs its action when pressed.
|
|
766
|
+
- A menu trigger rendered through a button opens with ArrowDown, and arrows still move past it.
|
|
767
|
+
- Choosing from a menu in the toolbar returns focus to its trigger.
|
|
768
|
+
- A text field keeps Home and End for its caret.
|
|
769
|
+
- Up and Down step a number field in the toolbar.
|
|
770
|
+
- Separators run across the toolbar.
|
|
771
|
+
- A group of buttons is named.
|
|
772
|
+
- A link in the toolbar follows its href with Enter.
|
|
773
|
+
- With loop off, arrows stop at the ends.
|
|
774
|
+
- A disabled toolbar keeps one tab stop, and every item says it's disabled.
|
|
775
|
+
|
|
776
|
+
**Vertical**
|
|
777
|
+
|
|
778
|
+
- ArrowDown and ArrowUp move between items, and Left and Right don't.
|
|
779
|
+
- Separators run across a vertical toolbar.
|
|
780
|
+
|
|
781
|
+
**Disabled groups**
|
|
782
|
+
|
|
783
|
+
- Toggles and toggle groups in a disabled group are disabled.
|
|
784
|
+
- A link in a disabled group is disabled, and follows its href once enabled.
|
|
785
|
+
- Enabling a group enables the toggles and buttons in it.
|
|
786
|
+
|
|
787
|
+
Runs in React, Vue and web components.
|