@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
|
@@ -90,12 +90,8 @@ export function PopoverShare() {
|
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
/* With `transition`, the view transition animates library-driven opens and closes (Firefox
|
|
93
|
-
included); dismissals keep the CSS exit above.
|
|
94
|
-
|
|
95
|
-
in the close's new snapshot as well (a double image). */
|
|
96
|
-
html:active-view-transition .demo-popover-vt {
|
|
97
|
-
transition: none;
|
|
98
|
-
}
|
|
93
|
+
included); dismissals keep the CSS exit above.
|
|
94
|
+
The library keeps the two apart; no extra rule is needed. */
|
|
99
95
|
|
|
100
96
|
::view-transition-new(.pop) {
|
|
101
97
|
animation: 160ms ease-out both demo-pop-in;
|
|
@@ -211,22 +207,22 @@ import { Popover } from "@funstack/ui/popover";
|
|
|
211
207
|
|
|
212
208
|
| | JS-free mode | Library mode |
|
|
213
209
|
| - | - | - |
|
|
214
|
-
| Selected when | Root has none of `open`, `defaultOpen`, `openChangeAction` | Root has any of them |
|
|
210
|
+
| Selected when | Root has none of `open`, `defaultOpen`, `openChangeAction`, `onOpenChange` | Root has any of them |
|
|
215
211
|
| Open | the browser toggles it (the Trigger's `popovertarget`) | the click is intercepted and dispatched in the Root's transition; `showPopover({ source: trigger })` runs in the commit that mounts the content. Any other open (a foreign invoker, a script) is cancelled at `beforetoggle` and routed the same way |
|
|
216
212
|
| Close by a part (Trigger, Close) | the browser | the library: `openChangeAction(false)` is awaited, then `hidePopover()` runs in the commit |
|
|
217
|
-
| Close by a dismissal (Escape, click outside, another popover) | the browser | the browser; `
|
|
213
|
+
| Close by a dismissal (Escape, click outside, another popover) | the browser | the browser; a fact: `onOpenChange(false)` is called synchronously, nothing is pending, no view transition |
|
|
218
214
|
| Popup content | always mounted (in the server HTML) | rendered from committed `open`; unmounted while closed unless `keepMounted` |
|
|
219
215
|
| Trigger `data-open` | kept current on the element from the popup's `toggle` event | optimistic, rendered |
|
|
220
216
|
| Trigger `data-pending` | not emitted | emitted |
|
|
221
217
|
| Before hydration | everything works | the native open happens; the content arrives on hydration |
|
|
222
218
|
| `transition` on Popup | no effect (development warning) | animates opens, content swaps and every library-driven close |
|
|
223
219
|
|
|
224
|
-
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, a click outside, another popover opening) is the browser's
|
|
220
|
+
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, a click outside, another popover opening) 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).
|
|
225
221
|
|
|
226
222
|
### <a id="other-openers"></a>Other ways to open and close
|
|
227
223
|
|
|
228
|
-
- **[Foreign invokers](../concepts/browser-owned-state.md#foreign-invoker) and scripts:** in library mode any open that the library did not start (a `<button commandfor command="show-popover">`, a `<button popovertarget>`, a script `showPopover()`) is cancelled at `beforetoggle` and dispatched with that `ToggleEvent`. A foreign close happens natively
|
|
229
|
-
- **Hover card (Chromium):** a `<button interestfor>` naming the Popup (your own button, or the Trigger with `interestfor` added) opens it on interest (hover or keyboard focus) through the library, and in library mode the Popup hides again on lost interest:
|
|
224
|
+
- **[Foreign invokers](../concepts/browser-owned-state.md#foreign-invoker) and scripts:** in library mode any open that the library did not start (a `<button commandfor command="show-popover">`, a `<button popovertarget>`, a script `showPopover()`) is cancelled at `beforetoggle` and dispatched with that `ToggleEvent`. A foreign close happens natively, so it is a fact: `onOpenChange(false)` with `"activate"` and a `hide-popover` or `toggle-popover` command's `CommandEvent`, or a `<button popovertarget>`'s `beforetoggle` `ToggleEvent`, whose `source` is the button. Escape, a click outside and a script `hidePopover()` are `"dismiss"` facts.
|
|
225
|
+
- **Hover card (Chromium):** a `<button interestfor>` naming the Popup (your own button, or the Trigger with `interestfor` added) opens it on interest (hover or keyboard focus) through the library, and in library mode the Popup hides again on lost interest: a `"dismiss"` fact, `onOpenChange(false)`, whose `details.event` is the `loseinterest` event (its `source` is the button). Lost interest while the open is still pending cancels it (a request, `openChangeAction(false, { reason: "dismiss" })`, superseding the open), so the card never appears under a pointer that has left. A Trigger-click open stays open on lost interest, as in the platform. As with the platform's own lost-interest hide, focus is not returned to the Trigger. Firefox and Safari ignore `interestfor`, so give the button a click path (make it the Trigger) when the card must open everywhere. For a name or description (`role="tooltip"` content), use [Tooltip](tooltip.md).
|
|
230
226
|
|
|
231
227
|
## Props
|
|
232
228
|
|
|
@@ -234,9 +230,10 @@ In library mode, opening and [a part's close](../concepts/browser-owned-state.md
|
|
|
234
230
|
|
|
235
231
|
| Prop | Type | Default | Description |
|
|
236
232
|
| - | - | - | - |
|
|
237
|
-
| `open` | `boolean` | – | Controlled open state. undefined means uncontrolled. Selects library mode. |
|
|
233
|
+
| `open` | `boolean` | – | Controlled open state. undefined means uncontrolled. Selects library mode. Pass `onOpenChange` too: the browser closes the popover without asking (development warns). |
|
|
238
234
|
| `defaultOpen` | `boolean` | – | Initial open state in uncontrolled library mode. A popover that starts open is shown after hydration (there is no attribute for an open popover in HTML); its content and the Trigger's `data-open` are already in the server HTML, while the Trigger is exposed collapsed until the popup is shown. `defaultOpen={false}` is the usual way to select library mode without an action. |
|
|
239
|
-
| `openChangeAction` | `ChangeAction<boolean, PopoverOpenChangeDetails>` | – | Awaited for `true` (the popover opens when it resolves and the content has rendered) and for a `false` the user asked a part for (Trigger, Close: the popover hides when it resolves).
|
|
235
|
+
| `openChangeAction` | `ChangeAction<boolean, PopoverOpenChangeDetails>` | – | Requests only. Awaited for `true` (the popover opens when it resolves and the content has rendered) and for a `false` the user asked a part for (Trigger, Close: the popover hides when it resolves). 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"` (Trigger, Close, a foreign open), `"dismiss"` (lost interest while an `interestfor` open is still pending) or `"platform"` (found open on hydration; `event` is `undefined`). Selects library mode. |
|
|
236
|
+
| `onOpenChange` | `UrgentChangeHandler<boolean, PopoverOpenChangeDetails>` | – | Facts only: the popover was closed without the library closing it. Always `false`. `details.reason`: `"dismiss"` (Escape, a click outside, another popover or modal dialog, a parent popover closing, script `hidePopover()`, lost interest on an `interestfor` button) or `"activate"` (a foreign invoker; a non-button Trigger 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 popover shown again at once. May return a promise (a Server Function); a rejection or a throw goes to `reportError`. Selects library mode. |
|
|
240
237
|
| `children` | `ReactNode \| ((state: PopoverRootState) => ReactNode)` | – | The parts. The function form receives the optimistic state and must not suspend. |
|
|
241
238
|
|
|
242
239
|
- **State**: `PopoverRootState` is `{ open, pending }`; `open` is optimistic, and both are `false` in JS-free mode.
|
|
@@ -254,10 +251,10 @@ A `<button popovertarget>`: see [Triggers of a popup](../concepts/browser-owned-
|
|
|
254
251
|
| `children` | `ReactNode \| ((state: PopoverTriggerState) => ReactNode)` | – | Rendered from optimistic state; must not suspend. |
|
|
255
252
|
| `render` | `ReactElement \| ((props, state: PopoverTriggerState) => ReactNode)` | – | Replace the default \<button> (element form) or take over rendering (function form). |
|
|
256
253
|
|
|
257
|
-
- **State**: `PopoverTriggerState` is `{ open, pending, disabled }`; `pending` is true while the Root is pending: an open
|
|
254
|
+
- **State**: `PopoverTriggerState` is `{ open, pending, disabled }`; `pending` is true while the Root is pending: an open or a part's close, never a dismissal (a request still running when a dismissal superseded it keeps `pending` until that request settles).
|
|
258
255
|
- **Owned**: `type` (only on a `<button>`), `disabled`, `aria-disabled` (library mode, link or component `render`), `popoverTarget` (only on an invoker), `aria-expanded` (only on a Trigger that is no invoker), `onClick` (library mode), `data-open`, `data-pending`, `data-disabled`. Owned and never written: `popoverTargetAction`, `commandfor`, `command`. Not in the props type: these three, `popoverTarget` and `aria-expanded`.
|
|
259
256
|
|
|
260
|
-
A click on a `<button>` Trigger while open is a part's close; a second click during a pending open cancels it (the latest intent wins). A Trigger rendered as another element (library mode only) is light-dismissed before its click; that close is
|
|
257
|
+
A click on a `<button>` Trigger while open is a part's close; a second click during a pending open cancels it (the latest intent wins). A Trigger rendered as another element (library mode only) is light-dismissed before its click; that close is a fact, `onOpenChange(false)` with `"activate"` and the click. `aria-haspopup` and `aria-controls` pass through.
|
|
261
258
|
|
|
262
259
|
### `Popover.Popup`
|
|
263
260
|
|
|
@@ -265,7 +262,7 @@ A click on a `<button>` Trigger while open is a part's close; a second click dur
|
|
|
265
262
|
| - | - | - | - |
|
|
266
263
|
| `side` | `"top" \| "bottom" \| "left" \| "right" \| "inline-start" \| "inline-end" \| null` | `"bottom"` | Placement relative to the Trigger through inline `position-area`, with `position-try-fallbacks: flip-block, flip-inline, flip-block flip-inline` flipping it when it does not fit. `inline-start` / `inline-end` follow the popup's direction (`inline-end` is the right in LTR, the left in RTL); the other four are physical. `null` emits no inline placement and no `data-side` / `data-align`: your stylesheet owns placement. |
|
|
267
264
|
| `align` | `"start" \| "center" \| "end"` | `"center"` | 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. Ignored when `side` is `null`. |
|
|
268
|
-
| `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). Unmounting waits for the popover's CSS exit animation, or happens in the close commit when `transition` is set. Ignored in JS-free mode (always mounted). |
|
|
265
|
+
| `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). Unmounting waits for the popover's CSS exit animation, or happens in the close commit 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)). |
|
|
269
266
|
| `initialFocus` | `RefObject<HTMLElement \| null> \| string` | – | The element to focus on open: a ref, or a selector resolved inside the popup. The library writes `autofocus` on it right before `showPopover()` and lets the platform focus it. Default: the platform's choice for a `<dialog>` (the first focusable element, else the popup); with `render={<div />}` focus stays on the Trigger. 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). |
|
|
270
267
|
| `transition` | `ViewTransitionClass` | – | Library mode only. Forwarded to a `<ViewTransition>` around the popover element itself: animates the opening commit, content swaps, and every library-driven close (Trigger, Close, a controlled `open={false}`) in all engines. Dismissals are the browser's and animate with CSS. Default: no boundary. Keep it static; any value makes a Root inserted by a transition run the page cross-fade. |
|
|
271
268
|
| `className` | `string \| ((state: PopoverPopupState) => string \| undefined)` | – | A class name, or a function of the part's state. |
|
|
@@ -282,7 +279,8 @@ A click on a `<button>` Trigger while open is a part's close; a second click dur
|
|
|
282
279
|
|
|
283
280
|
| Prop | Type | Default | Description |
|
|
284
281
|
| - | - | - | - |
|
|
285
|
-
| `action` | `Action<[details: ActionDetails]>` | – | Runs in this button's own transition (`data-pending` on it), then closes the popover: in library mode through the Root (`openChangeAction(false)` awaited, view transition if set), in JS-free mode with `hidePopover()`. A rejection reaches the nearest Error Boundary above the button and leaves the popover open. A second click while it is pending is ignored, and the button is `aria-disabled="true"` meanwhile
|
|
282
|
+
| `action` | `Action<[details: ActionDetails]>` | – | Runs in this button's own transition (`data-pending` on it), then closes the popover: in library mode through the Root (`openChangeAction(false)` awaited, view transition if set), in JS-free mode with `hidePopover()`. A rejection reaches the nearest Error Boundary above the button and leaves the popover open. A second click while it is pending is ignored, and the button is `aria-disabled="true"` meanwhile, unless `whilePending` is `"run"`. Without `action` in JS-free mode the button is a native `command="hide-popover"` invoker. |
|
|
283
|
+
| `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 popover 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). |
|
|
286
284
|
| `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). |
|
|
287
285
|
| `className` | `string \| ((state: PopoverCloseState) => string \| undefined)` | – | A class name, or a function of the part's state. |
|
|
288
286
|
| `style` | `CSSProperties \| ((state: PopoverCloseState) => CSSProperties \| undefined)` | – | Inline style, or a function of the part's state. |
|
|
@@ -292,7 +290,7 @@ A click on a `<button>` Trigger while open is a part's close; a second click dur
|
|
|
292
290
|
- **State**: `PopoverCloseState` is `{ pending, disabled }`.
|
|
293
291
|
- **Owned**: `type` (on a `<button>` only), `disabled`, `aria-disabled`, `commandfor`, `command` (not on a link or other non-button host element), `onClick` (library mode, or with `action`), `data-pending`, `data-disabled`; a `render` element cannot re-enable a disabled Close.
|
|
294
292
|
|
|
295
|
-
In library mode the click is always intercepted, so every Close goes through the Root.
|
|
293
|
+
In library mode the click is always intercepted, so every Close goes through the Root. By default (`whilePending="ignore"`) a second click while the action is pending is ignored (and cancelled), and the button is `aria-disabled="true"` for as long as it shows `data-pending` (the action and the hide); never natively disabled, so it keeps focus. To hide at once and finish the work in the background, do not return the promise: `action={() => { void apply(); }}`. If the user dismisses the popover and opens it again while the action runs, the action's close is dropped: it belonged to the earlier open. Popovers have no return value.
|
|
296
294
|
|
|
297
295
|
### `Popover.Title`, `Popover.Description`
|
|
298
296
|
|
|
@@ -316,9 +314,9 @@ A dialog-role Popup with neither a Title nor an `aria-label` is a development wa
|
|
|
316
314
|
| `data-side`, `data-align` | Popup | While shown: where the browser placed the popup (`top` / `bottom` / `left` / `right`, after any flip; read from the computed `position-area`). Otherwise the requested placement. Absent with `side={null}`. |
|
|
317
315
|
| `aria-expanded` | Trigger, only when it is no [invoker](../concepts/browser-owned-state.md#popup-triggers): a link or other non-button element, or a disabled component `render` | Whether the popup is shown (library mode). A `<button>` Trigger has none: the browser exposes the state. |
|
|
318
316
|
| `data-open` | Trigger | Library mode: optimistic open state. JS-free mode: whether the popup is shown, written from its `toggle` event. |
|
|
319
|
-
| `data-pending` | Trigger | An open
|
|
317
|
+
| `data-pending` | Trigger | An open or a part-initiated 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. |
|
|
320
318
|
| `data-pending` | Close | Its `action` is in flight. |
|
|
321
|
-
| `aria-disabled` | Close | `"true"` while `data-pending
|
|
319
|
+
| `aria-disabled` | Close | `"true"` while `data-pending` with `whilePending="ignore"` (the default): a second click is ignored meanwhile. |
|
|
322
320
|
| `data-disabled` | Trigger, Close | The `disabled` prop (both modes). |
|
|
323
321
|
|
|
324
322
|
## Keyboard and ARIA
|
|
@@ -327,7 +325,7 @@ A dialog-role Popup with neither a Title nor an `aria-label` is a development wa
|
|
|
327
325
|
| - | - | - |
|
|
328
326
|
| Enter / Space on the Trigger | Toggles | the browser (JS-free) or the Trigger |
|
|
329
327
|
| Tab / Shift+Tab | Moves through the popup; the popup follows the Trigger in focus order. Tab past the end leaves, and the popover stays open | the browser |
|
|
330
|
-
| Escape | Closes the innermost open popover; focus returns to its Trigger; `
|
|
328
|
+
| Escape | Closes the innermost open popover; focus returns to its Trigger; `onOpenChange(false, { reason: "dismiss" })` | the browser (and the library for a nested popover) |
|
|
331
329
|
| Escape in a modal Dialog opened from the popup | Closes the Dialog only; a second Escape closes the popover | the browser |
|
|
332
330
|
|
|
333
331
|
- **Initial focus.** With the default `<dialog>`, opening runs the dialog focusing steps: the `initialFocus` target, else the first focusable element, else the popup itself (the APG non-modal dialog), in every engine. For a disclosure-style card that keeps focus on the Trigger, render a `<div>`: `render={<div />}` with `role="region"` and an `aria-label`.
|
|
@@ -339,7 +337,7 @@ A dialog-role Popup with neither a Title nor an `aria-label` is a development wa
|
|
|
339
337
|
|
|
340
338
|
Concept: [Transitions & ViewTransition](../concepts/transitions.md#transition-types)
|
|
341
339
|
|
|
342
|
-
Library mode: `fsui-popover` plus `fsui-popover-open` or `fsui-popover-close`; a controlled close carries none. JS-free mode starts no transitions.
|
|
340
|
+
Library mode: `fsui-popover` plus `fsui-popover-open` or `fsui-popover-close`; a controlled close carries none, and a dismissal starts no transition at all. JS-free mode starts no transitions.
|
|
343
341
|
|
|
344
342
|
### ViewTransition: an exit in every engine
|
|
345
343
|
|
|
@@ -352,22 +350,20 @@ With `transition`, the Popup renders `<ViewTransition>` around the popover eleme
|
|
|
352
350
|
```css
|
|
353
351
|
::view-transition-new(.pop-in) { animation: 160ms ease-out both pop-in; }
|
|
354
352
|
::view-transition-old(.pop-out) { animation: 120ms ease-in both pop-out; }
|
|
355
|
-
/* Keep the CSS exit above for dismissals, but not while a view transition runs. */
|
|
356
|
-
html:active-view-transition .popover { transition: none; }
|
|
357
353
|
@media (prefers-reduced-motion: reduce) {
|
|
358
354
|
::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
|
|
359
355
|
}
|
|
360
356
|
```
|
|
361
357
|
|
|
362
358
|
- Transition types: `fsui-popover` plus `fsui-popover-open` or `fsui-popover-close`. A controlled close carries none.
|
|
363
|
-
- Dismissals (Escape, a click outside) animate with the CSS exit only
|
|
359
|
+
- Dismissals (Escape, a click outside) are facts: their commit is urgent, so they start no view transition and animate with the CSS exit only. Keep it next to `transition`: the library turns the popup'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)).
|
|
364
360
|
- A plain open starts no document view transition: the content mounts under the already-mounted popover element. A Popup with `transition` that itself mounts inside a transition (a Root inserted by one, a nested Popup mounting with the outer content) runs the page cross-fade ([the transition prop](../concepts/transitions.md#transition-prop), issue [#35](https://github.com/uhyo/funstack-ui/issues/35)). The page receives no pointer events while a view transition runs: keep them short.
|
|
365
361
|
|
|
366
362
|
## Optimistic and pending
|
|
367
363
|
|
|
368
364
|
Concept: [Pending & optimistic state](../concepts/pending-and-optimistic.md)
|
|
369
365
|
|
|
370
|
-
Library mode: the Trigger shows the optimistic open state (`data-open`) and `data-pending` while an open
|
|
366
|
+
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: the popup, `data-open`, the committed `open` and the expanded state assistive technology hears all change at once, and nothing is pending. 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).
|
|
371
367
|
|
|
372
368
|
### Walkthrough (library mode)
|
|
373
369
|
|
|
@@ -411,13 +407,18 @@ function RowActions({ id, archive }: { id: string; archive: () => Promise<void>
|
|
|
411
407
|
// permissions are loaded, then it opens once, complete. A Close with an `action` runs it with its
|
|
412
408
|
// own pending state, then closes through the Root: the commit hides the popup, and
|
|
413
409
|
// `transition="pop"` animates that exit with a view transition, Firefox included. Escape and
|
|
414
|
-
// clicks outside are the browser's (reason "dismiss") and use
|
|
410
|
+
// clicks outside are the browser's, facts reported to `onOpenChange` (reason "dismiss"), and use
|
|
411
|
+
// the CSS fade.
|
|
415
412
|
export function PopoverActions() {
|
|
416
413
|
const [archived, setArchived] = useState<readonly string[]>([]);
|
|
417
414
|
const [last, setLast] = useState("(none yet)");
|
|
418
415
|
const record = (open: boolean, { reason }: PopoverOpenChangeDetails) => {
|
|
419
416
|
// The synchronous part of an action: this setState is a transition update.
|
|
420
|
-
setLast(`
|
|
417
|
+
setLast(`openChangeAction(${open}, "${reason}")`);
|
|
418
|
+
};
|
|
419
|
+
const recordFact = (open: boolean, { reason }: PopoverOpenChangeDetails) => {
|
|
420
|
+
// A fact handler: this setState is urgent.
|
|
421
|
+
setLast(`onOpenChange(${open}, "${reason}")`);
|
|
421
422
|
};
|
|
422
423
|
const rows = [
|
|
423
424
|
{ id: "report", name: "Quarterly report" },
|
|
@@ -429,11 +430,11 @@ export function PopoverActions() {
|
|
|
429
430
|
{rows.map(({ id, name }) => (
|
|
430
431
|
<li key={id} className="demo-row" data-archived={archived.includes(id) ? "" : undefined}>
|
|
431
432
|
<span>{name}</span>
|
|
432
|
-
<Popover.Root defaultOpen={false} openChangeAction={record}>
|
|
433
|
+
<Popover.Root defaultOpen={false} openChangeAction={record} onOpenChange={recordFact}>
|
|
433
434
|
<Popover.Trigger className="demo-button" aria-label={`Actions for ${name}`}>
|
|
434
435
|
{({ pending }) => (pending ? <span className="demo-spinner" aria-hidden /> : "⋯")}
|
|
435
436
|
</Popover.Trigger>
|
|
436
|
-
<Popover.Popup className="demo-popover
|
|
437
|
+
<Popover.Popup className="demo-popover" align="end" transition="pop">
|
|
437
438
|
<Popover.Title>{name}</Popover.Title>
|
|
438
439
|
<RowActions
|
|
439
440
|
id={id}
|
|
@@ -454,7 +455,7 @@ export function PopoverActions() {
|
|
|
454
455
|
</button>
|
|
455
456
|
</div>
|
|
456
457
|
<output className="demo-readout">
|
|
457
|
-
last
|
|
458
|
+
last call: <code>{last}</code>
|
|
458
459
|
</output>
|
|
459
460
|
</>
|
|
460
461
|
);
|
|
@@ -467,11 +468,75 @@ export function PopoverActions() {
|
|
|
467
468
|
2. The commit that sets committed `open` renders the Popup's children; `RowActions` suspends, so React holds the commit. The popup stays hidden; the Trigger keeps spinning.
|
|
468
469
|
3. The data arrives: the content commits and `showPopover({ source: trigger })` runs in the same commit, so the popup is anchored below the Trigger and the platform focuses fully rendered content. With `transition="pop"` it animates in.
|
|
469
470
|
4. Click Archive: the button shows its own pending label while its action runs; then the Close dispatches `openChangeAction(false, { reason: "activate" })` and the commit that ends it hides the popup inside a view transition: the exit animates in every engine.
|
|
470
|
-
5. Press Escape or click outside instead: the browser hides the popover at once (CSS fade), and the Root
|
|
471
|
+
5. Press Escape or click outside instead: the browser hides the popover at once (CSS fade), and the Root calls `onOpenChange(false, { reason: "dismiss" })` in the same event. Nothing is pending, and `openChangeAction` is not called.
|
|
471
472
|
|
|
472
473
|
> **Refusing a close**
|
|
473
474
|
>
|
|
474
|
-
> A controlled parent that keeps `open` after a **part-initiated** close vetoes it: nothing was hidden, the Trigger's `data-open` snaps back. After a **dismissal** the popover is already hidden; a parent that keeps `open` gets it re-opened once
|
|
475
|
+
> A controlled parent that keeps `open` after a **part-initiated** close vetoes it: nothing was hidden, the Trigger's `data-open` snaps back. After a **dismissal** the popover is already hidden; a parent that keeps `open` gets it re-opened at once, which the user sees as a blink. The re-open never moves focus: it stays where the dismissal put it (the Trigger after Escape, the element clicked outside), for the default `<dialog>` popup as for a `<div>` one. Adopt `false` in `onOpenChange`, directly (`onOpenChange={setOpen}`), not in `startTransition` and not after an `await`.
|
|
476
|
+
|
|
477
|
+
### A slow `openChangeAction`
|
|
478
|
+
|
|
479
|
+
Here every `openChangeAction` call takes 2 seconds, like a server call, and `onOpenChange` logs the dismissals. The Trigger is exposed as expanded exactly while the popup is shown:
|
|
480
|
+
|
|
481
|
+
```tsx title="PopoverSlowOpen.tsx"
|
|
482
|
+
"use client";
|
|
483
|
+
import { startTransition, useState } from "react";
|
|
484
|
+
import { Popover } from "@funstack/ui/popover";
|
|
485
|
+
import type { PopoverOpenChangeDetails } from "@funstack/ui/popover";
|
|
486
|
+
import { sleep } from "./fake-api.js";
|
|
487
|
+
|
|
488
|
+
// A slow `openChangeAction`: a pretend server call of 2 seconds for every request (an open, or a
|
|
489
|
+
// close with the Trigger or the Close). Opening: the Trigger gets data-open and data-pending at
|
|
490
|
+
// once, the popup is shown when the action settles. Closing with the Trigger or the Close: the
|
|
491
|
+
// popup stays shown until the action settles. Escape and a click outside are the browser's, a
|
|
492
|
+
// fact: the popup hides at once, nothing is pending and the action is not called; `onOpenChange`
|
|
493
|
+
// reports it, synchronously. The browser exposes the Trigger as expanded exactly while the popup
|
|
494
|
+
// is shown. The readout is plain text, not a live region.
|
|
495
|
+
export function PopoverSlowOpen() {
|
|
496
|
+
const [log, setLog] = useState("(none yet)");
|
|
497
|
+
const slow = async (open: boolean, { reason }: PopoverOpenChangeDetails) => {
|
|
498
|
+
const call = `openChangeAction(${open}, "${reason}")`;
|
|
499
|
+
setLog(`${call}: running…`);
|
|
500
|
+
await sleep(2000);
|
|
501
|
+
// After an await: wrap the update in startTransition (React limitation).
|
|
502
|
+
startTransition(() => setLog(`${call}: settled`));
|
|
503
|
+
};
|
|
504
|
+
// A fact: called in the browser's event, not awaited. A plain setState here is urgent.
|
|
505
|
+
const dismissed = (open: boolean, { reason }: PopoverOpenChangeDetails) => {
|
|
506
|
+
setLog(`onOpenChange(${open}, "${reason}")`);
|
|
507
|
+
};
|
|
508
|
+
return (
|
|
509
|
+
<div className="demo-stack">
|
|
510
|
+
<Popover.Root openChangeAction={slow} onOpenChange={dismissed}>
|
|
511
|
+
<Popover.Trigger className="demo-button">
|
|
512
|
+
{({ open, pending }) => (
|
|
513
|
+
<>
|
|
514
|
+
Filters{pending && <span className="demo-spinner" aria-hidden />}
|
|
515
|
+
<span aria-hidden>{open ? " ▴" : " ▾"}</span>
|
|
516
|
+
</>
|
|
517
|
+
)}
|
|
518
|
+
</Popover.Trigger>
|
|
519
|
+
<Popover.Popup className="demo-popover">
|
|
520
|
+
<Popover.Title>Filters</Popover.Title>
|
|
521
|
+
<p>Saved filters for this list.</p>
|
|
522
|
+
<Popover.Close className="demo-button">Close</Popover.Close>
|
|
523
|
+
</Popover.Popup>
|
|
524
|
+
</Popover.Root>
|
|
525
|
+
<p className="demo-readout">
|
|
526
|
+
Last: <code>{log}</code>
|
|
527
|
+
</p>
|
|
528
|
+
</div>
|
|
529
|
+
);
|
|
530
|
+
}
|
|
531
|
+
```
|
|
532
|
+
|
|
533
|
+
`popover.css`: the same file as above.
|
|
534
|
+
|
|
535
|
+
- Open: the Trigger gets `data-open` and `data-pending` at once (here a spinner and ▴) and stays collapsed; the popup is shown, and the Trigger expanded, when the action settles.
|
|
536
|
+
- Close with the Trigger or Close: `data-open` goes at once, the popup stays shown and the Trigger expanded until the action settles.
|
|
537
|
+
- Escape or a click outside: a fact. The popup hides, `data-open` goes and the Trigger is collapsed at once; nothing is pending and the slow action is not called; `onOpenChange` is.
|
|
538
|
+
|
|
539
|
+
The readout under the example is plain text, not a live region, so it does not interrupt a screen reader.
|
|
475
540
|
|
|
476
541
|
## Suspense
|
|
477
542
|
|
|
@@ -483,7 +548,7 @@ Content that suspends holds the open: the popup stays hidden with the Trigger pe
|
|
|
483
548
|
|
|
484
549
|
Concept: [Browser-owned state](../concepts/browser-owned-state.md)
|
|
485
550
|
|
|
486
|
-
JS-free mode: the browser owns everything through the Trigger's `popovertarget` and the Close's Invoker Command. Library mode: opening and a close asked for by a part are
|
|
551
|
+
JS-free mode: the browser owns everything through the Trigger's `popovertarget` and the Close's Invoker Command. Library mode: opening and a close asked for by a part are requests (`openChangeAction`); a dismissal (Escape, a click outside, another popover opening) is the browser's, a fact: the popover closes at once and `onOpenChange(false)` is called with `reason: "dismiss"`. Dismissals animate with CSS only.
|
|
487
552
|
|
|
488
553
|
## Before hydration
|
|
489
554
|
|
|
@@ -539,7 +604,7 @@ The Popup emits no `data-open`: `:popover-open` is exact. Enter and exit animate
|
|
|
539
604
|
```tsx
|
|
540
605
|
const [open, setOpen] = useState(false);
|
|
541
606
|
|
|
542
|
-
<Popover.Root open={open} openChangeAction={
|
|
607
|
+
<Popover.Root open={open} openChangeAction={setOpen} onOpenChange={setOpen}>
|
|
543
608
|
<Popover.Trigger>Rename</Popover.Trigger>
|
|
544
609
|
<Popover.Popup initialFocus="[name=title]">
|
|
545
610
|
<Popover.Title>Rename</Popover.Title>
|
|
@@ -560,7 +625,7 @@ const [open, setOpen] = useState(false);
|
|
|
560
625
|
### Controlled, opened without a Trigger
|
|
561
626
|
|
|
562
627
|
```tsx
|
|
563
|
-
<Popover.Root open={open} openChangeAction={
|
|
628
|
+
<Popover.Root open={open} openChangeAction={setOpen} onOpenChange={setOpen}>
|
|
564
629
|
<Popover.Popup side={null} className="popover centered">…</Popover.Popup>
|
|
565
630
|
</Popover.Root>
|
|
566
631
|
```
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Progress
|
|
2
2
|
|
|
3
|
-
A progress bar (WAI-ARIA `progressbar`)
|
|
3
|
+
A progress bar (WAI-ARIA `progressbar`). It is an **output-only** component: nothing is pressed or typed, so there is no action, no pending state and no optimistic state. A Progress is the display of _someone else's_ action. It has no behaviour JavaScript: `Progress.Root` has no `"use client"`, so a Server Component renders it on the server (the small client parts still ship; see [Server Components](#server-components)).
|
|
4
4
|
|
|
5
5
|
```tsx title="ProgressUpload.tsx"
|
|
6
6
|
"use client";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Slider
|
|
2
2
|
|
|
3
|
-
A slider (WAI-ARIA Slider and Slider (Multi-Thumb) patterns)
|
|
3
|
+
A slider (WAI-ARIA Slider and Slider (Multi-Thumb) patterns): a control for a continuous value. Each thumb is a styleable element containing a visually hidden native `<input type="range">`, so the role, the value and bounds, every key (RTL mirroring included), labels, forms and `disabled` are the platform's. The library adds the styleable thumb and track, pointer dragging, several thumbs that cannot cross, and the asynchronous half: a drag produces many **steps** and one **commit**.
|
|
4
4
|
|
|
5
5
|
```tsx title="SliderVolume.tsx"
|
|
6
6
|
"use client";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Toast
|
|
2
2
|
|
|
3
|
-
Toasts report on something that already happened or is happening elsewhere. The input is a function, `toast()`, callable from anywhere: an action body, a store, an effect. The output is yours: a `Toast.Viewport` rendered once maps the queue to parts. The queue is
|
|
3
|
+
Toasts report on something that already happened or is happening elsewhere. The input is a function, `toast()`, callable from anywhere: an action body, a store, an effect. The output is yours: a `Toast.Viewport` rendered once maps the queue to parts. The queue is **urgent by design**: React holds every transition while an async action is pending, so a toast pushed as a transition would appear only after the action it reports on. Toast spends its [Async React](../why.md#async-react) budget elsewhere: a toast that follows a promise, an Undo that is an ordinary action prop with `data-pending`, an `onClose` handler that knows whether the Undo window was used, and a Suspense guard so a toast whose content suspends does not blank the page.
|
|
4
4
|
|
|
5
5
|
```tsx title="ToastArchive.tsx"
|
|
6
6
|
"use client";
|
|
@@ -255,13 +255,13 @@ export function ToastNotifications() {
|
|
|
255
255
|
- **No Provider.** `toast` is bound to a module-level default manager; a Viewport without `manager` renders it. A second Viewport on the same manager warns and renders nothing. `createToastManager()` makes an isolated queue (a second React root, a test) for `<Toast.Viewport manager={m}>`.
|
|
256
256
|
- **No list element, no Portal part.** Toasts are focusable `dialog`s (`alertdialog` for `priority: "high"`) named by their Title and described by their Description. The region is wherever the Viewport is rendered; its only move (into a modal dialog) is the library's. On the client it sits inside two `display: contents` wrappers: an anchor where the Viewport is rendered, and the element the library moves.
|
|
257
257
|
- The Title is a `div`, not a heading: transient notifications stay out of heading navigation.
|
|
258
|
-
- Calls made before the Viewport mounts are buffered and shown when it does. A Viewport that unmounts leaves its toasts with the manager for the next one (timers stop; no `
|
|
258
|
+
- Calls made before the Viewport mounts are buffered and shown when it does. A Viewport that unmounts leaves its toasts with the manager for the next one (timers stop; no `onClose` is called).
|
|
259
259
|
|
|
260
260
|
## How it works
|
|
261
261
|
|
|
262
262
|
### The urgent queue
|
|
263
263
|
|
|
264
|
-
Every queue change (add, update, dismiss, the drop after an exit animation) is a normal, urgent update. `toast()` dispatches from a microtask, so a call inside a `startTransition` scope, the sync prefix of an action included, escapes the scope and shows at once; calls keep their order.
|
|
264
|
+
Every queue change (add, update, dismiss, the drop after an exit animation) is a normal, urgent update. `toast()` dispatches from a microtask, so a call inside a `startTransition` scope, the sync prefix of an action included, escapes the scope and shows at once; calls keep their order. What a toast _drives_ is a transition as usual: its Action's action. The report that it left, `onClose`, is a handler: a fact, called synchronously and not awaited.
|
|
265
265
|
|
|
266
266
|
```tsx title="ToastUrgent.tsx"
|
|
267
267
|
"use client";
|
|
@@ -319,15 +319,15 @@ export function ToastUrgent() {
|
|
|
319
319
|
| rejects, no `error` | dismissed | rejects with the reason (the action prop's Error Boundary gets it) |
|
|
320
320
|
| a `success` / `error` function throws | dismissed (never left pending) | rejects with what the function threw |
|
|
321
321
|
|
|
322
|
-
### Undo and
|
|
322
|
+
### Undo and onClose
|
|
323
323
|
|
|
324
|
-
`Toast.Action` is a [pure trigger](../concepts/pending-and-optimistic.md#pure-trigger), like `Menu.Item`. While its action runs the Action and the Root carry `data-pending` and the toast's timer is paused; when it resolves the toast closes with `reason: "activate"` (unless `closeOnSettle={false}`). A rejection keeps the toast and reaches the nearest Error Boundary **above the Viewport**: put one around the list.
|
|
324
|
+
`Toast.Action` is a [pure trigger](../concepts/pending-and-optimistic.md#pure-trigger), like `Menu.Item`. While its action runs the Action and the Root carry `data-pending` and the toast's timer is paused; when it resolves the toast closes with `reason: "activate"` (unless `closeOnSettle={false}`). A second click meanwhile is ignored and the Action is `aria-disabled="true"`: one Undo, one Retry. With `closeOnSettle={false}` the toast stays and the Action is your own trigger, so every click runs (add `whilePending="ignore"` for a Retry that must not overlap). A rejection keeps the toast and reaches the nearest Error Boundary **above the Viewport**: put one around the list. Not when the Action is gone or hidden by the time it rejects: the toast was closed while the action ran, or a `toast.update` gave it content that is still suspending. The error then goes to the global `reportError` (a window `error` event) instead.
|
|
325
325
|
|
|
326
326
|
> **A caught error closes the toast**
|
|
327
327
|
>
|
|
328
|
-
> A `catch` inside the action resolves it, and a resolved action closes the toast, so a "Could not undo" written with `toast.update` in the `catch` is never seen. Rethrow after the update (the toast stays; the boundary above the Viewport gets the error), or use `closeOnSettle={false}` and `toast.dismiss(details.id)` on success.
|
|
328
|
+
> A `catch` inside the action resolves it, and a resolved action closes the toast, so a "Could not undo" written with `toast.update` in the `catch` is never seen. Rethrow after the update (the toast stays; the boundary above the Viewport gets the error), or use `closeOnSettle={false}`, `whilePending="ignore"` and `toast.dismiss(details.id)` on success.
|
|
329
329
|
|
|
330
|
-
A toast's `
|
|
330
|
+
A toast's `onClose` is called once, synchronously, in the moment the toast is closed (its exit animation, if any, has not run yet): `"activate"` (its Action settled), `"dismiss"` (Close, Escape, `toast.dismiss()`, a promise toast with no message for its outcome) or `"timeout"`. That is the "do later, unless undone" pattern:
|
|
331
331
|
|
|
332
332
|
```tsx title="ToastUndoWindow.tsx"
|
|
333
333
|
"use client";
|
|
@@ -338,13 +338,16 @@ import { sleep } from "./fake-api.js";
|
|
|
338
338
|
const initial = ["Groceries", "Dentist", "Call Ada"];
|
|
339
339
|
|
|
340
340
|
// "Do later, unless undone": the item leaves the list at once (local state), and the toast is the
|
|
341
|
-
// grace period. `
|
|
341
|
+
// grace period. `onClose` is called when the toast leaves, with the reason: "activate" when Undo
|
|
342
342
|
// was used, otherwise ("timeout", or "dismiss" through Close, Escape or toast.dismiss()) the
|
|
343
|
-
// deletion is committed.
|
|
343
|
+
// deletion is committed. It is a handler, not an action: not awaited, so the slow delete holds
|
|
344
|
+
// no other transition, and a rejection would go to reportError. Hover or focus the toast to pause
|
|
345
|
+
// its 6 second timer.
|
|
344
346
|
export function ToastUndoWindow() {
|
|
345
347
|
const [items, setItems] = useState(initial);
|
|
346
348
|
const [log, setLog] = useState<readonly string[]>([]);
|
|
347
|
-
|
|
349
|
+
// Called from onClose, a handler: a plain setState there is an urgent update, even after an await.
|
|
350
|
+
const note = (line: string) => setLog((l) => [line, ...l].slice(0, 3));
|
|
348
351
|
|
|
349
352
|
const remove = (name: string) => {
|
|
350
353
|
setItems((list) => list.filter((item) => item !== name));
|
|
@@ -355,7 +358,7 @@ export function ToastUndoWindow() {
|
|
|
355
358
|
label: "Undo",
|
|
356
359
|
action: () => startTransition(() => setItems((list) => [...list, name])),
|
|
357
360
|
},
|
|
358
|
-
|
|
361
|
+
onClose: async ({ reason }) => {
|
|
359
362
|
if (reason === "activate") {
|
|
360
363
|
note(`Restored ${name}`);
|
|
361
364
|
return;
|
|
@@ -395,6 +398,25 @@ export function ToastUndoWindow() {
|
|
|
395
398
|
}
|
|
396
399
|
```
|
|
397
400
|
|
|
401
|
+
`onClose` is a [handler, not an action](../concepts/action-props.md#on-handler): it is not awaited, so a slow `deleteForReal` holds no other transition in the app, and it may be a Server Function. A rejection, or a throw, goes to `reportError`; it never reaches an Error Boundary (the toast has already left). To show the user a failure, catch it yourself:
|
|
402
|
+
|
|
403
|
+
```tsx
|
|
404
|
+
toast({
|
|
405
|
+
title: "Message deleted",
|
|
406
|
+
duration: 8000,
|
|
407
|
+
action: { label: "Undo", action: () => restoreToList(id) },
|
|
408
|
+
onClose: async ({ reason }) => {
|
|
409
|
+
if (reason === "activate") return;
|
|
410
|
+
try {
|
|
411
|
+
await deleteForReal(id);
|
|
412
|
+
} catch {
|
|
413
|
+
restoreToList(id);
|
|
414
|
+
toast({ title: "Could not delete the message", priority: "high" });
|
|
415
|
+
}
|
|
416
|
+
},
|
|
417
|
+
});
|
|
418
|
+
```
|
|
419
|
+
|
|
398
420
|
### Timers
|
|
399
421
|
|
|
400
422
|
A toast's timer starts once it is visible (within `limit`), its content has rendered and it is not pending, and resumes with the remaining time after a pause. Timers pause while the pointer is over the region, focus is inside it, the document is hidden or the window is blurred (`data-paused`), and per toast while it is pending. Elapsing closes the toast with `reason: "timeout"`. Pausing helps sighted users; the persistent default for action toasts and the hotkey are what give screen-reader users time to reach an Undo.
|
|
@@ -424,7 +446,7 @@ On the server every method is a no-op with a development warning, and nothing is
|
|
|
424
446
|
| `priority` | `"normal" \| "high"` | `"normal"` | `"high"`: announced with `ariaNotify` priority `"high"`, Root role `alertdialog`. |
|
|
425
447
|
| `duration` | `number \| null` | `Viewport duration; null with an action` | Milliseconds until the toast closes with `reason: "timeout"`; `null` never. A toast with an `action` is persistent unless you set it; if you do, keep the action reachable elsewhere too (WCAG 2.2.1). |
|
|
426
448
|
| `action` | `{ label: ReactNode; action: Action<[ToastActionDetails]> }` | – | What `Toast.Action` renders and runs. `details.id` is the toast's id, so an inline action can update or dismiss its own toast. |
|
|
427
|
-
| `
|
|
449
|
+
| `onClose` | `UrgentHandler<ToastCloseDetails>` | – | A [handler](../concepts/action-props.md#on-handler), not an action: called once when the toast leaves, synchronously, outside any transition, and not awaited; `details.reason` is `"activate"`, `"dismiss"` or `"timeout"`. May return a promise (a Server Function); a rejection or a throw goes to `reportError`. Not called when the Viewport unmounts. |
|
|
428
450
|
| `announce` | `(toast: ToastItem) => string \| null` | – | The text `ariaNotify` speaks for this toast; `null` for nothing. Wins over the Viewport's `announce`. |
|
|
429
451
|
| `data` | `unknown` | – | Anything your Viewport children want to render. |
|
|
430
452
|
|
|
@@ -470,6 +492,7 @@ On the server every method is a no-op with a development warning, and nothing is
|
|
|
470
492
|
| - | - | - | - |
|
|
471
493
|
| `action` | `Action<[ToastActionDetails]>` | `toast.action.action` | Runs in this part's transition. The part renders nothing when neither it nor the toast has an action. |
|
|
472
494
|
| `closeOnSettle` | `boolean` | `true` | Close the toast (`reason: "activate"`) when the action resolves. |
|
|
495
|
+
| `whilePending` | `"run" \| "ignore"` | `"ignore", or "run" with closeOnSettle={false}` | What a click does while this part's action is pending. `"ignore"`: nothing (the click is cancelled, `aria-disabled="true"` meanwhile). `"run"`: the action runs again; the Action and the Root stay `data-pending` and the timer paused until every run has settled; with `closeOnSettle` the toast then closes once, if the latest run resolved (a rejection keeps it, in both modes). Set it on the part: `toast({ action })` has no such option. See [A second click while pending](../concepts/pending-and-optimistic.md#second-click). |
|
|
473
496
|
| `className` | `string \| ((state: ToastActionState) => string \| undefined)` | – | A class name, or a function of the part's state. |
|
|
474
497
|
| `style` | `CSSProperties \| ((state: ToastActionState) => CSSProperties \| undefined)` | – | Inline style, or a function of the part's state. |
|
|
475
498
|
| `children` | `ReactNode \| ((state: ToastActionState) => ReactNode)` | – | Default: `toast.action.label`. |
|
|
@@ -478,7 +501,7 @@ On the server every method is a no-op with a development warning, and nothing is
|
|
|
478
501
|
- **State**: `ToastActionState` is `{ pending, toast }`.
|
|
479
502
|
- **Owned**: `type` (on a `<button>` only), `onClick`, `aria-disabled`, `data-pending`.
|
|
480
503
|
|
|
481
|
-
|
|
504
|
+
By default (`whilePending="ignore"` unless `closeOnSettle={false}`) a second click while the action is pending is ignored (and cancelled): one Undo, one Retry. The Action is then `aria-disabled="true"` while it shows `data-pending`; it is never natively disabled, so it keeps focus.
|
|
482
505
|
|
|
483
506
|
### `Toast.Close`
|
|
484
507
|
|
|
@@ -499,7 +522,7 @@ Closes the toast with `reason: "dismiss"`, like Escape. Give it a name (text or
|
|
|
499
522
|
| Hook | On | Meaning |
|
|
500
523
|
| - | - | - |
|
|
501
524
|
| `data-pending` | Root, Action | The toast's promise is unsettled, or its Action's action runs (not set while its content merely suspends) |
|
|
502
|
-
| `aria-disabled` | Action | `"true"` while `data-pending
|
|
525
|
+
| `aria-disabled` | Action | `"true"` while `data-pending` with `whilePending="ignore"` (the default unless `closeOnSettle={false}`): a second click is ignored |
|
|
503
526
|
| `data-ending` | Root | Closed, kept (and `inert`) until the animations the ending state started finish |
|
|
504
527
|
| `data-type` | Root | The toast's `type` |
|
|
505
528
|
| `data-paused` | Viewport | A viewport-wide timer pause holds; pause a progress bar with it |
|
|
@@ -147,7 +147,8 @@ export function ToolbarEditor() {
|
|
|
147
147
|
background: color-mix(in srgb, var(--color-text) 8%, transparent);
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
-
/* [data-disabled], not [aria-disabled]: a pending Button
|
|
150
|
+
/* [data-disabled], not [aria-disabled]: a pending Button with whilePending="ignore" is
|
|
151
|
+
aria-disabled too. */
|
|
151
152
|
.demo-toolbar-button[data-disabled] {
|
|
152
153
|
opacity: 0.5;
|
|
153
154
|
cursor: not-allowed;
|
|
@@ -367,7 +367,7 @@ Concept: [Browser-owned state](../concepts/browser-owned-state.md)
|
|
|
367
367
|
|
|
368
368
|
All of it: a tooltip's visibility is not application state, so the browser owns it.
|
|
369
369
|
|
|
370
|
-
There is no `open` prop, no
|
|
370
|
+
There is no `open` prop, no callback and no `data-open`: every open and close is the browser's or a timer the user drives, so none of it is a request (an action). The popup is a popover in the top layer, opened and closed by the browser (or by the library's listeners calling `showPopover` / `hidePopover`), never through React state. Style it with `:popover-open`, and the trigger of an open tooltip with `:has(+ :popover-open)`. Tooltip is therefore the one component with no transitions, no `data-pending` and no `transition` prop; animate it in CSS:
|
|
371
371
|
|
|
372
372
|
```css
|
|
373
373
|
.tip {
|