@funstack/ui 0.1.0-alpha.16 → 0.1.0-alpha.18
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/accordion/accordion-root.mjs +7 -5
- package/dist/accordion/accordion-root.mjs.map +1 -1
- package/dist/button/button.d.mts +27 -12
- package/dist/button/button.d.mts.map +1 -1
- package/dist/button/button.mjs +16 -9
- package/dist/button/button.mjs.map +1 -1
- package/dist/checkbox-group/checkbox-group-root.mjs +12 -5
- package/dist/checkbox-group/checkbox-group-root.mjs.map +1 -1
- package/dist/combobox/combobox-popup.d.mts +4 -1
- package/dist/combobox/combobox-popup.d.mts.map +1 -1
- package/dist/combobox/combobox-popup.mjs.map +1 -1
- package/dist/combobox/combobox-root.d.mts +15 -5
- package/dist/combobox/combobox-root.d.mts.map +1 -1
- package/dist/combobox/combobox-root.mjs +9 -11
- package/dist/combobox/combobox-root.mjs.map +1 -1
- package/dist/combobox/combobox-trigger.mjs +7 -2
- package/dist/combobox/combobox-trigger.mjs.map +1 -1
- package/dist/dialog/dialog-close.d.mts +13 -3
- package/dist/dialog/dialog-close.d.mts.map +1 -1
- package/dist/dialog/dialog-close.mjs +3 -2
- package/dist/dialog/dialog-close.mjs.map +1 -1
- package/dist/dialog/dialog-context.mjs.map +1 -1
- package/dist/dialog/dialog-form.d.mts +2 -1
- package/dist/dialog/dialog-form.d.mts.map +1 -1
- package/dist/dialog/dialog-form.mjs.map +1 -1
- package/dist/dialog/dialog-popup.d.mts +9 -4
- package/dist/dialog/dialog-popup.d.mts.map +1 -1
- package/dist/dialog/dialog-popup.mjs +21 -21
- package/dist/dialog/dialog-popup.mjs.map +1 -1
- package/dist/dialog/dialog-root.d.mts +38 -24
- package/dist/dialog/dialog-root.d.mts.map +1 -1
- package/dist/dialog/dialog-root.mjs +10 -8
- package/dist/dialog/dialog-root.mjs.map +1 -1
- package/dist/dialog/dialog-trigger.d.mts +3 -3
- package/dist/dialog/dialog-trigger.mjs.map +1 -1
- package/dist/dialog/index.d.mts +5 -5
- package/dist/dialog/index.mjs +5 -5
- package/dist/dialog/index.mjs.map +1 -1
- package/dist/docs/components/accordion.md +1 -1
- package/dist/docs/components/button.md +71 -24
- package/dist/docs/components/checkbox-group.md +12 -3
- package/dist/docs/components/combobox.md +85 -22
- package/dist/docs/components/context-menu.md +8 -8
- package/dist/docs/components/dialog.md +42 -36
- package/dist/docs/components/menu.md +106 -25
- package/dist/docs/components/popover.md +101 -36
- package/dist/docs/components/progress.md +1 -1
- package/dist/docs/components/slider.md +1 -1
- package/dist/docs/components/toast.md +37 -14
- package/dist/docs/components/toolbar.md +2 -1
- package/dist/docs/components/tooltip.md +1 -1
- package/dist/docs/concepts/action-props.md +55 -25
- package/dist/docs/concepts/browser-owned-state.md +27 -12
- package/dist/docs/concepts/pending-and-optimistic.md +15 -2
- package/dist/docs/concepts/render.md +23 -0
- package/dist/docs/concepts/server-components.md +15 -1
- package/dist/docs/concepts/suspense.md +8 -3
- package/dist/docs/concepts/transitions.md +3 -9
- package/dist/docs/getting-started.md +9 -22
- package/dist/docs/index.md +5 -4
- package/dist/docs/roadmap.md +54 -0
- package/dist/docs/why.md +7 -3
- package/dist/index.d.mts +2 -2
- package/dist/internal/call-urgent-handler.mjs +37 -0
- package/dist/internal/call-urgent-handler.mjs.map +1 -0
- package/dist/internal/css-transition-cut.mjs +66 -0
- package/dist/internal/css-transition-cut.mjs.map +1 -0
- package/dist/internal/overlay-popup.mjs.map +1 -1
- package/dist/internal/report-dropped.mjs +45 -0
- package/dist/internal/report-dropped.mjs.map +1 -0
- package/dist/internal/types.d.mts +33 -7
- package/dist/internal/types.d.mts.map +1 -1
- package/dist/internal/use-action-trigger.mjs +32 -17
- package/dist/internal/use-action-trigger.mjs.map +1 -1
- package/dist/internal/use-controllable-action.mjs +56 -17
- package/dist/internal/use-controllable-action.mjs.map +1 -1
- package/dist/internal/use-exit-animation.mjs +1 -1
- package/dist/internal/use-exit-animation.mjs.map +1 -1
- package/dist/internal/use-native-group-reconciliation.mjs +8 -6
- package/dist/internal/use-native-group-reconciliation.mjs.map +1 -1
- package/dist/internal/use-overlay-close.mjs +10 -4
- package/dist/internal/use-overlay-close.mjs.map +1 -1
- package/dist/internal/use-overlay-root.mjs +40 -7
- package/dist/internal/use-overlay-root.mjs.map +1 -1
- package/dist/internal/use-popover-popup.mjs +25 -7
- package/dist/internal/use-popover-popup.mjs.map +1 -1
- package/dist/internal/use-popover-trigger.d.mts +1 -1
- package/dist/internal/use-popover-trigger.d.mts.map +1 -1
- package/dist/internal/use-popover-trigger.mjs +11 -3
- package/dist/internal/use-popover-trigger.mjs.map +1 -1
- package/dist/menu/menu-checkbox-item.d.mts +1 -1
- package/dist/menu/menu-checkbox-item.mjs.map +1 -1
- package/dist/menu/menu-item.d.mts +15 -4
- package/dist/menu/menu-item.d.mts.map +1 -1
- package/dist/menu/menu-item.mjs +10 -5
- package/dist/menu/menu-item.mjs.map +1 -1
- package/dist/menu/menu-outside.mjs +2 -2
- package/dist/menu/menu-outside.mjs.map +1 -1
- package/dist/menu/menu-popup.d.mts +3 -0
- package/dist/menu/menu-popup.d.mts.map +1 -1
- package/dist/menu/menu-popup.mjs.map +1 -1
- package/dist/menu/menu-root.d.mts +27 -12
- package/dist/menu/menu-root.d.mts.map +1 -1
- package/dist/menu/menu-root.mjs +5 -4
- package/dist/menu/menu-root.mjs.map +1 -1
- package/dist/number-field/number-field-root.d.mts.map +1 -1
- package/dist/number-field/number-field-root.mjs +2 -8
- package/dist/number-field/number-field-root.mjs.map +1 -1
- package/dist/popover/index.d.mts +3 -3
- package/dist/popover/index.mjs +3 -3
- package/dist/popover/index.mjs.map +1 -1
- package/dist/popover/popover-close.d.mts +14 -3
- package/dist/popover/popover-close.d.mts.map +1 -1
- package/dist/popover/popover-close.mjs +4 -2
- package/dist/popover/popover-close.mjs.map +1 -1
- package/dist/popover/popover-popup.d.mts +6 -3
- package/dist/popover/popover-popup.d.mts.map +1 -1
- package/dist/popover/popover-popup.mjs +3 -2
- package/dist/popover/popover-popup.mjs.map +1 -1
- package/dist/popover/popover-root.d.mts +31 -18
- package/dist/popover/popover-root.d.mts.map +1 -1
- package/dist/popover/popover-root.mjs +9 -7
- package/dist/popover/popover-root.mjs.map +1 -1
- package/dist/slider/slider-root.d.mts.map +1 -1
- package/dist/slider/slider-root.mjs +2 -8
- package/dist/slider/slider-root.mjs.map +1 -1
- package/dist/toast/toast-action.d.mts +14 -3
- package/dist/toast/toast-action.d.mts.map +1 -1
- package/dist/toast/toast-action.mjs +6 -4
- package/dist/toast/toast-action.mjs.map +1 -1
- package/dist/toast/toast-context.mjs.map +1 -1
- package/dist/toast/toast-queue.mjs.map +1 -1
- package/dist/toast/toast-viewport.d.mts.map +1 -1
- package/dist/toast/toast-viewport.mjs +15 -15
- package/dist/toast/toast-viewport.mjs.map +1 -1
- package/dist/toast/toast.d.mts +10 -7
- package/dist/toast/toast.d.mts.map +1 -1
- package/dist/toast/toast.mjs.map +1 -1
- package/dist/toggle-group/toggle-group-root.mjs +1 -1
- package/dist/toggle-group/toggle-group-root.mjs.map +1 -1
- package/package.json +1 -1
- package/skills/funstack-ui-knowledge/SKILL.md +6 -6
- package/dist/internal/use-superseded-rejection.mjs +0 -47
- package/dist/internal/use-superseded-rejection.mjs.map +0 -1
|
@@ -101,12 +101,8 @@ html:has(.demo-dialog:modal) {
|
|
|
101
101
|
|
|
102
102
|
/* With `transition`, a view transition animates the library-driven opens and closes (a Close
|
|
103
103
|
part, a Form, a controlled close), Firefox included; dismissals (Escape, a click on the
|
|
104
|
-
backdrop) are the browser's and keep the CSS exit above.
|
|
105
|
-
|
|
106
|
-
captures it in the close's new snapshot as well (a double image). */
|
|
107
|
-
html:active-view-transition .demo-dialog-vt {
|
|
108
|
-
transition: none;
|
|
109
|
-
}
|
|
104
|
+
backdrop) are the browser's and keep the CSS exit above.
|
|
105
|
+
The library keeps the two apart; no extra rule is needed. */
|
|
110
106
|
|
|
111
107
|
::view-transition-new(.demo-dialog-pop) {
|
|
112
108
|
animation: 180ms ease-out both demo-dialog-pop-in;
|
|
@@ -228,16 +224,16 @@ import { Dialog } from "@funstack/ui/dialog";
|
|
|
228
224
|
|
|
229
225
|
| | JS-free mode | Library mode |
|
|
230
226
|
| - | - | - |
|
|
231
|
-
| Selected when | Root has none of `open`, `defaultOpen`, `openChangeAction` | Root has any of them |
|
|
227
|
+
| Selected when | Root has none of `open`, `defaultOpen`, `openChangeAction`, `onOpenChange` | Root has any of them |
|
|
232
228
|
| Open | the browser runs `command="show-modal"` | the click is intercepted and dispatched in the Root's transition; `showModal()` runs in the commit that mounts the content |
|
|
233
229
|
| Close by a part (Close, Form, a foreign close command, controlled `open={false}`) | the browser | the click, submit or command is cancelled and dispatched in the Root's transition; `close(returnValue)` runs in the commit that ends it |
|
|
234
|
-
| Dismissal (Escape, Android back, a click outside) | the browser | the browser, at once; `
|
|
230
|
+
| Dismissal (Escape, Android back, a click outside) | the browser | the browser, at once; a fact: `onOpenChange(false)` is called synchronously, nothing is pending, no view transition |
|
|
235
231
|
| Popup content | always mounted (in the server HTML) | rendered from committed `open`; unmounted while closed unless `keepMounted` |
|
|
236
232
|
| Trigger `data-open`, `data-pending` | not emitted; style `:open` on the dialog | emitted (optimistic) |
|
|
237
233
|
| Before hydration | everything works | the native open happens; the content arrives on hydration (see below) |
|
|
238
234
|
| `transition` on Popup | no effect (development warning) | animates opens, content swaps and every library-driven close |
|
|
239
235
|
|
|
240
|
-
In library mode, opening and [a part's close](../concepts/browser-owned-state.md#parts-close) are the library's; a [dismissal](../concepts/browser-owned-state.md#dismissal) (Escape, Android back, a click outside) is the browser's
|
|
236
|
+
In library mode, opening and [a part's close](../concepts/browser-owned-state.md#parts-close) are the library's; a [dismissal](../concepts/browser-owned-state.md#dismissal) (Escape, Android back, a click outside) is the browser's: a fact, reported to `onOpenChange` ([Requests and facts](../concepts/browser-owned-state.md#requests-and-facts)). The mode is decided on the first render; switching later is not supported (development warning).
|
|
241
237
|
|
|
242
238
|
## Props
|
|
243
239
|
|
|
@@ -245,9 +241,10 @@ In library mode, opening and [a part's close](../concepts/browser-owned-state.md
|
|
|
245
241
|
|
|
246
242
|
| Prop | Type | Default | Description |
|
|
247
243
|
| - | - | - | - |
|
|
248
|
-
| `open` | `boolean` | – | Controlled open state. undefined means uncontrolled. Selects library mode. |
|
|
244
|
+
| `open` | `boolean` | – | Controlled open state. undefined means uncontrolled. Selects library mode. Pass `onOpenChange` too: the browser closes the dialog without asking (development warns). |
|
|
249
245
|
| `defaultOpen` | `boolean` | – | Initial open state in uncontrolled library mode. A dialog that starts open is shown after hydration, never by the server HTML; its content and the Trigger's open state are already in that HTML. `defaultOpen={false}` is the usual way to select library mode without an action. |
|
|
250
|
-
| `openChangeAction` | `ChangeAction<boolean, DialogOpenChangeDetails>` | – | Awaited for `true`: the dialog opens when it resolves and the content has rendered. Awaited for a `false` the user asked a part for (a `Dialog.Close`, a `Dialog.Form` submit or settled action, a foreign close command): the dialog closes with `details.returnValue` when it resolves, with a view transition if the Popup has `transition`; a controlled parent that keeps `open` vetoes it.
|
|
246
|
+
| `openChangeAction` | `ChangeAction<boolean, DialogOpenChangeDetails>` | – | Requests only. Awaited for `true`: the dialog opens when it resolves and the content has rendered. Awaited for a `false` the user asked a part for (a `Dialog.Close`, a `Dialog.Form` submit or settled action, a foreign close command): the dialog closes with `details.returnValue` when it resolves, with a view transition if the Popup has `transition`; a controlled parent that keeps `open` vetoes it. Never called for a dismissal (`onOpenChange`). Runs in the Root's transition; may be a Server Function; rejections reach the nearest Error Boundary above the Root. `details`: `reason` (`"activate"` or `"platform"`) and `returnValue` (the closing button's or submitter's `value`, `undefined` on open). Selects library mode. |
|
|
247
|
+
| `onOpenChange` | `UrgentChangeHandler<boolean, DialogOpenChangeDetails>` | – | Facts only: the dialog was closed without the library closing it (Escape, Android back, an assistive-technology dismiss, a click outside with `lightDismiss`, a script `close()` / `requestClose()`). Always `false`, with `reason: "dismiss"` and `returnValue` as the browser left it (`""` for Escape). Called synchronously in the browser's `close` event, outside any transition, and not awaited: nothing is pending and no view transition runs. A dismissal while a part's close is still running is reported at once and supersedes that close. In controlled mode set state directly here (`onOpenChange={setOpen}`), never in `startTransition` or after an `await`; a parent that keeps `open` gets the dialog shown again at once. May return a promise (a Server Function); a rejection or a throw goes to `reportError`. Selects library mode. |
|
|
251
248
|
| `modal` | `boolean` | `true` | `showModal()` (top layer, backdrop, inert page, Escape) or `show()`. A non-modal dialog has no command to open it, so its Trigger always uses a click handler: in JS-free mode too, it needs JavaScript to open. |
|
|
252
249
|
| `children` | `ReactNode \| ((state: DialogRootState) => ReactNode)` | – | The parts. The function form receives the optimistic state and must not suspend. |
|
|
253
250
|
|
|
@@ -266,14 +263,14 @@ One per Root: focus returns to the Trigger that mounted last, and a non-modal di
|
|
|
266
263
|
| `children` | `ReactNode \| ((state: DialogTriggerState) => ReactNode)` | – | Rendered from optimistic state; must not suspend. |
|
|
267
264
|
| `render` | `ReactElement \| ((props, state: DialogTriggerState) => ReactNode)` | – | Replace the default \<button> (element form) or take over rendering (function form). |
|
|
268
265
|
|
|
269
|
-
- **State**: `DialogTriggerState` is `{ open, pending, disabled }`; `pending` is true while the Root is pending: an open in flight, a part's close waiting for `openChangeAction(false)
|
|
266
|
+
- **State**: `DialogTriggerState` is `{ open, pending, disabled }`; `pending` is true while the Root is pending: an open in flight, or a part's close waiting for `openChangeAction(false)`. A dismissal never pends, but a request still running when a dismissal superseded it keeps `pending` until that request settles.
|
|
270
267
|
- **Owned**: `type` (on a `<button>` only), `disabled`, `aria-disabled` (a link or component `render` with the click handler installed), `commandfor`, `command` (not on a link or other non-button host element), `onClick` (when it installs one), `onPointerDown` (non-modal JS-free mode), `data-open`, `data-pending`, `data-disabled`.
|
|
271
268
|
|
|
272
269
|
### `Dialog.Popup`
|
|
273
270
|
|
|
274
271
|
| Prop | Type | Default | Description |
|
|
275
272
|
| - | - | - | - |
|
|
276
|
-
| `keepMounted` | `boolean` | `false` | Library mode. `false`: children are not rendered while closed, so content that suspends holds the open until it is ready. `true`: children stay in `<Activity mode="hidden">` (state kept, effects stopped, pre-rendered at low priority; not in the server HTML). Either way, unmounting waits for the dialog's CSS exit animation, or happens inside the close's view transition when `transition` is set. Ignored in JS-free mode (always mounted). |
|
|
273
|
+
| `keepMounted` | `boolean` | `false` | Library mode. `false`: children are not rendered while closed, so content that suspends holds the open until it is ready. `true`: children stay in `<Activity mode="hidden">` (state kept, effects stopped, pre-rendered at low priority; not in the server HTML). Either way, unmounting waits for the dialog's CSS exit animation, or happens inside the close's view transition when `transition` is set. Ignored in JS-free mode (always mounted). An action of a part inside that rejects while it is hidden goes to `reportError`, not to an Error Boundary (see [Action props](../concepts/action-props.md)). |
|
|
277
274
|
| `initialFocus` | `RefObject<HTMLElement \| null> \| string` | – | The element to focus on open: a ref, or a selector resolved inside the dialog. The library writes `autofocus` on it right before `showModal()` and lets the platform focus it; it never calls `.focus()`. Default: the platform's choice (the first focusable element). In JS-free mode the attribute is written after mount; prefer it to `autoFocus`, which React writes only into server-rendered HTML (not when the Popup renders on the client, for example after a client navigation to a Server Component page). |
|
|
278
275
|
| `lightDismiss` | `boolean` | `false` | Close on a click outside the dialog (the `::backdrop` for a modal). JS `pointerdown` and `click` listeners: both the press and the click must land outside, so a drag that starts inside (selecting text) never closes. With `experimental_closedBy`, native `closedby="any"`, which behaves the same. A click on the Trigger of an open non-modal dialog counts as outside, as native `closedby="any"` treats it: the dialog ends closed and the click does not re-open it, in JS-free and library mode. |
|
|
279
276
|
| `experimental_closedBy` | `boolean` | `false` | Renders `closedby` (`"any"` with `lightDismiss`, else `"closerequest"`) and skips the JS dismiss listeners where the browser implements it (Chromium, Firefox). Elsewhere the JS stays. See [Experimental features](../concepts/experimental.md). |
|
|
@@ -292,7 +289,8 @@ Other props, such as `role="alertdialog"` or `onCancel`, pass through.
|
|
|
292
289
|
|
|
293
290
|
| Prop | Type | Default | Description |
|
|
294
291
|
| - | - | - | - |
|
|
295
|
-
| `action` | `Action<[details: DialogCloseDetails]>` | – | Runs in this button's own transition (`data-pending` on it), then closes the dialog with `value` as `returnValue`: in library mode through the Root (`openChangeAction(false)` awaited, view transition if set; the button stays pending until the dialog closes), in JS-free mode with `close(value)`. A rejection reaches the nearest Error Boundary above the button and leaves the dialog open. If the dialog was closed and opened again while the action ran, the close is dropped: it belonged to the previous opening. A second click while it is pending is ignored, and the button is `aria-disabled="true"` meanwhile
|
|
292
|
+
| `action` | `Action<[details: DialogCloseDetails]>` | – | Runs in this button's own transition (`data-pending` on it), then closes the dialog with `value` as `returnValue`: in library mode through the Root (`openChangeAction(false)` awaited, view transition if set; the button stays pending until the dialog closes), in JS-free mode with `close(value)`. A rejection reaches the nearest Error Boundary above the button and leaves the dialog open. If the dialog was closed and opened again while the action ran, the close is dropped: it belonged to the previous opening. A second click while it is pending is ignored, and the button is `aria-disabled="true"` meanwhile, unless `whilePending` is `"run"`. Without `action` the button is a native `command="request-close"` invoker in JS-free mode and goes straight through the Root in library mode. `details.returnValue` is the `value`. |
|
|
293
|
+
| `whilePending` | `"run" \| "ignore"` | `"ignore"` | What a click, Enter or Space does while this part's `action` is pending. `"ignore"`: nothing (the click is cancelled, `aria-disabled="true"` meanwhile). `"run"`: the action runs again (`data-pending` until every run has settled, no `aria-disabled`); the dialog closes once the last run has settled, and only if the latest run resolved: a rejection leaves it open in both modes. No effect without `action`. See [A second click while pending](../concepts/pending-and-optimistic.md#second-click). |
|
|
296
294
|
| `value` | `string` | – | Becomes `dialog.returnValue`, and `details.returnValue` of `openChangeAction(false)`. |
|
|
297
295
|
| `disabled` | `boolean` | `false` | Native `disabled`; owned, so a `render` element cannot re-enable it. With a link or component `render` where the Close handles the click (library mode, or with `action`), `aria-disabled="true"` instead (the element stays focusable). |
|
|
298
296
|
| `className` | `string \| ((state: DialogCloseState) => string \| undefined)` | – | A class name, or a function of the part's state. |
|
|
@@ -303,7 +301,7 @@ Other props, such as `role="alertdialog"` or `onCancel`, pass through.
|
|
|
303
301
|
- **State**: `DialogCloseState` is `{ pending, disabled }`.
|
|
304
302
|
- **Owned**: `type` (on a `<button>` only), `disabled`, `aria-disabled`, `commandfor`, `command` (not on a link or other non-button host element), `value`, `onClick` (library mode, or with `action`), `data-pending`, `data-disabled`; a `render` element cannot re-enable a disabled Close.
|
|
305
303
|
|
|
306
|
-
|
|
304
|
+
By default (`whilePending="ignore"`) a second click, Enter or Space while the action is pending is ignored (and cancelled), and the button is `aria-disabled="true"` for as long as it shows `data-pending`, which spans the action and the close; it is never natively disabled, so it keeps focus. To close at once and finish the work in the background, do not return the promise: `action={() => { void save(); }}`.
|
|
307
305
|
|
|
308
306
|
### `Dialog.Form`
|
|
309
307
|
|
|
@@ -343,9 +341,9 @@ With field errors from `useActionState`, render it as a `Form.Root`: `<Dialog.Fo
|
|
|
343
341
|
| `::backdrop` | Popup | The modal backdrop. |
|
|
344
342
|
| `data-modal` | Popup | The `modal` prop (also before the dialog opens). |
|
|
345
343
|
| `data-open` | Trigger | Optimistic open state (library mode only). |
|
|
346
|
-
| `data-pending` | Trigger | An open
|
|
344
|
+
| `data-pending` | Trigger | An open or a part's close is in flight (library mode only). A dismissal never pends, but a request still running when a dismissal superseded it keeps it until that request settles. |
|
|
347
345
|
| `data-pending` | Close | Its `action` is in flight. |
|
|
348
|
-
| `aria-disabled` | Close | `"true"` while `data-pending
|
|
346
|
+
| `aria-disabled` | Close | `"true"` while `data-pending` with `whilePending="ignore"` (the default): a second click is ignored meanwhile. |
|
|
349
347
|
| `data-disabled` | Trigger, Close | The `disabled` prop (both modes). |
|
|
350
348
|
|
|
351
349
|
The `<dialog>` emits no `data-open`: `:open` and `:modal` are exact. Enter and exit animate in CSS, in both modes:
|
|
@@ -371,7 +369,7 @@ The CSS exit animates in Chromium and Safari; Firefox closes a dialog instantly.
|
|
|
371
369
|
| - | - | - |
|
|
372
370
|
| Enter / Space on the Trigger | Opens | the browser (JS-free) or the Trigger |
|
|
373
371
|
| Tab / Shift+Tab in a modal | Cycles through the dialog and the browser UI; the page is inert | the browser |
|
|
374
|
-
| Escape (modal) | Closes and returns focus; `
|
|
372
|
+
| Escape (modal) | Closes and returns focus; `onOpenChange(false, { reason: "dismiss" })` | the browser |
|
|
375
373
|
| Escape (non-modal) | Closes with `requestClose()` | the Popup (or `closedby` with the flag) |
|
|
376
374
|
| Escape in a nested dialog | Closes the innermost one only | the browser |
|
|
377
375
|
| Enter in a form field | Submits the Form: closes (through the Root in library mode), or runs the action and then closes | the browser / Form |
|
|
@@ -402,15 +400,13 @@ With `transition`, the Popup renders `<ViewTransition>` around the `<dialog>`. A
|
|
|
402
400
|
```css
|
|
403
401
|
::view-transition-new(.pop) { animation: 180ms ease-out both pop-in; }
|
|
404
402
|
::view-transition-old(.pop) { animation: 140ms ease-in both pop-out; }
|
|
405
|
-
/* Keep the CSS exit above for dismissals, but not while a view transition runs. */
|
|
406
|
-
html:active-view-transition .dialog { transition: none; }
|
|
407
403
|
@media (prefers-reduced-motion: reduce) {
|
|
408
404
|
::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
|
|
409
405
|
}
|
|
410
406
|
```
|
|
411
407
|
|
|
412
408
|
- Library-driven closes: a `Dialog.Close`, a `Dialog.Form` submit or settled action, a foreign `request-close` / `close` command, a controlled `open={false}`. Transition types: `fsui-dialog` plus `fsui-dialog-open` or `fsui-dialog-close`; a controlled close carries none.
|
|
413
|
-
- Dismissals (Escape, a click outside) animate with the CSS exit only: keep it
|
|
409
|
+
- Dismissals (Escape, a click outside) animate with the CSS exit only: keep it next to `transition`. The library turns the dialog's CSS transitions off for the moment of its own show and hide while a view transition runs, so you need no extra rule ([A popup with a CSS exit and a view transition](../concepts/transitions.md#css-exit)).
|
|
414
410
|
- The `::backdrop` is not captured on its own: it is part of the page snapshot and leaves with the root cross-fade. A backdrop that should animate with the dialog is an element rendered as the Popup's first child (`position: fixed; inset: 0`; clicks on it are not light dismiss).
|
|
415
411
|
- A plain open with `transition="none"` starts no document view transition (the content mounts under the already-mounted `<dialog>`). A Root inserted by a transition with `transition` on its Popup, or a nested Popup with `transition` that mounts with the outer content, runs the page cross-fade ([issue #35](https://github.com/uhyo/funstack-ui/issues/35)).
|
|
416
412
|
|
|
@@ -418,7 +414,7 @@ html:active-view-transition .dialog { transition: none; }
|
|
|
418
414
|
|
|
419
415
|
Concept: [Pending & optimistic state](../concepts/pending-and-optimistic.md)
|
|
420
416
|
|
|
421
|
-
Library mode: the Trigger shows the optimistic open state (`data-open`) and `data-pending` while an open
|
|
417
|
+
Library mode: the Trigger shows the optimistic open state (`data-open`) and `data-pending` while an open or a part's close is in flight; a dismissal is a fact and pends nothing. The Popup's content renders from the committed `open`. A Close with an `action` is a [pure trigger](../concepts/pending-and-optimistic.md#pure-trigger) (`data-pending`; `aria-disabled` while it ignores a second click, the default).
|
|
422
418
|
|
|
423
419
|
### Walkthrough (library mode)
|
|
424
420
|
|
|
@@ -466,13 +462,17 @@ function OrderDetails({ id }: { id: string }) {
|
|
|
466
462
|
// data is ready, then the dialog opens once, complete. The Close button's close is library-owned
|
|
467
463
|
// too: openChangeAction(false) runs first, then the dialog closes in a view transition
|
|
468
464
|
// (`transition`), so the exit animates in every engine, Firefox included. Escape and a click on
|
|
469
|
-
// the backdrop are dismissals: the browser closes the dialog (with the CSS exit)
|
|
470
|
-
//
|
|
465
|
+
// the backdrop are dismissals: the browser closes the dialog (with the CSS exit), a fact reported
|
|
466
|
+
// to `onOpenChange` synchronously. The readout shows what the Root received.
|
|
471
467
|
export function DialogOrders() {
|
|
472
468
|
const [last, setLast] = useState("(none yet)");
|
|
473
469
|
const record = (open: boolean, { reason, returnValue }: DialogOpenChangeDetails) => {
|
|
474
470
|
// The synchronous part of an action: this setState is a transition update.
|
|
475
|
-
setLast(`
|
|
471
|
+
setLast(`openChangeAction(${open}, "${reason}") returnValue=${JSON.stringify(returnValue)}`);
|
|
472
|
+
};
|
|
473
|
+
const recordFact = (open: boolean, { reason, returnValue }: DialogOpenChangeDetails) => {
|
|
474
|
+
// A fact handler: this setState is urgent.
|
|
475
|
+
setLast(`onOpenChange(${open}, "${reason}") returnValue=${JSON.stringify(returnValue)}`);
|
|
476
476
|
};
|
|
477
477
|
return (
|
|
478
478
|
<>
|
|
@@ -480,7 +480,7 @@ export function DialogOrders() {
|
|
|
480
480
|
{["1042", "1043"].map((id) => (
|
|
481
481
|
<li key={id} className="demo-row">
|
|
482
482
|
Order #{id}
|
|
483
|
-
<Dialog.Root defaultOpen={false} openChangeAction={record}>
|
|
483
|
+
<Dialog.Root defaultOpen={false} openChangeAction={record} onOpenChange={recordFact}>
|
|
484
484
|
<Dialog.Trigger className="demo-button">
|
|
485
485
|
{({ pending }) => (
|
|
486
486
|
<>
|
|
@@ -490,7 +490,7 @@ export function DialogOrders() {
|
|
|
490
490
|
)}
|
|
491
491
|
</Dialog.Trigger>
|
|
492
492
|
<Dialog.Popup
|
|
493
|
-
className="demo-dialog
|
|
493
|
+
className="demo-dialog"
|
|
494
494
|
lightDismiss
|
|
495
495
|
initialFocus="[data-autofocus]"
|
|
496
496
|
transition={{
|
|
@@ -517,7 +517,7 @@ export function DialogOrders() {
|
|
|
517
517
|
</button>
|
|
518
518
|
</div>
|
|
519
519
|
<output className="demo-readout">
|
|
520
|
-
last
|
|
520
|
+
last call: <code>{last}</code>
|
|
521
521
|
</output>
|
|
522
522
|
</>
|
|
523
523
|
);
|
|
@@ -529,14 +529,14 @@ export function DialogOrders() {
|
|
|
529
529
|
1. Click Details: the click is cancelled (so the native command does not run), the Trigger gets `data-open` and `data-pending`, and `openChangeAction(true, { reason: "activate", returnValue: undefined })` runs.
|
|
530
530
|
2. The commit that sets committed `open` renders the Popup's children; `OrderDetails` suspends, so React holds the commit. The dialog stays closed; the Trigger keeps spinning.
|
|
531
531
|
3. The data arrives: the content commits and `showModal()` runs in the same commit's layout effect, so the platform focuses fully rendered content (here the Close button, through `initialFocus`).
|
|
532
|
-
4. Close it with the Close button: the click is cancelled, the Trigger shows `data-pending` while `openChangeAction(false, { reason: "activate", returnValue: "done" })` runs, then the dialog closes in a view transition (the `transition` prop), in Firefox too. Escape or a click on the backdrop (`lightDismiss`) are dismissals: the browser closes the dialog at once and the Root
|
|
532
|
+
4. Close it with the Close button: the click is cancelled, the Trigger shows `data-pending` while `openChangeAction(false, { reason: "activate", returnValue: "done" })` runs, then the dialog closes in a view transition (the `transition` prop), in Firefox too. Escape or a click on the backdrop (`lightDismiss`) are dismissals: the browser closes the dialog at once and the Root calls `onOpenChange(false, { reason: "dismiss" })` in the same event, with nothing pending. The second open is instant (the data is cached).
|
|
533
533
|
5. If the opening action rejects, the error reaches the Error Boundary above the Root and the dialog never opens.
|
|
534
534
|
|
|
535
535
|
To open now and show a skeleton instead, put a `<Suspense>` boundary inside the Popup: a newly mounted boundary shows its fallback immediately.
|
|
536
536
|
|
|
537
537
|
> **A part's close is yours to refuse; a dismissal's is not**
|
|
538
538
|
>
|
|
539
|
-
> A close a part asks for waits for `openChangeAction(false)`: a controlled parent that keeps `open` gets a plain snap-back, and the dialog never blinks (for example "the save failed, keep editing", checked through `details.returnValue`). A dismissal is already done when
|
|
539
|
+
> A close a part asks for waits for `openChangeAction(false)`: a controlled parent that keeps `open` gets a plain snap-back, and the dialog never blinks (for example "the save failed, keep editing", checked through `details.returnValue`). A dismissal is already done when `onOpenChange` runs: a parent that does not adopt `false` gets the dialog re-opened at once, and the user sees it close and come back (a modal dialog takes focus back; a non-modal one leaves focus where the dismissal put it). Adopt a dismissal's `false` directly in `onOpenChange` (not in `startTransition`, not after an `await`). If the user dismisses the dialog while a part's close is still running, `onOpenChange` hears it at once and that close is superseded: a later veto of it changes nothing. Neither is a way to ask the user first: an action must never await input, so build confirmation inside the dialog (see the callout above).
|
|
540
540
|
|
|
541
541
|
## Suspense
|
|
542
542
|
|
|
@@ -548,7 +548,7 @@ Content that suspends holds the open: the dialog stays closed with the Trigger p
|
|
|
548
548
|
|
|
549
549
|
Concept: [Browser-owned state](../concepts/browser-owned-state.md)
|
|
550
550
|
|
|
551
|
-
JS-free mode: the browser owns everything through Invoker Commands. Library mode: opening and a close asked for by a part are
|
|
551
|
+
JS-free mode: the browser owns everything through Invoker Commands. Library mode: opening and a close asked for by a part are requests (`openChangeAction`); a dismissal (Escape, Android back, a click outside) is the browser's, a fact: the dialog closes at once, `onOpenChange(false)` is called with `reason: "dismiss"`, and a controlled parent that keeps `open` gets it re-opened at once. Dismissals animate with CSS only.
|
|
552
552
|
|
|
553
553
|
## Before hydration
|
|
554
554
|
|
|
@@ -642,15 +642,21 @@ export function DialogProfile() {
|
|
|
642
642
|
|
|
643
643
|
For a single "run this, then close" button without a form, such as Delete, use `Dialog.Close action`: it shows `data-pending` on the button and closes when the action resolves.
|
|
644
644
|
|
|
645
|
-
In library mode a `method="dialog"` submit is a library-owned close too, with the submitter's `value`, after your own `onSubmit` ran. To leave such a form to the browser, call `event.stopPropagation()` in its `onSubmit`: the dialog then closes natively and
|
|
645
|
+
In library mode a `method="dialog"` submit is a library-owned close too, with the submitter's `value`, after your own `onSubmit` ran. To leave such a form to the browser, call `event.stopPropagation()` in its `onSubmit`: the dialog then closes natively and `onOpenChange` hears it as a `reason: "dismiss"` fact.
|
|
646
646
|
|
|
647
647
|
### Server Functions
|
|
648
648
|
|
|
649
649
|
The dialog's action and the [form channel](../concepts/action-props.md#form-channel) are independent, and both usable from a Server Component:
|
|
650
650
|
|
|
651
651
|
```tsx
|
|
652
|
-
// Persist "seen" when the user
|
|
653
|
-
|
|
652
|
+
// Persist "seen" when the user closes an announcement: a Close button is a request,
|
|
653
|
+
// Escape a fact, so pass the Server Function to both. It receives (open, details): with a
|
|
654
|
+
// Trigger inside, the action is also called with true when the dialog opens.
|
|
655
|
+
<Dialog.Root
|
|
656
|
+
defaultOpen={!user.seenAnnouncement}
|
|
657
|
+
openChangeAction={markAnnouncementSeen}
|
|
658
|
+
onOpenChange={markAnnouncementSeen}
|
|
659
|
+
>
|
|
654
660
|
...
|
|
655
661
|
</Dialog.Root>
|
|
656
662
|
|
|
@@ -658,7 +664,7 @@ The dialog's action and the [form channel](../concepts/action-props.md#form-chan
|
|
|
658
664
|
<Dialog.Form action={saveProfile}>...</Dialog.Form>
|
|
659
665
|
```
|
|
660
666
|
|
|
661
|
-
`openChangeAction` is a per-dialog action with the Trigger's pending state; `Dialog.Form action` is React's form action with React's `useFormStatus`. The Form only observes the form channel to close the dialog afterwards; it never wraps your function and never reports form pending as the dialog's.
|
|
667
|
+
`openChangeAction` is a per-dialog action with the Trigger's pending state; `onOpenChange` is called and not awaited, nothing pends for it, and its rejection goes to `reportError`; `Dialog.Form action` is React's form action with React's `useFormStatus`. The Form only observes the form channel to close the dialog afterwards; it never wraps your function and never reports form pending as the dialog's.
|
|
662
668
|
|
|
663
669
|
## Recipes
|
|
664
670
|
|
|
@@ -667,7 +673,7 @@ The dialog's action and the [form channel](../concepts/action-props.md#form-chan
|
|
|
667
673
|
```tsx
|
|
668
674
|
const [open, setOpen] = useState(false);
|
|
669
675
|
|
|
670
|
-
<Dialog.Root open={open} openChangeAction={
|
|
676
|
+
<Dialog.Root open={open} openChangeAction={setOpen} onOpenChange={setOpen}>
|
|
671
677
|
<Dialog.Popup>...</Dialog.Popup>
|
|
672
678
|
</Dialog.Root>
|
|
673
679
|
```
|
|
@@ -19,7 +19,11 @@ export function MenuRowActions() {
|
|
|
19
19
|
const [last, setLast] = useState("(none yet)");
|
|
20
20
|
const [fail, setFail] = useState(false);
|
|
21
21
|
const record = (open: boolean, { reason }: MenuOpenChangeDetails) => {
|
|
22
|
-
setLast(`
|
|
22
|
+
setLast(`openChangeAction(${open}, "${reason}")`);
|
|
23
|
+
};
|
|
24
|
+
// Escape, a click outside, Tab: facts, reported synchronously and not awaited.
|
|
25
|
+
const recordFact = (open: boolean, { reason }: MenuOpenChangeDetails) => {
|
|
26
|
+
setLast(`onOpenChange(${open}, "${reason}")`);
|
|
23
27
|
};
|
|
24
28
|
const done = (text: string) => () => startTransition(() => setStatus(text));
|
|
25
29
|
|
|
@@ -27,7 +31,7 @@ export function MenuRowActions() {
|
|
|
27
31
|
<div className="demo-stack">
|
|
28
32
|
<div className="demo-row">
|
|
29
33
|
<span>{status}</span>
|
|
30
|
-
<Menu.Root openChangeAction={record}>
|
|
34
|
+
<Menu.Root openChangeAction={record} onOpenChange={recordFact}>
|
|
31
35
|
<Menu.Trigger className="demo-button" aria-label="Actions for Report.pdf">
|
|
32
36
|
{({ pending }) => (pending ? <span className="demo-spinner" aria-hidden /> : "⋯")}
|
|
33
37
|
</Menu.Trigger>
|
|
@@ -70,7 +74,7 @@ export function MenuRowActions() {
|
|
|
70
74
|
<input type="checkbox" checked={fail} onChange={(e) => setFail(e.target.checked)} />
|
|
71
75
|
Make Archive fail
|
|
72
76
|
</label>
|
|
73
|
-
<p className="demo-readout">Last
|
|
77
|
+
<p className="demo-readout">Last call: {last}</p>
|
|
74
78
|
</div>
|
|
75
79
|
);
|
|
76
80
|
}
|
|
@@ -141,7 +145,9 @@ export function MenuRowActions() {
|
|
|
141
145
|
outline: none;
|
|
142
146
|
background: color-mix(in srgb, var(--color-primary) 15%, transparent);
|
|
143
147
|
}
|
|
144
|
-
|
|
148
|
+
/* Not while pending: an item that ignores activation while its action runs is aria-disabled too
|
|
149
|
+
(`whilePending="ignore"`), and its pending look is [data-pending] below. */
|
|
150
|
+
.demo-menu [aria-disabled="true"]:not([data-pending]) {
|
|
145
151
|
opacity: 0.45;
|
|
146
152
|
cursor: default;
|
|
147
153
|
}
|
|
@@ -201,12 +207,6 @@ export function MenuRowActions() {
|
|
|
201
207
|
translate: 0 -4px;
|
|
202
208
|
}
|
|
203
209
|
}
|
|
204
|
-
/* Keep the CSS exit for dismissals, but not while a view transition runs (Chromium would
|
|
205
|
-
capture a fading menu twice). The whole class: submenus close with their parent. */
|
|
206
|
-
html:active-view-transition .demo-menu {
|
|
207
|
-
transition: none;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
210
|
@media (prefers-reduced-motion: reduce) {
|
|
211
211
|
.demo-menu {
|
|
212
212
|
transition: none;
|
|
@@ -253,7 +253,7 @@ import { Menu } from "@funstack/ui/menu";
|
|
|
253
253
|
|
|
254
254
|
### Items, actions and closing
|
|
255
255
|
|
|
256
|
-
Click, Enter or Space on an `Item` runs its `action` in the item's own transition. The menu **stays open while the action runs**, with `data-pending` on the item, and closes once it settles, through the top-level Root (`openChangeAction(false, { reason: "activate" })`, then `hidePopover()` in the commit, with a view transition if the Popup has `transition`). A synchronous action closes in the same tick. A rejection leaves the menu open and reaches the nearest Error Boundary above the item. A second click, Enter or Space while the action is pending is ignored (and cancelled), and the item is `aria-disabled="true"` meanwhile. A pending item is an ordinary item for navigation; only the open focus skips items with the `disabled` prop (`data-disabled`). For "close now, work in the background" do not return the promise: `action={() => { void archive(id); }}`.
|
|
256
|
+
Click, Enter or Space on an `Item` runs its `action` in the item's own transition. The menu **stays open while the action runs**, with `data-pending` on the item, and closes once it settles, through the top-level Root (`openChangeAction(false, { reason: "activate" })`, then `hidePopover()` in the commit, with a view transition if the Popup has `transition`). A synchronous action closes in the same tick. A rejection leaves the menu open and reaches the nearest Error Boundary above the item. A second click, Enter or Space while the action is pending is ignored (and cancelled), and the item is `aria-disabled="true"` meanwhile: the first activation already ends in the menu's close. A `closeOnActivate={false}` item is different: nothing of the library's follows its action, so it runs every activation (a "Zoom in" item counts each press), with `data-pending` until the last run settles and no `aria-disabled`. `whilePending` overrides either default. A pending item is an ordinary item for navigation; only the open focus skips items with the `disabled` prop (`data-disabled`). For "close now, work in the background" do not return the promise: `action={() => { void archive(id); }}`.
|
|
257
257
|
|
|
258
258
|
- `closeOnActivate={false}` keeps the menu open (a "Refresh" item).
|
|
259
259
|
- A [Button](button.md) inside a `Menu.Popup` is not a menu item: no `role="menuitem"`, not in the arrow-key set, and it does not close the menu. Use `Menu.Item` for actions in a menu.
|
|
@@ -341,9 +341,10 @@ A `Menu.ContextTrigger` in the Root opens the same Popup at the pointer from a r
|
|
|
341
341
|
|
|
342
342
|
| Prop | Type | Default | Description |
|
|
343
343
|
| - | - | - | - |
|
|
344
|
-
| `open` | `boolean` | – | Controlled open state. undefined means uncontrolled. |
|
|
344
|
+
| `open` | `boolean` | – | Controlled open state. undefined means uncontrolled. Pass `onOpenChange` too: the browser closes the menu without asking (development warns). A parent that keeps `true` after a dismissal gets the menu shown again at once, with focus left where the dismissal put it (no initial focus). |
|
|
345
345
|
| `defaultOpen` | `boolean` | – | Initial open state when uncontrolled. Shown after hydration. |
|
|
346
|
-
| `openChangeAction` | `ChangeAction<boolean, MenuOpenChangeDetails>` | – | Awaited for `true` (the menu opens when it resolves and the items have rendered) and for the closes a part asks for (the Trigger, an item's activation, ArrowLeft in a submenu); the menu stays shown until the action settles, with `data-pending` on the Trigger meanwhile.
|
|
346
|
+
| `openChangeAction` | `ChangeAction<boolean, MenuOpenChangeDetails>` | – | Requests only. Awaited for `true` (the menu opens when it resolves and the items have rendered) and for the closes a part asks for (the Trigger, an item's activation, ArrowLeft in a submenu, the pointer leaving a hover-opened submenu); the menu stays shown until the action settles, with `data-pending` on the Trigger meanwhile. Never called for a dismissal (`onOpenChange`). Runs in the Root's transition; may be a Server Function. `details.reason`: `"activate"`, `"dismiss"` (the hover close of a submenu) or `"platform"` (found open on hydration; `event` is `undefined`). |
|
|
347
|
+
| `onOpenChange` | `UrgentChangeHandler<boolean, MenuOpenChangeDetails>` | – | Facts only: the menu was closed without the library closing it on request. Always `false`. `details.reason`: `"dismiss"` (Escape, a click outside, Tab or focus leaving the menu, a right- or middle-click outside, the parent menu closing a submenu, a scroll or a release outside under a [context menu](context-menu.md), script) or `"activate"` (a [foreign invoker](../concepts/browser-owned-state.md#foreign-invoker), whose press does not move focus out of the menu; a Trigger rendered as another element, pressed while open). Called synchronously in the browser's `toggle` event, outside any transition, and not awaited: nothing is pending and no view transition runs. In controlled mode set state directly here (`onOpenChange={setOpen}`), never in `startTransition` or after an `await`; a parent that keeps `open` gets the menu shown again at once. Each submenu's Root has its own. May return a promise (a Server Function); a rejection or a throw goes to `reportError`. |
|
|
347
348
|
| `loop` | `boolean` | `true` | ArrowDown / ArrowUp wrap from the last item to the first and back. |
|
|
348
349
|
| `delay` | `number` | `100` | Submenu only: milliseconds from hovering the SubmenuTrigger to the open. A development warning on a top-level Root. |
|
|
349
350
|
| `closeDelay` | `number` | `150` | Submenu only: milliseconds from the pointer leaving the SubmenuTrigger and the submenu to the close. |
|
|
@@ -375,7 +376,7 @@ Use it in a top-level Root only. A primary-button press on it while the menu is
|
|
|
375
376
|
| - | - | - | - |
|
|
376
377
|
| `side` | `"top" \| "bottom" \| "left" \| "right" \| "inline-start" \| "inline-end" \| null` | `"bottom" ("inline-end" in a submenu)` | Placement through inline `position-area`, with `position-try-fallbacks` flipping it (a submenu flips inline only). `inline-start` / `inline-end` follow the popup's direction: a submenu opens on the right of its item in LTR and on the left in RTL, the side the arrow keys point to. `left` / `right` stay physical. `null` emits no inline placement and no `data-side` / `data-align`. Ignored for an open from a [Menu.ContextTrigger](context-menu.md), which is placed at the pointer; there `null` opts out of the inline point placement too. |
|
|
377
378
|
| `align` | `"start" \| "center" \| "end"` | `"start"` | Alignment along the side. On a top / bottom side `start` / `end` are inline-relative (`start` lines up the inline-start edges: the left in LTR, the right in RTL); on the other sides the top / bottom edges. |
|
|
378
|
-
| `keepMounted` | `boolean` | `false` | false: the items render only while open (items that suspend hold the open, with `data-pending` on the Trigger). true: they stay mounted in `<Activity mode="hidden"
|
|
379
|
+
| `keepMounted` | `boolean` | `false` | false: the items render only while open (items that suspend hold the open, with `data-pending` on the Trigger). true: they stay mounted in `<Activity mode="hidden">`; an item action that rejects while the menu is closed goes to `reportError`, not to an Error Boundary. |
|
|
379
380
|
| `experimental_focusgroup` | `boolean` | `false` | Renders `focusgroup="menu wrap\|nowrap"`. Where the engine implements it (Chromium 150+), the browser moves focus for ArrowUp / ArrowDown / Home / End and items render no `tabindex`; elsewhere nothing changes. Typeahead, activation, submenu keys and Tab stay in JS. |
|
|
380
381
|
| `transition` | `ViewTransitionClass` | – | Forwarded to a `<ViewTransition>` around the popup element: animates the open and every library-driven close (an item's activation, the Trigger, ArrowLeft, a hover close, controlled) in every engine. Dismissals animate with CSS only. |
|
|
381
382
|
| `className` | `string \| ((state: MenuPopupState) => string \| undefined)` | – | A class name, or a function of the part's state. |
|
|
@@ -392,7 +393,7 @@ A menu shown on the physical side you asked for costs no render for the placemen
|
|
|
392
393
|
|
|
393
394
|
| Prop | Type | Default | Description |
|
|
394
395
|
| - | - | - | - |
|
|
395
|
-
| `action` | `Action<[details: MenuItemDetails]>` | – | Runs in the item's own transition (`data-pending` on the item); the menu closes when it settles. A second activation while it is pending is ignored, and the item is `aria-disabled="true"` meanwhile. May be a Server Function (`details.event` is virtual). A rejection keeps the menu open and reaches the nearest Error Boundary above the item. |
|
|
396
|
+
| `action` | `Action<[details: MenuItemDetails]>` | – | Runs in the item's own transition (`data-pending` on the item); the menu closes when it settles. A second activation while it is pending is ignored, and the item is `aria-disabled="true"` meanwhile, unless `whilePending` is `"run"` (the default with `closeOnActivate={false}`). May be a Server Function (`details.event` is virtual). A rejection keeps the menu open and reaches the nearest Error Boundary above the item. |
|
|
396
397
|
| `closeOnActivate` | `boolean` | `true` | Close the whole menu once `action` settles. |
|
|
397
398
|
| `disabled` | `boolean` | `false` | Renders `aria-disabled="true"` and `data-disabled`, never the native attribute: a disabled item stays focusable (the APG) and is reached by the arrow keys and typeahead, but never activates. |
|
|
398
399
|
| `label` | `string` | – | Text that typeahead matches when the item's text content is not representative (an icon). Rendered as `data-typeahead`. |
|
|
@@ -400,9 +401,10 @@ A menu shown on the physical side you asked for costs no render for the placemen
|
|
|
400
401
|
| `style` | `CSSProperties \| ((state: MenuItemState) => CSSProperties \| undefined)` | – | Inline style, or a function of the part's state. |
|
|
401
402
|
| `children` | `ReactNode \| ((state: MenuItemState) => ReactNode)` | – | Content, or a function of the part's state. |
|
|
402
403
|
| `render` | `ReactElement \| ((props, state: MenuItemState) => ReactNode)` | – | Replace the default \<button> (element form) or take over rendering (function form). |
|
|
404
|
+
| `whilePending` | `"run" \| "ignore"` | `"ignore", or "run" with closeOnActivate={false}` | What a click, Enter or Space does while this item's `action` is pending. `"ignore"`: nothing (the event is cancelled, `aria-disabled="true"` meanwhile). `"run"`: the action runs again (`data-pending` until every run has settled, no `aria-disabled`); a closing item closes the menu once the last run has settled, and only if the latest run resolved: a rejection keeps the menu open in both modes. No effect without `action`. See [A second click while pending](../concepts/pending-and-optimistic.md#second-click). |
|
|
403
405
|
|
|
404
406
|
- **State**: `MenuItemState` is `{ pending, disabled }`.
|
|
405
|
-
- **Owned**: `type` (on a `<button>`), `role`, `tabIndex`, `disabled` (always absent), `aria-disabled` (the `disabled` prop, or while pending), `onClick`, `onKeyDown`, `onPointerMove`, `data-pending`, `data-disabled`, `data-typeahead`.
|
|
407
|
+
- **Owned**: `type` (on a `<button>`), `role`, `tabIndex`, `disabled` (always absent), `aria-disabled` (the `disabled` prop, or while pending with `whilePending="ignore"`), `onClick`, `onKeyDown`, `onPointerMove`, `data-pending`, `data-disabled`, `data-typeahead`.
|
|
406
408
|
|
|
407
409
|
### `Menu.CheckboxItem`
|
|
408
410
|
|
|
@@ -488,7 +490,7 @@ Both an item of the parent menu (roving `tabindex`, typeahead) and the trigger o
|
|
|
488
490
|
| `data-open` | ContextTrigger | Optimistic open state of the Root (no `aria-expanded`: the region has no role). |
|
|
489
491
|
| `data-pending` | Trigger, SubmenuTrigger, ContextTrigger | An open or close of the Root is in flight (items that suspend hold the open). |
|
|
490
492
|
| `data-pending` | Item, CheckboxItem, RadioItem, RadioGroup | The item's `action` or change action is in flight; on the RadioGroup while a selection is. |
|
|
491
|
-
| `aria-disabled` | Item, CheckboxItem, RadioItem, SubmenuTrigger | `"true"` for the `disabled` prop (items are never natively disabled), and on an Item while its `action` is pending. |
|
|
493
|
+
| `aria-disabled` | Item, CheckboxItem, RadioItem, SubmenuTrigger | `"true"` for the `disabled` prop (items are never natively disabled), and on an Item while its `action` is pending and it ignores a second activation (`whilePending="ignore"`, the default unless `closeOnActivate={false}`). |
|
|
492
494
|
| `data-disabled` | Trigger, items, ContextTrigger | The `disabled` prop. |
|
|
493
495
|
| `aria-checked`, `data-checked` | CheckboxItem, RadioItem | Optimistic checked state. |
|
|
494
496
|
| `data-typeahead` | Item, CheckboxItem, RadioItem, SubmenuTrigger | The `label` prop: the text typeahead matches. |
|
|
@@ -514,7 +516,7 @@ Both an item of the parent menu (roving `tabindex`, typeahead) and the trigger o
|
|
|
514
516
|
- Under `direction: rtl` ArrowLeft opens and ArrowRight closes a submenu, and the submenu opens on the left of its item (the default `side="inline-end"`); the top-level menu's `align="start"` lines up the right edges. Both follow the popup's inherited direction through `self-*` `position-area` keywords, so an RTL container works as well as an RTL page. Firefox misplaces popups inside a direction island ([#89](https://github.com/uhyo/funstack-ui/issues/89); see [Tooltip](tooltip.md#browser-notes)).
|
|
515
517
|
- **Focus is real DOM focus** on items (no `aria-activedescendant`). Every open focuses the first item, pointer opens included (no focus ring then, through `focus({ focusVisible: false })`; Safari may still show a ring on the first item after a click); a submenu opened by hover keeps focus on its trigger. **Moving the pointer over an item focuses it**, so keyboard and pointer always agree on the current item: style `:focus` as the hover state. A press on the menu's own space (padding, a `Separator`, a `GroupLabel`) keeps focus on the current item, so the arrow keys keep working. So does a press on a `<button>` Trigger while the menu is open: the click then closes it like an item's activation, on every browser (a Trigger rendered as another element is light-dismissed first: see [Triggers of a popup](../concepts/browser-owned-state.md#popup-triggers)).
|
|
516
518
|
- **Hover intent** for submenus: the submenu opens `delay` ms (100) after the pointer enters its trigger and closes `closeDelay` ms (150) after the pointer leaves both, unless keyboard focus is inside it. Touch never opens on hover.
|
|
517
|
-
- **Tab closes immediately**, without
|
|
519
|
+
- **Tab closes immediately**, without asking `openChangeAction`: a menu must not linger once focus has moved on. It is a fact, reported to `onOpenChange` as `"dismiss"`.
|
|
518
520
|
- **ARIA:** the Trigger and SubmenuTrigger have `aria-haspopup="menu"`; as invokers, the browser exposes their expanded state ([Triggers of a popup](../concepts/browser-owned-state.md#popup-triggers)); the Popup `role="menu"` and `aria-labelledby` pointing at its trigger; items their roles and `aria-checked` / `aria-disabled`.
|
|
519
521
|
|
|
520
522
|
### Inside a Toolbar
|
|
@@ -537,7 +539,90 @@ Opens and closes: `fsui-menu` plus `fsui-menu-open` or `fsui-menu-close`. A Chec
|
|
|
537
539
|
|
|
538
540
|
Concept: [Pending & optimistic state](../concepts/pending-and-optimistic.md)
|
|
539
541
|
|
|
540
|
-
The Trigger's `data-open` and CheckboxItem and RadioItem `data-checked` are optimistic; the state the browser exposes on the Trigger follows the shown menu. Items render from the committed open state. An Item is a [pure trigger](../concepts/pending-and-optimistic.md#pure-trigger): `data-pending` while its action runs
|
|
542
|
+
The Trigger's `data-open` and CheckboxItem and RadioItem `data-checked` are optimistic; the state the browser exposes on the Trigger follows the shown menu. Items render from the committed open state. An Item is a [pure trigger](../concepts/pending-and-optimistic.md#pure-trigger): `data-pending` while its action runs; a second activation is ignored, or with `closeOnActivate={false}` runs again (`whilePending`).
|
|
543
|
+
|
|
544
|
+
### A slow `openChangeAction`
|
|
545
|
+
|
|
546
|
+
A submenu's `Menu.Root` has its own `openChangeAction` and `onOpenChange`. Here both actions take 2 seconds, like a server call, and the handlers log the dismissals. Each trigger is exposed as expanded exactly while its menu is shown:
|
|
547
|
+
|
|
548
|
+
```tsx title="MenuSlowOpen.tsx"
|
|
549
|
+
"use client";
|
|
550
|
+
import { startTransition, useState } from "react";
|
|
551
|
+
import { Menu } from "@funstack/ui/menu";
|
|
552
|
+
import type { MenuOpenChangeDetails } from "@funstack/ui/menu";
|
|
553
|
+
import { sleep } from "./fake-api.js";
|
|
554
|
+
|
|
555
|
+
// A slow `openChangeAction` on the menu and on its submenu (a nested Root has its own): a
|
|
556
|
+
// pretend server call of 2 seconds for every request. Opening: the Trigger (or SubmenuTrigger)
|
|
557
|
+
// gets data-open and data-pending at once, the menu is shown when the action settles. Choosing an
|
|
558
|
+
// item closes the menu when the close's action settles. Escape and a click outside are the
|
|
559
|
+
// browser's, a fact: the menu hides at once, nothing is pending and the action is not called;
|
|
560
|
+
// `onOpenChange` reports it (also for a submenu closed with its parent). The browser exposes each
|
|
561
|
+
// trigger as expanded exactly while its menu is shown. The readout is plain text, not a live
|
|
562
|
+
// region.
|
|
563
|
+
export function MenuSlowOpen() {
|
|
564
|
+
const [log, setLog] = useState("(none yet)");
|
|
565
|
+
const [view, setView] = useState("List");
|
|
566
|
+
const slow =
|
|
567
|
+
(menu: string) =>
|
|
568
|
+
async (open: boolean, { reason }: MenuOpenChangeDetails) => {
|
|
569
|
+
const call = `${menu} openChangeAction(${open}, "${reason}")`;
|
|
570
|
+
setLog(`${call}: running…`);
|
|
571
|
+
await sleep(2000);
|
|
572
|
+
// After an await: wrap the update in startTransition (React limitation).
|
|
573
|
+
startTransition(() => setLog(`${call}: settled`));
|
|
574
|
+
};
|
|
575
|
+
// A fact: called in the browser's event, not awaited. A plain setState here is urgent.
|
|
576
|
+
const dismissed =
|
|
577
|
+
(menu: string) =>
|
|
578
|
+
(open: boolean, { reason }: MenuOpenChangeDetails) => {
|
|
579
|
+
setLog(`${menu} onOpenChange(${open}, "${reason}")`);
|
|
580
|
+
};
|
|
581
|
+
const choose = (next: string) => () => startTransition(() => setView(next));
|
|
582
|
+
|
|
583
|
+
return (
|
|
584
|
+
<div className="demo-stack">
|
|
585
|
+
<div className="demo-row">
|
|
586
|
+
<span>View: {view}</span>
|
|
587
|
+
<Menu.Root openChangeAction={slow("menu")} onOpenChange={dismissed("menu")}>
|
|
588
|
+
<Menu.Trigger className="demo-button">
|
|
589
|
+
{({ pending }) => (
|
|
590
|
+
<>Options{pending && <span className="demo-spinner" aria-hidden />}</>
|
|
591
|
+
)}
|
|
592
|
+
</Menu.Trigger>
|
|
593
|
+
<Menu.Popup className="demo-menu">
|
|
594
|
+
<Menu.Item action={choose("List")}>List</Menu.Item>
|
|
595
|
+
<Menu.Item action={choose("Grid")}>Grid</Menu.Item>
|
|
596
|
+
<Menu.Separator />
|
|
597
|
+
<Menu.Root openChangeAction={slow("submenu")} onOpenChange={dismissed("submenu")}>
|
|
598
|
+
<Menu.SubmenuTrigger>
|
|
599
|
+
{({ pending }) => (
|
|
600
|
+
<>Sort by{pending && <span className="demo-spinner" aria-hidden />}</>
|
|
601
|
+
)}
|
|
602
|
+
</Menu.SubmenuTrigger>
|
|
603
|
+
<Menu.Popup className="demo-menu">
|
|
604
|
+
<Menu.Item action={choose("List, by name")}>Name</Menu.Item>
|
|
605
|
+
<Menu.Item action={choose("List, by date")}>Date</Menu.Item>
|
|
606
|
+
</Menu.Popup>
|
|
607
|
+
</Menu.Root>
|
|
608
|
+
</Menu.Popup>
|
|
609
|
+
</Menu.Root>
|
|
610
|
+
</div>
|
|
611
|
+
<p className="demo-readout">
|
|
612
|
+
Last: <code>{log}</code>
|
|
613
|
+
</p>
|
|
614
|
+
</div>
|
|
615
|
+
);
|
|
616
|
+
}
|
|
617
|
+
```
|
|
618
|
+
|
|
619
|
+
`menu.css`: the same file as above.
|
|
620
|
+
|
|
621
|
+
- Open the menu (click, Enter) or the "Sort by" submenu (hover, ArrowRight): the trigger gets `data-open` and `data-pending` at once and stays collapsed; the menu is shown, focus moves into it and the trigger is expanded when the action settles.
|
|
622
|
+
- Choose an item, or click the Trigger again: the menu stays shown and the Trigger expanded until the close's action settles.
|
|
623
|
+
- Escape or a click outside: a fact. The menu hides and the Trigger is collapsed at once; nothing is pending and the slow action is not called; `onOpenChange` is (each open submenu's too, when the whole stack closes).
|
|
624
|
+
|
|
625
|
+
The readout under the example is plain text, not a live region, so it does not interrupt a screen reader.
|
|
541
626
|
|
|
542
627
|
## Suspense
|
|
543
628
|
|
|
@@ -560,7 +645,7 @@ The items render from committed state, so a submenu read with `use()`:
|
|
|
560
645
|
|
|
561
646
|
Concept: [Browser-owned state](../concepts/browser-owned-state.md)
|
|
562
647
|
|
|
563
|
-
The popup is a `popover="auto"`: the top layer, light dismiss and Escape are the browser's. A dismissal closes the menu at once
|
|
648
|
+
The popup is a `popover="auto"`: the top layer, light dismiss and Escape are the browser's. A dismissal closes the menu at once, a fact: `onOpenChange(false)` is called with `reason: "dismiss"`, nothing is pending, and it animates with CSS only.
|
|
564
649
|
|
|
565
650
|
## Before hydration
|
|
566
651
|
|
|
@@ -576,11 +661,7 @@ Style the popup with `:popover-open` and the items with `[role^="menuitem"]`, `:
|
|
|
576
661
|
<Menu.Popup transition={{ "fsui-menu-open": "menu-in", "fsui-menu-close": "menu-out", default: "none" }}>
|
|
577
662
|
```
|
|
578
663
|
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
```css
|
|
582
|
-
html:active-view-transition .menu { transition: none; }
|
|
583
|
-
```
|
|
664
|
+
Keep the CSS exit next to `transition`: it animates the dismissals. The library turns the popup's CSS transitions off for the moment of its own show and hide while a view transition runs, so its show or hide never runs a CSS transition and you need no extra rule ([A popup with a CSS exit and a view transition](../concepts/transitions.md#css-exit)).
|
|
584
665
|
|
|
585
666
|
## Browser notes
|
|
586
667
|
|