@funstack/ui 0.1.0-alpha.20 → 0.1.0-alpha.22
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/dist/alert-dialog/alert-dialog-root.mjs +2 -1
- package/dist/alert-dialog/alert-dialog-root.mjs.map +1 -1
- package/dist/avatar/avatar-context.mjs +24 -0
- package/dist/avatar/avatar-context.mjs.map +1 -0
- package/dist/avatar/avatar-fallback.d.mts +32 -0
- package/dist/avatar/avatar-fallback.d.mts.map +1 -0
- package/dist/avatar/avatar-fallback.mjs +31 -0
- package/dist/avatar/avatar-fallback.mjs.map +1 -0
- package/dist/avatar/avatar-image.d.mts +37 -0
- package/dist/avatar/avatar-image.d.mts.map +1 -0
- package/dist/avatar/avatar-image.mjs +91 -0
- package/dist/avatar/avatar-image.mjs.map +1 -0
- package/dist/avatar/avatar-root.d.mts +48 -0
- package/dist/avatar/avatar-root.d.mts.map +1 -0
- package/dist/avatar/avatar-root.mjs +81 -0
- package/dist/avatar/avatar-root.mjs.map +1 -0
- package/dist/avatar/index.d.mts +24 -0
- package/dist/avatar/index.d.mts.map +1 -0
- package/dist/avatar/index.mjs +24 -0
- package/dist/avatar/index.mjs.map +1 -0
- package/dist/dialog/dialog-close.d.mts.map +1 -1
- package/dist/dialog/dialog-close.mjs +14 -3
- package/dist/dialog/dialog-close.mjs.map +1 -1
- package/dist/dialog/dialog-context.mjs +7 -1
- package/dist/dialog/dialog-context.mjs.map +1 -1
- package/dist/dialog/dialog-popup.d.mts +1 -0
- package/dist/dialog/dialog-popup.d.mts.map +1 -1
- package/dist/dialog/dialog-popup.mjs +20 -2
- package/dist/dialog/dialog-popup.mjs.map +1 -1
- package/dist/dialog/dialog-root.mjs +6 -4
- package/dist/dialog/dialog-root.mjs.map +1 -1
- package/dist/docs/components/avatar.md +354 -0
- package/dist/docs/components/drawer.md +622 -0
- package/dist/docs/components/menu.md +1 -1
- package/dist/docs/components/menubar.md +309 -0
- package/dist/docs/components/meter.md +1 -1
- package/dist/docs/components/navigation-menu.md +501 -0
- package/dist/docs/components/number-field.md +2 -2
- package/dist/docs/components/otp-field.md +508 -0
- package/dist/docs/components/progress.md +1 -1
- package/dist/docs/components/radio-group.md +1 -1
- package/dist/docs/components/scroll-area.md +294 -0
- package/dist/docs/components/slider.md +1 -1
- package/dist/docs/concepts/direction-and-locales.md +106 -0
- package/dist/docs/index.md +8 -1
- package/dist/docs/roadmap.md +13 -0
- package/dist/drawer/drawer-close.d.mts +26 -0
- package/dist/drawer/drawer-close.d.mts.map +1 -0
- package/dist/drawer/drawer-close.mjs +19 -0
- package/dist/drawer/drawer-close.mjs.map +1 -0
- package/dist/drawer/drawer-description.d.mts +23 -0
- package/dist/drawer/drawer-description.d.mts.map +1 -0
- package/dist/drawer/drawer-description.mjs +18 -0
- package/dist/drawer/drawer-description.mjs.map +1 -0
- package/dist/drawer/drawer-form.d.mts +24 -0
- package/dist/drawer/drawer-form.d.mts.map +1 -0
- package/dist/drawer/drawer-form.mjs +19 -0
- package/dist/drawer/drawer-form.mjs.map +1 -0
- package/dist/drawer/drawer-popup.d.mts +77 -0
- package/dist/drawer/drawer-popup.d.mts.map +1 -0
- package/dist/drawer/drawer-popup.mjs +124 -0
- package/dist/drawer/drawer-popup.mjs.map +1 -0
- package/dist/drawer/drawer-root.d.mts +31 -0
- package/dist/drawer/drawer-root.d.mts.map +1 -0
- package/dist/drawer/drawer-root.mjs +23 -0
- package/dist/drawer/drawer-root.mjs.map +1 -0
- package/dist/drawer/drawer-swipe.d.mts +5 -0
- package/dist/drawer/drawer-swipe.d.mts.map +1 -0
- package/dist/drawer/drawer-swipe.mjs +193 -0
- package/dist/drawer/drawer-swipe.mjs.map +1 -0
- package/dist/drawer/drawer-title.d.mts +23 -0
- package/dist/drawer/drawer-title.d.mts.map +1 -0
- package/dist/drawer/drawer-title.mjs +18 -0
- package/dist/drawer/drawer-title.mjs.map +1 -0
- package/dist/drawer/drawer-trigger.d.mts +23 -0
- package/dist/drawer/drawer-trigger.d.mts.map +1 -0
- package/dist/drawer/drawer-trigger.mjs +18 -0
- package/dist/drawer/drawer-trigger.mjs.map +1 -0
- package/dist/drawer/index.d.mts +34 -0
- package/dist/drawer/index.d.mts.map +1 -0
- package/dist/drawer/index.mjs +33 -0
- package/dist/drawer/index.mjs.map +1 -0
- package/dist/index.d.mts +29 -2
- package/dist/index.mjs +6 -1
- package/dist/internal/menubar-context.mjs +12 -0
- package/dist/internal/menubar-context.mjs.map +1 -0
- package/dist/internal/overlay/trigger-ref.mjs +1 -1
- package/dist/internal/overlay/trigger-ref.mjs.map +1 -1
- package/dist/internal/overlay/use-overlay-root.mjs +3 -2
- package/dist/internal/overlay/use-overlay-root.mjs.map +1 -1
- package/dist/internal/overlay/use-popover-trigger.mjs +2 -2
- package/dist/internal/overlay/use-popover-trigger.mjs.map +1 -1
- package/dist/internal/range-value.mjs +5 -3
- package/dist/internal/range-value.mjs.map +1 -1
- package/dist/internal/swipe-arithmetic.mjs +75 -0
- package/dist/internal/swipe-arithmetic.mjs.map +1 -0
- package/dist/internal/swipe.mjs +169 -0
- package/dist/internal/swipe.mjs.map +1 -0
- package/dist/menu/menu-context-trigger.mjs +1 -1
- package/dist/menu/menu-popup.d.mts.map +1 -1
- package/dist/menu/menu-popup.mjs +34 -7
- package/dist/menu/menu-popup.mjs.map +1 -1
- package/dist/menu/menu-trigger.d.mts +10 -3
- package/dist/menu/menu-trigger.d.mts.map +1 -1
- package/dist/menu/menu-trigger.mjs +53 -5
- package/dist/menu/menu-trigger.mjs.map +1 -1
- package/dist/menubar/index.d.mts +3 -0
- package/dist/menubar/index.mjs +1 -0
- package/dist/menubar/menubar.d.mts +49 -0
- package/dist/menubar/menubar.d.mts.map +1 -0
- package/dist/menubar/menubar.mjs +147 -0
- package/dist/menubar/menubar.mjs.map +1 -0
- package/dist/meter/meter-root.d.mts +3 -2
- package/dist/meter/meter-root.d.mts.map +1 -1
- package/dist/meter/meter-root.mjs.map +1 -1
- package/dist/multi-select/multi-select-root.mjs +1 -1
- package/dist/multi-select/multi-select-trigger.mjs +1 -1
- package/dist/navigation-menu/index.d.mts +32 -0
- package/dist/navigation-menu/index.d.mts.map +1 -0
- package/dist/navigation-menu/index.mjs +32 -0
- package/dist/navigation-menu/index.mjs.map +1 -0
- package/dist/navigation-menu/navigation-menu-context.mjs +19 -0
- package/dist/navigation-menu/navigation-menu-context.mjs.map +1 -0
- package/dist/navigation-menu/navigation-menu-item.d.mts +79 -0
- package/dist/navigation-menu/navigation-menu-item.d.mts.map +1 -0
- package/dist/navigation-menu/navigation-menu-item.mjs +80 -0
- package/dist/navigation-menu/navigation-menu-item.mjs.map +1 -0
- package/dist/navigation-menu/navigation-menu-link.d.mts +48 -0
- package/dist/navigation-menu/navigation-menu-link.d.mts.map +1 -0
- package/dist/navigation-menu/navigation-menu-link.mjs +66 -0
- package/dist/navigation-menu/navigation-menu-link.mjs.map +1 -0
- package/dist/navigation-menu/navigation-menu-list.d.mts +33 -0
- package/dist/navigation-menu/navigation-menu-list.d.mts.map +1 -0
- package/dist/navigation-menu/navigation-menu-list.mjs +30 -0
- package/dist/navigation-menu/navigation-menu-list.mjs.map +1 -0
- package/dist/navigation-menu/navigation-menu-popup.d.mts +102 -0
- package/dist/navigation-menu/navigation-menu-popup.d.mts.map +1 -0
- package/dist/navigation-menu/navigation-menu-popup.mjs +93 -0
- package/dist/navigation-menu/navigation-menu-popup.mjs.map +1 -0
- package/dist/navigation-menu/navigation-menu-root.d.mts +33 -0
- package/dist/navigation-menu/navigation-menu-root.d.mts.map +1 -0
- package/dist/navigation-menu/navigation-menu-root.mjs +27 -0
- package/dist/navigation-menu/navigation-menu-root.mjs.map +1 -0
- package/dist/navigation-menu/navigation-menu-trigger.d.mts +32 -0
- package/dist/navigation-menu/navigation-menu-trigger.d.mts.map +1 -0
- package/dist/navigation-menu/navigation-menu-trigger.mjs +42 -0
- package/dist/navigation-menu/navigation-menu-trigger.mjs.map +1 -0
- package/dist/otp-field/index.d.mts +23 -0
- package/dist/otp-field/index.d.mts.map +1 -0
- package/dist/otp-field/index.mjs +23 -0
- package/dist/otp-field/index.mjs.map +1 -0
- package/dist/otp-field/otp-field-context.mjs +13 -0
- package/dist/otp-field/otp-field-context.mjs.map +1 -0
- package/dist/otp-field/otp-field-filter.d.mts +5 -0
- package/dist/otp-field/otp-field-filter.d.mts.map +1 -0
- package/dist/otp-field/otp-field-filter.mjs +135 -0
- package/dist/otp-field/otp-field-filter.mjs.map +1 -0
- package/dist/otp-field/otp-field-input.d.mts +41 -0
- package/dist/otp-field/otp-field-input.d.mts.map +1 -0
- package/dist/otp-field/otp-field-input.mjs +177 -0
- package/dist/otp-field/otp-field-input.mjs.map +1 -0
- package/dist/otp-field/otp-field-root.d.mts +152 -0
- package/dist/otp-field/otp-field-root.d.mts.map +1 -0
- package/dist/otp-field/otp-field-root.mjs +400 -0
- package/dist/otp-field/otp-field-root.mjs.map +1 -0
- package/dist/otp-field/otp-field-slot.d.mts +52 -0
- package/dist/otp-field/otp-field-slot.d.mts.map +1 -0
- package/dist/otp-field/otp-field-slot.mjs +67 -0
- package/dist/otp-field/otp-field-slot.mjs.map +1 -0
- package/dist/popover/index.d.mts +1 -1
- package/dist/popover/popover-trigger.mjs +1 -1
- package/dist/progress/progress-root.d.mts +3 -2
- package/dist/progress/progress-root.d.mts.map +1 -1
- package/dist/progress/progress-root.mjs.map +1 -1
- package/package.json +7 -1
- package/skills/funstack-ui-knowledge/SKILL.md +8 -1
|
@@ -0,0 +1,501 @@
|
|
|
1
|
+
# NavigationMenu
|
|
2
|
+
|
|
3
|
+
A site header: a row of links, some of which are buttons that open a panel of more links. It is the **disclosure** pattern, not a menu: no `menu` roles, no arrow keys, Tab moves through everything. Each panel is a `<div popover>` next to its `<button popovertarget>`, so the browser gives the toggle, the expanded state, Escape, light dismiss and one open panel at a time with **no JavaScript**: the default NavigationMenu works before and without hydration, and its links are in the server HTML. After hydration the library closes a panel when focus leaves it and when one of its links is followed. A panel whose content is worth loading late opts into library mode, where opening is a transition.
|
|
4
|
+
|
|
5
|
+
```tsx title="NavigationMenuSite.tsx"
|
|
6
|
+
// No "use client": this file is a Server Component. No Item has an open-state prop, so every
|
|
7
|
+
// panel runs in JS-free mode: the browser toggles it through `popovertarget`, keeps one open at a
|
|
8
|
+
// time, closes it on Escape and a click outside, and the links are in the server HTML. After
|
|
9
|
+
// hydration the library adds two closes: focus leaving an Item, and a followed link.
|
|
10
|
+
//
|
|
11
|
+
// The links point at sections of this page, so following one keeps you here.
|
|
12
|
+
import { NavigationMenu } from "@funstack/ui/navigation-menu";
|
|
13
|
+
|
|
14
|
+
const sections = {
|
|
15
|
+
Reference: [
|
|
16
|
+
{ href: "#anatomy", label: "Anatomy" },
|
|
17
|
+
{ href: "#props", label: "Props" },
|
|
18
|
+
{ href: "#data-attributes", label: "Data attributes" },
|
|
19
|
+
],
|
|
20
|
+
Behaviour: [
|
|
21
|
+
{ href: "#how-it-works", label: "How it works" },
|
|
22
|
+
{ href: "#keyboard-and-aria", label: "Keyboard and ARIA" },
|
|
23
|
+
{ href: "#suspense", label: "Suspense" },
|
|
24
|
+
],
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export function NavigationMenuSite() {
|
|
28
|
+
return (
|
|
29
|
+
<NavigationMenu.Root aria-label="This page" className="demo-nav">
|
|
30
|
+
<NavigationMenu.List className="demo-nav-list">
|
|
31
|
+
{Object.entries(sections).map(([title, links]) => (
|
|
32
|
+
<NavigationMenu.Item key={title}>
|
|
33
|
+
<NavigationMenu.Trigger className="demo-nav-trigger">{title}</NavigationMenu.Trigger>
|
|
34
|
+
<NavigationMenu.Popup className="demo-nav-panel">
|
|
35
|
+
<ul className="demo-nav-links">
|
|
36
|
+
{links.map((link) => (
|
|
37
|
+
<li key={link.href}>
|
|
38
|
+
<NavigationMenu.Link href={link.href}>{link.label}</NavigationMenu.Link>
|
|
39
|
+
</li>
|
|
40
|
+
))}
|
|
41
|
+
</ul>
|
|
42
|
+
</NavigationMenu.Popup>
|
|
43
|
+
</NavigationMenu.Item>
|
|
44
|
+
))}
|
|
45
|
+
<NavigationMenu.Item>
|
|
46
|
+
<NavigationMenu.Link href="#recipes" className="demo-nav-trigger">
|
|
47
|
+
Recipes
|
|
48
|
+
</NavigationMenu.Link>
|
|
49
|
+
</NavigationMenu.Item>
|
|
50
|
+
</NavigationMenu.List>
|
|
51
|
+
</NavigationMenu.Root>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
```css title="navigation-menu.css"
|
|
57
|
+
/* NavigationMenu: a row of Triggers (button[popovertarget]) and links; each panel is an auto
|
|
58
|
+
popover right after its Trigger. Open state is `:popover-open`; `data-open` on the Trigger
|
|
59
|
+
after hydration, `:has(+ :popover-open)` before it. */
|
|
60
|
+
|
|
61
|
+
.demo-nav-list {
|
|
62
|
+
display: flex;
|
|
63
|
+
flex-wrap: wrap;
|
|
64
|
+
gap: 4px;
|
|
65
|
+
margin: 0;
|
|
66
|
+
padding: 0;
|
|
67
|
+
list-style: none;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.demo-nav-trigger {
|
|
71
|
+
display: inline-flex;
|
|
72
|
+
align-items: center;
|
|
73
|
+
gap: 0.4em;
|
|
74
|
+
padding: 0.35em 0.8em;
|
|
75
|
+
border: 0;
|
|
76
|
+
border-radius: 6px;
|
|
77
|
+
background: transparent;
|
|
78
|
+
color: var(--color-text);
|
|
79
|
+
font: inherit;
|
|
80
|
+
text-decoration: none;
|
|
81
|
+
cursor: pointer;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.demo-nav-trigger:hover {
|
|
85
|
+
background: var(--color-bg-secondary);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.demo-nav-trigger[data-open],
|
|
89
|
+
.demo-nav-trigger:has(+ :popover-open) {
|
|
90
|
+
background: var(--color-bg-secondary);
|
|
91
|
+
color: var(--color-link);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.demo-nav-trigger[data-pending] {
|
|
95
|
+
cursor: progress;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.demo-nav-panel {
|
|
99
|
+
/* The popover UA stylesheet sets `inset: 0; margin: auto`: reset both for anchored placement. */
|
|
100
|
+
inset: auto;
|
|
101
|
+
margin: 4px 0;
|
|
102
|
+
min-inline-size: 12rem;
|
|
103
|
+
padding: 6px;
|
|
104
|
+
border: 1px solid var(--color-border);
|
|
105
|
+
border-radius: 10px;
|
|
106
|
+
background: var(--color-bg);
|
|
107
|
+
color: var(--color-text);
|
|
108
|
+
box-shadow: 0 12px 40px rgb(0 0 0 / 0.2);
|
|
109
|
+
opacity: 0;
|
|
110
|
+
translate: 0 -4px;
|
|
111
|
+
transition:
|
|
112
|
+
opacity 0.15s,
|
|
113
|
+
translate 0.15s,
|
|
114
|
+
display 0.15s allow-discrete,
|
|
115
|
+
overlay 0.15s allow-discrete;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
.demo-nav-panel:popover-open {
|
|
119
|
+
opacity: 1;
|
|
120
|
+
translate: 0;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
@starting-style {
|
|
124
|
+
.demo-nav-panel:popover-open {
|
|
125
|
+
opacity: 0;
|
|
126
|
+
translate: 0 -4px;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
::view-transition-group(.demo-nav-panel) {
|
|
131
|
+
animation-duration: 0.2s;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
.demo-nav-links {
|
|
135
|
+
margin: 0;
|
|
136
|
+
padding: 0;
|
|
137
|
+
list-style: none;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
.demo-nav-links a {
|
|
141
|
+
display: block;
|
|
142
|
+
padding: 0.35em 0.6em;
|
|
143
|
+
border-radius: 6px;
|
|
144
|
+
color: inherit;
|
|
145
|
+
text-decoration: none;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
.demo-nav-links a:hover,
|
|
149
|
+
.demo-nav-links a:focus-visible {
|
|
150
|
+
background: var(--color-bg-secondary);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
.demo-nav [aria-current="page"] {
|
|
154
|
+
font-weight: 600;
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
This example is a Server Component. Open a panel and press Tab: focus enters the panel's links, and leaving the last one closes it. Opening the other panel closes the first one; Escape and a click outside close it too. The links point at sections of this page.
|
|
159
|
+
|
|
160
|
+
## Anatomy
|
|
161
|
+
|
|
162
|
+
```tsx
|
|
163
|
+
import { NavigationMenu } from "@funstack/ui/navigation-menu";
|
|
164
|
+
|
|
165
|
+
<NavigationMenu.Root aria-label="Main"> {/* nav */}
|
|
166
|
+
<NavigationMenu.List> {/* ul[role=list] */}
|
|
167
|
+
<NavigationMenu.Item> {/* li; owns one panel */}
|
|
168
|
+
<NavigationMenu.Trigger>Products</NavigationMenu.Trigger> {/* button[popovertarget] */}
|
|
169
|
+
<NavigationMenu.Popup> {/* div[popover=auto] */}
|
|
170
|
+
<ul>
|
|
171
|
+
<li><NavigationMenu.Link href="/analytics">Analytics</NavigationMenu.Link></li>
|
|
172
|
+
<li><NavigationMenu.Link href="/billing">Billing</NavigationMenu.Link></li>
|
|
173
|
+
</ul>
|
|
174
|
+
</NavigationMenu.Popup>
|
|
175
|
+
</NavigationMenu.Item>
|
|
176
|
+
<NavigationMenu.Item>
|
|
177
|
+
<NavigationMenu.Link href="/pricing" aria-current="page">Pricing</NavigationMenu.Link>
|
|
178
|
+
</NavigationMenu.Item>
|
|
179
|
+
</NavigationMenu.List>
|
|
180
|
+
</NavigationMenu.Root>
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
- **Render the Popup immediately after its Trigger**, in the same Item. Every engine then puts the panel's links right after the Trigger in the Tab order (Safari only when the two are adjacent). Development warns otherwise. One Trigger and one Popup per Item.
|
|
184
|
+
- **The Item owns the open state**, with the props of a [Popover.Root](popover.md). There is no state on the Root: the platform keeps the panels exclusive, because sibling `auto` popovers close each other.
|
|
185
|
+
- **Root and List are structure**: the `nav` landmark (name it when the page has more than one) and a list with an explicit `role="list"`, which keeps its list semantics in Safari under `list-style: none`. Both are directive-free; Item, Trigger, Popup and Link are client components with serialisable props, so the whole navigation can be written in a Server Component.
|
|
186
|
+
- An Item with only a Link in it is a plain `li`: a top-level entry.
|
|
187
|
+
|
|
188
|
+
## How it works
|
|
189
|
+
|
|
190
|
+
An Item with none of `open`, `defaultOpen`, `openChangeAction` and `onOpenChange` runs in **JS-free mode**: the browser toggles the panel and the content is always mounted. Any of them selects **library mode**: the Trigger's click is a request awaited in the Item's transition, the content mounts on open, and the closes the browser performs are facts. The mode is fixed at mount, and the two can be mixed in one navigation.
|
|
191
|
+
|
|
192
|
+
| Close | Who | Library mode channel | \`reason\` |
|
|
193
|
+
| - | - | - | - |
|
|
194
|
+
| Trigger click while open | the browser (JS-free); the library (library mode) | `openChangeAction(false)`, awaited with the panel still shown | `"activate"` |
|
|
195
|
+
| A followed Link inside the panel | the library, after hydration | `openChangeAction(false)`, awaited | `"activate"` |
|
|
196
|
+
| Escape (focus returns to the Trigger) | the browser | `onOpenChange(false)` | `"dismiss"` |
|
|
197
|
+
| A press outside | the browser | `onOpenChange(false)` | `"dismiss"` |
|
|
198
|
+
| Another panel (or any other `auto` popover) opening | the browser | `onOpenChange(false)` | `"dismiss"` |
|
|
199
|
+
| Focus leaving the Item (Tab past the last link) | the library, after hydration | `onOpenChange(false)`; while the open is still pending, `openChangeAction(false)` | `"dismiss"` |
|
|
200
|
+
| Controlled `open={false}` | the library | none | – |
|
|
201
|
+
|
|
202
|
+
- **Opens on a click only** (Enter and Space are the native click), never on hover: touch has no hover, and a button that opens on hover and toggles on click closes the panel under a user who hovers and then clicks. A hover preview is a [HoverCard](hover-card.md).
|
|
203
|
+
- **Focus leaving the Item** to an element outside it closes the panel at once (a null `relatedTarget`, such as a window blur, closes nothing). Without it, a keyboard user who tabs past a panel would leave it open over the page. It needs the hydrated component; before hydration a panel stays open until Escape, a click outside or another panel.
|
|
204
|
+
- **Use JS-free mode for a site's navigation.** Library mode is for a panel whose content is worth loading late (recently viewed pages, an account panel) or whose open state the app needs to know.
|
|
205
|
+
|
|
206
|
+
## Links
|
|
207
|
+
|
|
208
|
+
```tsx
|
|
209
|
+
<NavigationMenu.Link href="/pricing" aria-current="page">Pricing</NavigationMenu.Link>
|
|
210
|
+
<NavigationMenu.Link render={<RouterLink to="/analytics" />}>Analytics</NavigationMenu.Link>
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
- **Following a Link inside a panel closes the panel**: a click with the primary button and no modifier key. With a client-side router the navigation keeps the `nav` mounted, and a click inside a popover is not a light dismiss, so the panel would otherwise stay over the new page. A Ctrl-, Cmd-, Shift- or Alt-click (new tab, new window, download) and a middle click leave it open, so several links can be opened from one panel. The link's own attributes are not read: a plain click on a `target="_blank"` or a `download` link closes the panel too. `closeOnActivate={false}` opts a link out.
|
|
214
|
+
- **The panel closes right away, not with the new page.** In library mode the close is a request that settles as soon as `openChangeAction(false)` does; with a router that renders the next page in a transition (FUNSTACK Router, for one), the panel is gone before a page that loads its data commits, in a commit (and, with `transition`, a view transition) of its own. In JS-free mode it is a `hidePopover()` in the click.
|
|
215
|
+
- The close listener is attached to the element, so `onClick` stays yours and a router link's own click handling runs untouched (also when it prevents the default). When the panel closes, the browser returns focus from the link to the Trigger; where focus goes after the navigation is the router's business.
|
|
216
|
+
- **The current page** is the native `aria-current="page"`, which you set (the library does not know the URL) and style with `[aria-current="page"]`. A router link that sets it itself works through `render`.
|
|
217
|
+
- A Link outside a panel renders an `<a>` and nothing else.
|
|
218
|
+
|
|
219
|
+
## Props
|
|
220
|
+
|
|
221
|
+
### `NavigationMenu.Root`
|
|
222
|
+
|
|
223
|
+
| Prop | Type | Default | Description |
|
|
224
|
+
| - | - | - | - |
|
|
225
|
+
| `className` | `string \| ((state: NavigationMenuRootState) => string \| undefined)` | – | A class name, or a function of the part's state. |
|
|
226
|
+
| `style` | `CSSProperties \| ((state: NavigationMenuRootState) => CSSProperties \| undefined)` | – | Inline style, or a function of the part's state. |
|
|
227
|
+
| `children` | `ReactNode \| ((state: NavigationMenuRootState) => ReactNode)` | – | Content, or a function of the part's state. |
|
|
228
|
+
| `render` | `ReactElement \| ((props, state: NavigationMenuRootState) => ReactNode)` | – | Replace the default \<nav> (element form) or take over rendering (function form). |
|
|
229
|
+
|
|
230
|
+
- **State**: `NavigationMenuRootState` is empty.
|
|
231
|
+
- **Owned**: nothing: every `<nav>` prop passes through. Name it with `aria-label` or `aria-labelledby`.
|
|
232
|
+
|
|
233
|
+
Directive-free: it reads no context and calls no hook.
|
|
234
|
+
|
|
235
|
+
### `NavigationMenu.List`
|
|
236
|
+
|
|
237
|
+
| Prop | Type | Default | Description |
|
|
238
|
+
| - | - | - | - |
|
|
239
|
+
| `className` | `string \| ((state: NavigationMenuListState) => string \| undefined)` | – | A class name, or a function of the part's state. |
|
|
240
|
+
| `style` | `CSSProperties \| ((state: NavigationMenuListState) => CSSProperties \| undefined)` | – | Inline style, or a function of the part's state. |
|
|
241
|
+
| `children` | `ReactNode \| ((state: NavigationMenuListState) => ReactNode)` | – | Content, or a function of the part's state. |
|
|
242
|
+
| `render` | `ReactElement \| ((props, state: NavigationMenuListState) => ReactNode)` | – | Replace the default \<ul> (element form) or take over rendering (function form). |
|
|
243
|
+
|
|
244
|
+
- **State**: `NavigationMenuListState` is empty.
|
|
245
|
+
- **Owned**: nothing. `role="list"` is a default you can override.
|
|
246
|
+
|
|
247
|
+
Directive-free.
|
|
248
|
+
|
|
249
|
+
### `NavigationMenu.Item`
|
|
250
|
+
|
|
251
|
+
| Prop | Type | Default | Description |
|
|
252
|
+
| - | - | - | - |
|
|
253
|
+
| `open` | `boolean` | – | Controlled open state of this Item's panel. Pass `onOpenChange` too: the browser closes the panel without asking (development warns). |
|
|
254
|
+
| `defaultOpen` | `boolean` | – | Initial open state in uncontrolled library mode. Shown after hydration, never in the server HTML. `defaultOpen={false}` alone selects library mode. |
|
|
255
|
+
| `openChangeAction` | `ChangeAction<boolean, NavigationMenuOpenChangeDetails>` | – | Requests only: the Trigger's toggle and a followed Link's close. Awaited in the Item's transition: the panel opens when it resolves and the content has rendered, and closes when a close resolves. May be a Server Function. A rejection reaches the nearest Error Boundary above the Item and the panel keeps its previous state. |
|
|
256
|
+
| `onOpenChange` | `UrgentChangeHandler<boolean, NavigationMenuOpenChangeDetails>` | – | Facts only: the panel was dismissed (Escape, a click outside, another panel opening, focus leaving the Item). Always `false`, with `reason: "dismiss"`. Called synchronously, outside any transition, not awaited. Controlled: set state directly here (`onOpenChange={setOpen}`). |
|
|
257
|
+
| `className` | `string \| ((state: NavigationMenuItemState) => string \| undefined)` | – | A class name, or a function of the part's state. |
|
|
258
|
+
| `style` | `CSSProperties \| ((state: NavigationMenuItemState) => CSSProperties \| undefined)` | – | Inline style, or a function of the part's state. |
|
|
259
|
+
| `children` | `ReactNode \| ((state: NavigationMenuItemState) => ReactNode)` | – | A Trigger and its Popup, or a Link. The function form receives the optimistic state. |
|
|
260
|
+
| `render` | `ReactElement \| ((props, state: NavigationMenuItemState) => ReactNode)` | – | Replace the default \<li> (element form) or take over rendering (function form). |
|
|
261
|
+
|
|
262
|
+
- **State**: `NavigationMenuItemState` is `{ open, pending }`; `open` is optimistic, both are `false` in JS-free mode. `NavigationMenuOpenChangeDetails` is `{ reason }` plus the virtual `event`: `"activate"` for the Trigger and a followed Link, `"dismiss"` for everything else, `"platform"` for a panel found open at hydration.
|
|
263
|
+
- **Owned**: nothing rendered: no attributes on the `<li>`.
|
|
264
|
+
|
|
265
|
+
The focus-leave listener is attached through the `ref`, so `onBlur` stays yours. Every `li` prop passes through.
|
|
266
|
+
|
|
267
|
+
### `NavigationMenu.Trigger`
|
|
268
|
+
|
|
269
|
+
| Prop | Type | Default | Description |
|
|
270
|
+
| - | - | - | - |
|
|
271
|
+
| `disabled` | `boolean` | `false` | Never opens. Native `disabled` on a `<button>`; with a link or component `render` in library mode, `aria-disabled` (still focusable). |
|
|
272
|
+
| `className` | `string \| ((state: NavigationMenuTriggerState) => string \| undefined)` | – | A class name, or a function of the part's state. |
|
|
273
|
+
| `style` | `CSSProperties \| ((state: NavigationMenuTriggerState) => CSSProperties \| undefined)` | – | Inline style, or a function of the part's state. |
|
|
274
|
+
| `children` | `ReactNode \| ((state: NavigationMenuTriggerState) => ReactNode)` | – | Rendered from optimistic state; must not suspend. |
|
|
275
|
+
| `render` | `ReactElement \| ((props, state: NavigationMenuTriggerState) => ReactNode)` | – | Should render a `<button>`: only a button is a `popovertarget` invoker (another element works only in library mode). |
|
|
276
|
+
|
|
277
|
+
- **State**: `NavigationMenuTriggerState` is `{ open, pending, disabled }` (Popover.Trigger's).
|
|
278
|
+
- **Owned**: `type`, `disabled`, `popoverTarget`, `aria-expanded` (never rendered on a button: the browser exposes the panel's state on its invoker), `onClick` in library mode, `data-open`, `data-pending`, `data-disabled`; `commandfor`, `command` and `popoverTargetAction` are not accepted.
|
|
279
|
+
|
|
280
|
+
### `NavigationMenu.Popup`
|
|
281
|
+
|
|
282
|
+
| Prop | Type | Default | Description |
|
|
283
|
+
| - | - | - | - |
|
|
284
|
+
| `side` | `"top" \| "bottom" \| "left" \| "right" \| "inline-start" \| "inline-end" \| null` | `"bottom"` | Placement against the Trigger through inline `position-area`, with `position-try-fallbacks` flipping it when it does not fit. `null` renders no placement (and no `data-side` / `data-align`), for a full-width panel your stylesheet places. |
|
|
285
|
+
| `align` | `"start" \| "center" \| "end"` | `"start"` | Alignment along the side; `start` / `end` are inline-relative on a top or bottom side (mirrored in RTL). |
|
|
286
|
+
| `keepMounted` | `boolean` | `false` | Library mode: keep the children rendered inside a hidden `<Activity>` while the panel is closed. Ignored in JS-free mode, where they are always mounted. |
|
|
287
|
+
| `transition` | `ViewTransitionClass` | – | Library mode only: a `<ViewTransition>` around the panel animates library-driven opens and closes (the Trigger, a followed Link, a controlled change). Dismissals animate with CSS. Static: changing it remounts the panel. |
|
|
288
|
+
| `className` | `string \| ((state: NavigationMenuPopupState) => string \| undefined)` | – | A class name, or a function of the part's state. |
|
|
289
|
+
| `style` | `CSSProperties \| ((state: NavigationMenuPopupState) => CSSProperties \| undefined)` | – | Inline style, or a function of the part's state. |
|
|
290
|
+
| `children` | `ReactNode \| ((state: NavigationMenuPopupState) => ReactNode)` | – | The panel's links. In library mode they render from committed state and may suspend. |
|
|
291
|
+
| `render` | `ReactElement \| ((props, state: NavigationMenuPopupState) => ReactNode)` | – | Replace the default \<div> (element form) or take over rendering (function form). |
|
|
292
|
+
|
|
293
|
+
- **State**: `NavigationMenuPopupState` is `{ open, side, align }`; `open` is committed (`false` in JS-free mode; `:popover-open` is the DOM truth); `side` / `align` are where the browser placed the panel while it is shown, your props otherwise.
|
|
294
|
+
- **Owned**: `id`, `popover` (`"auto"`), `data-side` / `data-align` (unless `side` is `null`).
|
|
295
|
+
|
|
296
|
+
No role: the disclosure pattern's panel is a plain region, and a `<div popover>` moves no focus when it opens. Pass `aria-label` and a `role` for a named region. `onToggle` and `onBeforeToggle` are not accepted; use a `ref`.
|
|
297
|
+
|
|
298
|
+
### `NavigationMenu.Link`
|
|
299
|
+
|
|
300
|
+
| Prop | Type | Default | Description |
|
|
301
|
+
| - | - | - | - |
|
|
302
|
+
| `closeOnActivate` | `boolean` | `true` | Inside a Popup: following the link (primary button, no modifier key) closes the panel. Ignored outside a Popup. |
|
|
303
|
+
| `className` | `string \| ((state: NavigationMenuLinkState) => string \| undefined)` | – | A class name, or a function of the part's state. |
|
|
304
|
+
| `style` | `CSSProperties \| ((state: NavigationMenuLinkState) => CSSProperties \| undefined)` | – | Inline style, or a function of the part's state. |
|
|
305
|
+
| `children` | `ReactNode \| ((state: NavigationMenuLinkState) => ReactNode)` | – | Content, or a function of the part's state. |
|
|
306
|
+
| `render` | `ReactElement \| ((props, state: NavigationMenuLinkState) => ReactNode)` | – | Replace the `<a>`: a router's link component (`render={<Link to="/" />}`). |
|
|
307
|
+
|
|
308
|
+
- **State**: `NavigationMenuLinkState` is empty.
|
|
309
|
+
- **Owned**: nothing: every anchor prop passes through, `onClick` and `aria-current` included.
|
|
310
|
+
|
|
311
|
+
## Data attributes
|
|
312
|
+
|
|
313
|
+
| Hook | On | Meaning |
|
|
314
|
+
| - | - | - |
|
|
315
|
+
| `:popover-open` | Popup | The panel is shown (DOM truth, every mode). |
|
|
316
|
+
| `data-open` | Trigger | Library mode: optimistic open state. JS-free mode: kept from the panel's `toggle` after hydration (use `:has(+ :popover-open)` before it). |
|
|
317
|
+
| `data-pending` | Trigger | Library mode: an open or a close is in flight. |
|
|
318
|
+
| `data-disabled` | Trigger | The `disabled` prop. |
|
|
319
|
+
| `data-side`, `data-align` | Popup | While shown: where the browser placed the panel (after any flip). Otherwise the requested placement. Absent with `side={null}`. |
|
|
320
|
+
| `[aria-current="page"]` | Link | Yours: the current page's link. |
|
|
321
|
+
|
|
322
|
+
## Keyboard and ARIA
|
|
323
|
+
|
|
324
|
+
| Key | Where | Behaviour |
|
|
325
|
+
| - | - | - |
|
|
326
|
+
| Tab / Shift+Tab | anywhere | The document's order: a Trigger, then its open panel's links, then the next entry. Tab past the last link closes the panel behind |
|
|
327
|
+
| Enter, Space | Trigger | Toggle the panel; focus stays on the Trigger |
|
|
328
|
+
| Enter | Link | Follow it; the panel closes |
|
|
329
|
+
| Escape | Trigger or panel, panel open | Close; focus returns to the Trigger |
|
|
330
|
+
|
|
331
|
+
- **Opening moves no focus**: the user who pressed Enter on "Products" is still on it, and Tab enters the panel. There is no `initialFocus`.
|
|
332
|
+
- **No arrow keys**, so the keyboard works the same before and after hydration. The Trigger has no `aria-expanded` and no `aria-controls`: every engine exposes the popover's expanded state on its `popovertarget` invoker.
|
|
333
|
+
- **Not a menu**: no `menu` / `menuitem` roles. The WAI ARIA Authoring Practices recommend the disclosure pattern for site navigation; an application menu of commands is a [Menu](menu.md).
|
|
334
|
+
|
|
335
|
+
## Transition types
|
|
336
|
+
|
|
337
|
+
Concept: [Transitions & ViewTransition](../concepts/transitions.md#transition-types)
|
|
338
|
+
|
|
339
|
+
Library mode: `fsui-navigation-menu` plus `fsui-navigation-menu-open` or `fsui-navigation-menu-close` for the Trigger's toggle and a followed Link's close. Dismissals are facts and start no transition. JS-free mode starts none.
|
|
340
|
+
|
|
341
|
+
> **With a router's view transitions**
|
|
342
|
+
>
|
|
343
|
+
> A Link's close and a router's navigation are two transitions that commit separately. Where the router adds its own transition type (FUNSTACK Router's `navigation`) before it awaits the navigation, React may attach that type to the panel's close commit, the next transition to commit, and the page's commit then has none. If your page animation matches on that type, give the panel no `transition`. The router side is tracked in [#189](https://github.com/uhyo/funstack-ui/issues/189).
|
|
344
|
+
|
|
345
|
+
## Optimistic and pending
|
|
346
|
+
|
|
347
|
+
Concept: [Pending & optimistic state](../concepts/pending-and-optimistic.md)
|
|
348
|
+
|
|
349
|
+
Library mode: from the click the Trigger has `data-open` (optimistic) and `data-pending`; the panel is hidden until `openChangeAction(true)` resolves and its content has rendered. A close through the Trigger or a Link keeps the panel shown until `openChangeAction(false)` settles. Dismissals pend nothing.
|
|
350
|
+
|
|
351
|
+
```tsx title="NavigationMenuRecent.tsx"
|
|
352
|
+
"use client";
|
|
353
|
+
import { use, useState } from "react";
|
|
354
|
+
import { NavigationMenu } from "@funstack/ui/navigation-menu";
|
|
355
|
+
import type { NavigationMenuOpenChangeDetails } from "@funstack/ui/navigation-menu";
|
|
356
|
+
import { sleep } from "./fake-api.js";
|
|
357
|
+
|
|
358
|
+
// A library-mode Item: `openChangeAction` selects it. The panel's content reads a promise with
|
|
359
|
+
// `use()`, so the first open suspends: the Trigger shows data-open and data-pending, the panel
|
|
360
|
+
// appears when the pages have loaded, with a view transition (`transition`). Tab away while it
|
|
361
|
+
// loads and the open is cancelled. The first panel is JS-free; opening one closes the other.
|
|
362
|
+
let recent: Promise<readonly string[]> | null = null;
|
|
363
|
+
function loadRecent(): Promise<readonly string[]> {
|
|
364
|
+
recent ??= sleep(1500).then(() => ["Quarterly report", "Invoices", "Team settings"]);
|
|
365
|
+
return recent;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
function RecentPages() {
|
|
369
|
+
const pages = use(loadRecent());
|
|
370
|
+
return (
|
|
371
|
+
<ul className="demo-nav-links">
|
|
372
|
+
{pages.map((page) => (
|
|
373
|
+
<li key={page}>
|
|
374
|
+
<NavigationMenu.Link href="#suspense">{page}</NavigationMenu.Link>
|
|
375
|
+
</li>
|
|
376
|
+
))}
|
|
377
|
+
</ul>
|
|
378
|
+
);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
export function NavigationMenuRecent() {
|
|
382
|
+
const [log, setLog] = useState("(none yet)");
|
|
383
|
+
const request = (open: boolean, { reason }: NavigationMenuOpenChangeDetails) => {
|
|
384
|
+
setLog(`openChangeAction(${open}, "${reason}")`);
|
|
385
|
+
};
|
|
386
|
+
// A fact: Escape, a click outside, another panel opening, focus leaving the Item.
|
|
387
|
+
const dismissed = (open: boolean, { reason }: NavigationMenuOpenChangeDetails) => {
|
|
388
|
+
setLog(`onOpenChange(${open}, "${reason}")`);
|
|
389
|
+
};
|
|
390
|
+
return (
|
|
391
|
+
<div className="demo-stack">
|
|
392
|
+
<NavigationMenu.Root aria-label="Workspace" className="demo-nav">
|
|
393
|
+
<NavigationMenu.List className="demo-nav-list">
|
|
394
|
+
<NavigationMenu.Item>
|
|
395
|
+
<NavigationMenu.Trigger className="demo-nav-trigger">Products</NavigationMenu.Trigger>
|
|
396
|
+
<NavigationMenu.Popup className="demo-nav-panel">
|
|
397
|
+
<ul className="demo-nav-links">
|
|
398
|
+
<li>
|
|
399
|
+
<NavigationMenu.Link href="#suspense">Analytics</NavigationMenu.Link>
|
|
400
|
+
</li>
|
|
401
|
+
<li>
|
|
402
|
+
<NavigationMenu.Link href="#suspense">Billing</NavigationMenu.Link>
|
|
403
|
+
</li>
|
|
404
|
+
</ul>
|
|
405
|
+
</NavigationMenu.Popup>
|
|
406
|
+
</NavigationMenu.Item>
|
|
407
|
+
<NavigationMenu.Item openChangeAction={request} onOpenChange={dismissed}>
|
|
408
|
+
<NavigationMenu.Trigger className="demo-nav-trigger">
|
|
409
|
+
{({ pending }) => (
|
|
410
|
+
<>Recent{pending && <span className="demo-spinner" aria-hidden />}</>
|
|
411
|
+
)}
|
|
412
|
+
</NavigationMenu.Trigger>
|
|
413
|
+
<NavigationMenu.Popup className="demo-nav-panel" transition="demo-nav-panel">
|
|
414
|
+
<RecentPages />
|
|
415
|
+
</NavigationMenu.Popup>
|
|
416
|
+
</NavigationMenu.Item>
|
|
417
|
+
</NavigationMenu.List>
|
|
418
|
+
</NavigationMenu.Root>
|
|
419
|
+
<p className="demo-readout">
|
|
420
|
+
Last: <code>{log}</code>
|
|
421
|
+
</p>
|
|
422
|
+
</div>
|
|
423
|
+
);
|
|
424
|
+
}
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
`navigation-menu.css`: the same file as above.
|
|
428
|
+
|
|
429
|
+
The first open of "Recent" waits 1.5 s for its pages: the Trigger shows a spinner, and the other panel stays open meanwhile. Tab away before it appears and the open is cancelled.
|
|
430
|
+
|
|
431
|
+
## Suspense
|
|
432
|
+
|
|
433
|
+
Concept: [Suspense](../concepts/suspense.md)
|
|
434
|
+
|
|
435
|
+
Library mode: the Popup's children render from committed state, so content that suspends holds the open, with `data-pending` on the Trigger, and the panel appears complete. In JS-free mode nothing suspends on open: the content is part of the page and streams with it.
|
|
436
|
+
|
|
437
|
+
```tsx
|
|
438
|
+
<NavigationMenu.Item openChangeAction={(open) => { if (open) preloadRecent(); }}>
|
|
439
|
+
<NavigationMenu.Trigger>Recent</NavigationMenu.Trigger>
|
|
440
|
+
<NavigationMenu.Popup transition="nav-panel">
|
|
441
|
+
<RecentPages /> {/* use(recent): the Trigger is data-pending until it resolves */}
|
|
442
|
+
</NavigationMenu.Popup>
|
|
443
|
+
</NavigationMenu.Item>
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
## Browser-owned state
|
|
447
|
+
|
|
448
|
+
Concept: [Browser-owned state](../concepts/browser-owned-state.md)
|
|
449
|
+
|
|
450
|
+
Each panel is an `auto` popover: the browser owns Escape, light dismiss and one panel at a time, and in JS-free mode the whole open state. In library mode a close the browser performs is a fact for `onOpenChange`; the focus-leave close is shaped the same way.
|
|
451
|
+
|
|
452
|
+
## Before hydration
|
|
453
|
+
|
|
454
|
+
Concept: [Server Components](../concepts/server-components.md#before-hydration)
|
|
455
|
+
|
|
456
|
+
JS-free mode works completely before hydration and without JavaScript: open, close, Escape, light dismiss, one panel at a time, the Tab order, placement and CSS animation. Missing until hydration: the focus-leave close and the Link close. A library-mode Trigger pressed before hydration opens an empty panel, which fills when the page hydrates.
|
|
457
|
+
|
|
458
|
+
## Recipes
|
|
459
|
+
|
|
460
|
+
### Animation, with and without JavaScript
|
|
461
|
+
|
|
462
|
+
```css
|
|
463
|
+
.nav-panel { opacity: 0; translate: 0 -4px; transition: opacity .15s, translate .15s, display .15s allow-discrete, overlay .15s allow-discrete; }
|
|
464
|
+
.nav-panel:popover-open { opacity: 1; translate: 0; }
|
|
465
|
+
@starting-style { .nav-panel:popover-open { opacity: 0; translate: 0 -4px; } }
|
|
466
|
+
.nav-trigger[data-open] { color: var(--accent); } /* after hydration */
|
|
467
|
+
.nav-trigger:has(+ :popover-open) { color: var(--accent); } /* without JavaScript */
|
|
468
|
+
[aria-current="page"] { font-weight: 600; }
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
### A full-width panel
|
|
472
|
+
|
|
473
|
+
```tsx
|
|
474
|
+
<NavigationMenu.Popup side={null} className="mega-panel">…</NavigationMenu.Popup>
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
```css
|
|
478
|
+
.mega-panel { position: fixed; inset-inline: 0; top: anchor(bottom); margin: 0; }
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
The implicit anchor (the Trigger) still applies. On small screens, put the same links in a different component, such as a [Drawer](drawer.md) or a [Collapsible](collapsible.md).
|
|
482
|
+
|
|
483
|
+
### With a router
|
|
484
|
+
|
|
485
|
+
```tsx
|
|
486
|
+
function NavLink({ to, children }) {
|
|
487
|
+
const { pathname } = useLocation();
|
|
488
|
+
return (
|
|
489
|
+
<NavigationMenu.Link href={to} aria-current={pathname === to ? "page" : undefined}>
|
|
490
|
+
{children}
|
|
491
|
+
</NavigationMenu.Link>
|
|
492
|
+
);
|
|
493
|
+
}
|
|
494
|
+
```
|
|
495
|
+
|
|
496
|
+
## Not included
|
|
497
|
+
|
|
498
|
+
- Opening on hover; arrow keys, Home and End between the top-level entries.
|
|
499
|
+
- A shared viewport that resizes between panels, an indicator under the active Trigger, an arrow, and a Root-level `value` naming the open Item: all need a Root-level owner. Moving from one panel to another is a dismissal and an open on two Items, so no single commit morphs one into the other.
|
|
500
|
+
- Nested flyouts (a panel inside a panel).
|
|
501
|
+
- A `current` prop on Link: use `aria-current="page"`.
|
|
@@ -265,7 +265,7 @@ export function NumberFieldFormats() {
|
|
|
265
265
|
`number-field.css`: the same file as above.
|
|
266
266
|
|
|
267
267
|
- `format` is `Intl.NumberFormatOptions`: `style` `"decimal"` (default), `"percent"` (the value is a fraction, `0.25` shows `25%`; default `step` `0.01`), `"currency"` and `"unit"`, plus fraction digits, grouping, sign display and numbering system.
|
|
268
|
-
- **Pass `locale`**. The default is the runtime's locale (on the server and in the browser alike); a development warning fires when the page's `lang` disagrees and no `locale` was given.
|
|
268
|
+
- **Pass `locale`**. The default is the runtime's locale (on the server and in the browser alike); a development warning fires when the page's `lang` disagrees and no `locale` was given. There is no locale provider: [Direction and locales](../concepts/direction-and-locales.md#locale) shows how to pass your i18n library's locale once.
|
|
269
269
|
- The parser accepts what the formatter produces: the locale's decimal and group separators and digits (Arabic-Indic, Devanagari, full-width), the currency or unit in any spelling (`€`, `EUR`, `euros`), a leading or trailing minus, U+2212 and accounting parentheses. **Grouping is strict**: a group separator must sit before the decimal separator and be followed by a whole group, so `1,5` in English is not 15 and `1.5` in German is not 15; the text reverts instead of silently becoming ten times larger.
|
|
270
270
|
- The committed value is **rounded to what the text shows** (the format's maximum fraction digits): `1.999` in a euro field commits `2` and shows `2,00 €`, so what the user sees is what the form posts. Stepped values are rounded the same way (a `step` finer than the format cannot post a digit the text hides). Set `maximumFractionDigits` higher for more precision. `notation: "compact"` cannot be parsed back and logs a development warning.
|
|
271
271
|
|
|
@@ -370,7 +370,7 @@ Must stay a `<label>`: it names the visible input through `for` and, through its
|
|
|
370
370
|
.number-field:has(.input:focus-visible) { outline: 2px solid var(--accent); }
|
|
371
371
|
```
|
|
372
372
|
|
|
373
|
-
The buttons' order is your markup's: an RTL page places `Decrement` first in source if it wants it at the inline start.
|
|
373
|
+
The buttons' order is your markup's: an RTL page places `Decrement` first in source if it wants it at the inline start. Direction never changes the keys (ArrowUp / ArrowDown only) and the locale never sets the direction; see [Direction and locales](../concepts/direction-and-locales.md).
|
|
374
374
|
|
|
375
375
|
## Keyboard and ARIA
|
|
376
376
|
|