@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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dialog-trigger.mjs","names":[],"sources":["../../src/dialog/dialog-trigger.tsx"],"sourcesContent":["\"use client\";\nimport { useCallback, useEffect, useRef } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, MouseEvent, ReactNode } from \"react\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { registerTrigger } from \"../internal/trigger-ref.js\";\nimport { useElementCheck } from \"../internal/use-element-check.js\";\nimport { disabledButton, rendersButton, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { useDialogContext } from \"./dialog-context.js\";\n\n/**\n * State of `Dialog.Trigger`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface DialogTriggerState {\n /** Optimistic open state (library mode); `false` in JS-free mode. */\n readonly open: boolean;\n /**\n * The Root's transition is pending: an open in flight, a close a part asked for in flight\n * (`openChangeAction(false)` awaited while the dialog is still open)
|
|
1
|
+
{"version":3,"file":"dialog-trigger.mjs","names":[],"sources":["../../src/dialog/dialog-trigger.tsx"],"sourcesContent":["\"use client\";\nimport { useCallback, useEffect, useRef } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, MouseEvent, ReactNode } from \"react\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { registerTrigger } from \"../internal/trigger-ref.js\";\nimport { useElementCheck } from \"../internal/use-element-check.js\";\nimport { disabledButton, rendersButton, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { useDialogContext } from \"./dialog-context.js\";\n\n/**\n * State of `Dialog.Trigger`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface DialogTriggerState {\n /** Optimistic open state (library mode); `false` in JS-free mode. */\n readonly open: boolean;\n /**\n * The Root's transition is pending: an open in flight, or a close a part asked for in flight\n * (`openChangeAction(false)` awaited while the dialog is still open). A dismissal is a fact and\n * is never pending.\n */\n readonly pending: boolean;\n /** The `disabled` prop. */\n readonly disabled: boolean;\n}\n\n/**\n * Props of `Dialog.Trigger`.\n *\n * @see https://ui.funstack.work/components/dialog\n */\nexport interface DialogTriggerProps extends Omit<\n ComponentPropsWithRef<\"button\">,\n \"onClick\" | \"className\" | \"style\" | \"children\"\n> {\n /**\n * Never dispatches. Native `disabled` on a `<button>` (no longer an invoker); with a link or\n * component `render` where the Trigger handles the click (library mode, or a non-modal\n * dialog), `aria-disabled=\"true\"` instead: the element stays focusable.\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, DialogTriggerState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, DialogTriggerState>;\n /** Rendered from optimistic state; must not suspend. */\n children?: StateValue<ReactNode, DialogTriggerState>;\n /** Should render a `<button>`; another element works only in library mode (click handler). */\n render?: RenderProp<ComponentPropsWithRef<\"button\">, DialogTriggerState>;\n}\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * The opener: `<button type=\"button\" commandfor command=\"show-modal\">`. In JS-free mode the\n * browser runs the command. In library mode the click is cancelled (so the command does not run)\n * and dispatched through the Root's transition; the button shows optimistic `data-open` and\n * `data-pending` until the dialog has opened. Non-modal dialogs have no command and always use a\n * click handler (`show()`).\n *\n * Owned keys (conventions 1.2): `type` (on a `<button>` only), `disabled`, `aria-disabled` (a\n * link or component `render` with the click handler installed), `commandfor`, `command`,\n * `onClick`, `onPointerDown` (non-modal JS-free mode), `data-open`, `data-pending`,\n * `data-disabled`.\n *\n * @see https://ui.funstack.work/components/dialog\n */\nexport function DialogTrigger({\n disabled = false,\n className,\n style,\n children,\n render,\n ...rest\n}: DialogTriggerProps) {\n const ctx = useDialogContext(\"Dialog.Trigger\");\n const isLibrary = ctx.mode === \"library\";\n const { modal, ids, triggerRef, popupRef } = ctx;\n\n const state: DialogTriggerState = {\n open: ctx.optimistic,\n // Every Root dispatch is an open or a part-initiated close, and both belong to the Trigger\n // (design 4.2). Not `optimistic !== committed`: a request superseded by a fact still runs\n // and is pending with both `false`.\n pending: ctx.pending,\n disabled,\n };\n\n const checkElement = useElementCheck(\n isDev &&\n ((element) =>\n !isLibrary && modal && element.tagName !== \"BUTTON\"\n ? `Dialog.Trigger: rendered a <${element.tagName.toLowerCase()}> in JS-free mode. Only a ` +\n '<button> runs `command=\"show-modal\"`; this trigger will not open the dialog. Render ' +\n \"a <button>, or put the Dialog in library mode (`defaultOpen={false}`).\"\n : null),\n );\n const libraryRef = useCallback(\n (element: HTMLElement) => {\n checkElement?.(element);\n return registerTrigger(triggerRef, element, \"Dialog.Trigger\");\n },\n [checkElement, triggerRef],\n );\n\n // A Trigger without a Popup opens nothing (design 14, dev warnings).\n useEffect(() => {\n if (!isDev) return;\n if (document.getElementById(ids.popup) === null) {\n console.error(\n \"Dialog.Trigger: no Dialog.Popup is rendered for this Dialog.Root; the trigger opens nothing.\",\n );\n }\n }, [ids.popup]);\n\n // Library mode (both modal and non-modal) and non-modal JS-free mode need a click handler;\n // modal JS-free mode is the browser's command.\n const installClick = isLibrary || !modal;\n // The modal JS-free command needs native `disabled` to stop it.\n const disabledProps = disabledButton(render, disabled, { handlesClick: installClick });\n // Only on a button (or a component, assumed to render one): another element is no invoker.\n const invoker = modal && disabledProps.invoker && rendersButton(render);\n // Non-modal JS-free mode: whether the dialog was open when the press began. A press on the\n // Trigger of an open `lightDismiss` dialog is a dismissal (the JS listeners or native\n // `closedby=\"any\"` close it before the click), so that click must not `show()` it again.\n // Pointer clicks only (`detail > 0`): a keyboard click has no press, and a press that never\n // became a click must not swallow a later one.\n const pressedOpen = useRef(false);\n const installPress = !isLibrary && !modal;\n const onPointerDown = () => {\n pressedOpen.current = popupRef.current?.open ?? false;\n };\n const onClick = (event: MouseEvent<HTMLElement>) => {\n if (isLibrary) {\n // Cancelling the click cancels the command (it runs as the button's activation\n // behaviour, only if the click was not cancelled).\n event.preventDefault();\n if (disabled) return;\n ctx.requestOpen(event.nativeEvent, \"activate\");\n return;\n }\n if (disabled) {\n // A disabled link must not navigate either.\n event.preventDefault();\n return;\n }\n const wasOpen = event.detail > 0 && pressedOpen.current;\n pressedOpen.current = false;\n const dialog = popupRef.current;\n if (dialog !== null && !dialog.open && !wasOpen && dialog.isConnected) dialog.show();\n };\n\n const libraryProps: ComponentPropsWithRef<\"button\"> & DataAttributes = {\n // `type` only applies to a <button>; on any other element the key is not owned.\n ...(rendersButton(render) && { type: \"button\" as const }),\n // Owned: a render element must not re-enable a disabled Trigger (in JS-free mode the\n // browser would run its command).\n ...disabledProps.props,\n commandfor: invoker ? ids.popup : undefined,\n command: invoker ? \"show-modal\" : undefined,\n // Only owned when installed, so a render element keeps its own `onClick` in modal JS-free\n // mode (Accordion's rule).\n ...(installClick && { onClick }),\n ...(installPress && { onPointerDown }),\n \"data-open\": dataAttr(state.open),\n \"data-pending\": dataAttr(state.pending),\n // Every mode: the styling hook agrees with the rendered `disabled` / `aria-disabled`\n // (conventions 1.2).\n \"data-disabled\": dataAttr(disabled),\n };\n\n return useRender<ComponentPropsWithRef<\"button\">, DialogTriggerState>({\n defaultElement: \"button\",\n render,\n state,\n className,\n style,\n children,\n props: rest,\n libraryProps,\n ref: libraryRef,\n });\n}\n\nDialogTrigger.displayName = \"DialogTrigger\";\n"],"mappings":";;;;;;;;;AAuDA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;;;;;;;;;;;AAgBvC,SAAgB,cAAc,EAC5B,WAAW,OACX,WACA,OACA,UACA,QACA,GAAG,QACkB;CACrB,MAAM,MAAM,iBAAiB,gBAAgB;CAC7C,MAAM,YAAY,IAAI,SAAS;CAC/B,MAAM,EAAE,OAAO,KAAK,YAAY,aAAa;CAE7C,MAAM,QAA4B;EAChC,MAAM,IAAI;EAIV,SAAS,IAAI;EACb;CACF;CAEA,MAAM,eAAe,gBACnB,WACI,YACA,CAAC,aAAa,SAAS,QAAQ,YAAY,WACvC,+BAA+B,QAAQ,QAAQ,YAAY,EAAE,4LAG7D,KACV;CACA,MAAM,aAAa,aAChB,YAAyB;EACxB,eAAe,OAAO;EACtB,OAAO,gBAAgB,YAAY,SAAS,gBAAgB;CAC9D,GACA,CAAC,cAAc,UAAU,CAC3B;CAGA,gBAAgB;EACd,IAAI,CAAC,OAAO;EACZ,IAAI,SAAS,eAAe,IAAI,KAAK,MAAM,MACzC,QAAQ,MACN,8FACF;CAEJ,GAAG,CAAC,IAAI,KAAK,CAAC;CAId,MAAM,eAAe,aAAa,CAAC;CAEnC,MAAM,gBAAgB,eAAe,QAAQ,UAAU,EAAE,cAAc,aAAa,CAAC;CAErF,MAAM,UAAU,SAAS,cAAc,WAAW,cAAc,MAAM;CAMtE,MAAM,cAAc,OAAO,KAAK;CAChC,MAAM,eAAe,CAAC,aAAa,CAAC;CACpC,MAAM,sBAAsB;EAC1B,YAAY,UAAU,SAAS,SAAS,QAAQ;CAClD;CACA,MAAM,WAAW,UAAmC;EAClD,IAAI,WAAW;GAGb,MAAM,eAAe;GACrB,IAAI,UAAU;GACd,IAAI,YAAY,MAAM,aAAa,UAAU;GAC7C;EACF;EACA,IAAI,UAAU;GAEZ,MAAM,eAAe;GACrB;EACF;EACA,MAAM,UAAU,MAAM,SAAS,KAAK,YAAY;EAChD,YAAY,UAAU;EACtB,MAAM,SAAS,SAAS;EACxB,IAAI,WAAW,QAAQ,CAAC,OAAO,QAAQ,CAAC,WAAW,OAAO,aAAa,OAAO,KAAK;CACrF;CAEA,MAAM,eAAiE;EAErE,GAAI,cAAc,MAAM,KAAK,EAAE,MAAM,SAAkB;EAGvD,GAAG,cAAc;EACjB,YAAY,UAAU,IAAI,QAAQ,KAAA;EAClC,SAAS,UAAU,eAAe,KAAA;EAGlC,GAAI,gBAAgB,EAAE,QAAQ;EAC9B,GAAI,gBAAgB,EAAE,cAAc;EACpC,aAAa,SAAS,MAAM,IAAI;EAChC,gBAAgB,SAAS,MAAM,OAAO;EAGtC,iBAAiB,SAAS,QAAQ;CACpC;CAEA,OAAO,UAA+D;EACpE,gBAAgB;EAChB;EACA;EACA;EACA;EACA;EACA,OAAO;EACP;EACA,KAAK;CACP,CAAC;AACH;AAEA,cAAc,cAAc"}
|
package/dist/dialog/index.d.mts
CHANGED
|
@@ -10,11 +10,11 @@ import { DialogTrigger, DialogTriggerProps, DialogTriggerState } from "./dialog-
|
|
|
10
10
|
/**
|
|
11
11
|
* Dialog built on `<dialog>` and Invoker Commands: `Root` (no DOM) > `Trigger`
|
|
12
12
|
* (`button[command=show-modal]`) + `Popup` (`dialog`) > `Title`, `Description`, `Form`, `Close`.
|
|
13
|
-
* JS-free when the Root has none of `open` / `defaultOpen` / `openChangeAction
|
|
14
|
-
* opening is a transition (pending Trigger, content from
|
|
15
|
-
* part asks for (Close, Form, a foreign close command:
|
|
16
|
-
* `close(returnValue)`); dismissals (Escape, a click
|
|
17
|
-
*
|
|
13
|
+
* JS-free when the Root has none of `open` / `defaultOpen` / `openChangeAction` /
|
|
14
|
+
* `onOpenChange`; otherwise opening is a request, a transition (pending Trigger, content from
|
|
15
|
+
* committed state), and so is a close a part asks for (Close, Form, a foreign close command:
|
|
16
|
+
* `openChangeAction(false)` awaited, then `close(returnValue)`); dismissals (Escape, a click
|
|
17
|
+
* outside) are the browser's facts, reported to `onOpenChange(false)`.
|
|
18
18
|
*
|
|
19
19
|
* @see https://ui.funstack.work/components/dialog
|
|
20
20
|
*/
|
package/dist/dialog/index.mjs
CHANGED
|
@@ -9,11 +9,11 @@ import { DialogTrigger } from "./dialog-trigger.mjs";
|
|
|
9
9
|
/**
|
|
10
10
|
* Dialog built on `<dialog>` and Invoker Commands: `Root` (no DOM) > `Trigger`
|
|
11
11
|
* (`button[command=show-modal]`) + `Popup` (`dialog`) > `Title`, `Description`, `Form`, `Close`.
|
|
12
|
-
* JS-free when the Root has none of `open` / `defaultOpen` / `openChangeAction
|
|
13
|
-
* opening is a transition (pending Trigger, content from
|
|
14
|
-
* part asks for (Close, Form, a foreign close command:
|
|
15
|
-
* `close(returnValue)`); dismissals (Escape, a click
|
|
16
|
-
*
|
|
12
|
+
* JS-free when the Root has none of `open` / `defaultOpen` / `openChangeAction` /
|
|
13
|
+
* `onOpenChange`; otherwise opening is a request, a transition (pending Trigger, content from
|
|
14
|
+
* committed state), and so is a close a part asks for (Close, Form, a foreign close command:
|
|
15
|
+
* `openChangeAction(false)` awaited, then `close(returnValue)`); dismissals (Escape, a click
|
|
16
|
+
* outside) are the browser's facts, reported to `onOpenChange(false)`.
|
|
17
17
|
*
|
|
18
18
|
* @see https://ui.funstack.work/components/dialog
|
|
19
19
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/dialog/index.ts"],"sourcesContent":["// Ships the platform attribute typings (`command`, `commandfor`) with this subpath\n// (conventions 7.4). Type-only: the built JS has no import of it.\nimport \"../internal/platform-attributes.js\";\nimport { DialogClose } from \"./dialog-close.js\";\nimport { DialogDescription } from \"./dialog-description.js\";\nimport { DialogForm } from \"./dialog-form.js\";\nimport { DialogPopup } from \"./dialog-popup.js\";\nimport { DialogRoot } from \"./dialog-root.js\";\nimport { DialogTitle } from \"./dialog-title.js\";\nimport { DialogTrigger } from \"./dialog-trigger.js\";\n\n/**\n * Dialog built on `<dialog>` and Invoker Commands: `Root` (no DOM) > `Trigger`\n * (`button[command=show-modal]`) + `Popup` (`dialog`) > `Title`, `Description`, `Form`, `Close`.\n * JS-free when the Root has none of `open` / `defaultOpen` / `openChangeAction
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/dialog/index.ts"],"sourcesContent":["// Ships the platform attribute typings (`command`, `commandfor`) with this subpath\n// (conventions 7.4). Type-only: the built JS has no import of it.\nimport \"../internal/platform-attributes.js\";\nimport { DialogClose } from \"./dialog-close.js\";\nimport { DialogDescription } from \"./dialog-description.js\";\nimport { DialogForm } from \"./dialog-form.js\";\nimport { DialogPopup } from \"./dialog-popup.js\";\nimport { DialogRoot } from \"./dialog-root.js\";\nimport { DialogTitle } from \"./dialog-title.js\";\nimport { DialogTrigger } from \"./dialog-trigger.js\";\n\n/**\n * Dialog built on `<dialog>` and Invoker Commands: `Root` (no DOM) > `Trigger`\n * (`button[command=show-modal]`) + `Popup` (`dialog`) > `Title`, `Description`, `Form`, `Close`.\n * JS-free when the Root has none of `open` / `defaultOpen` / `openChangeAction` /\n * `onOpenChange`; otherwise opening is a request, a transition (pending Trigger, content from\n * committed state), and so is a close a part asks for (Close, Form, a foreign close command:\n * `openChangeAction(false)` awaited, then `close(returnValue)`); dismissals (Escape, a click\n * outside) are the browser's facts, reported to `onOpenChange(false)`.\n *\n * @see https://ui.funstack.work/components/dialog\n */\nexport const Dialog = {\n Root: DialogRoot,\n Trigger: DialogTrigger,\n Popup: DialogPopup,\n Close: DialogClose,\n Form: DialogForm,\n Title: DialogTitle,\n Description: DialogDescription,\n} as const;\n\nexport type { DialogRootProps, DialogRootState, DialogOpenChangeDetails } from \"./dialog-root.js\";\nexport type { DialogTriggerProps, DialogTriggerState } from \"./dialog-trigger.js\";\nexport type { DialogPopupProps, DialogPopupState } from \"./dialog-popup.js\";\nexport type { DialogCloseProps, DialogCloseState, DialogCloseDetails } from \"./dialog-close.js\";\nexport type { DialogFormProps, DialogFormState } from \"./dialog-form.js\";\nexport type { DialogTitleProps, DialogTitleState } from \"./dialog-title.js\";\nexport type { DialogDescriptionProps, DialogDescriptionState } from \"./dialog-description.js\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAsBA,MAAa,SAAS;CACpB,MAAM;CACN,SAAS;CACT,OAAO;CACP,OAAO;CACP,MAAM;CACN,OAAO;CACP,aAAa;AACf"}
|
|
@@ -186,7 +186,7 @@ See [Browser-owned state](../concepts/browser-owned-state.md) for the reasoning.
|
|
|
186
186
|
|
|
187
187
|
| Prop | Type | Default | Description |
|
|
188
188
|
| - | - | - | - |
|
|
189
|
-
| `exclusive` | `boolean` | `false` | At most one item open. Also decides the value type: string \| null when exclusive, string\[] otherwise. |
|
|
189
|
+
| `exclusive` | `boolean` | `false` | At most one item open. Also decides the value type: string \| null when exclusive, string\[] otherwise. Fixed at mount: a later change is ignored (development warning). |
|
|
190
190
|
| `value` | `string[] \| string \| null (exclusive)` | – | Controlled open items. undefined means uncontrolled; \[] or null means none open. Selects library mode. |
|
|
191
191
|
| `defaultValue` | `string[] \| string \| null (exclusive)` | – | Initial open items in uncontrolled library mode. Selects library mode. |
|
|
192
192
|
| `valueChangeAction` | `ChangeAction<string[] \| string \| null, AccordionValueChangeDetails>` | – | Called with the next open items on every change, inside the Root's transition. Sync, async or a Server Function. `details`: `reason` (a `ChangeReason`; Accordion dispatches `"activate"` or `"platform"`), `item` (the item that changed) and `open` (its new state). In multiple mode the array lists items in the order they mounted. Selects library mode. |
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Button
|
|
2
2
|
|
|
3
|
-
A button whose click is a transition. Compared with `<button onClick>`, a `Button` runs `action` in its own transition and shows `data-pending` until it settles, ignores a
|
|
3
|
+
A button whose click is a transition. Compared with `<button onClick>`, a `Button` runs `action` in its own transition and shows `data-pending` until it settles, runs or ignores a click that comes while it is pending (`whilePending`), sends a rejection to the nearest Error Boundary, and takes a Server Function as `action` or `formAction`.
|
|
4
4
|
|
|
5
5
|
```tsx title="ButtonSave.tsx"
|
|
6
6
|
"use client";
|
|
@@ -11,9 +11,9 @@ import { DemoErrorBoundary } from "./DemoErrorBoundary.js";
|
|
|
11
11
|
import { fakeSave } from "./fake-api.js";
|
|
12
12
|
|
|
13
13
|
// Three Buttons with a 1.2 s fake save. Click Save several times quickly: the action runs once
|
|
14
|
-
// (the call counter, optimistic so it counts at once), because
|
|
15
|
-
// its own action is pending. The
|
|
16
|
-
//
|
|
14
|
+
// (the call counter, optimistic so it counts at once), because whilePending="ignore" makes the
|
|
15
|
+
// Button ignore activation while its own action is pending. The second Button rejects into the
|
|
16
|
+
// Error Boundary; the third catches inside and shows a toast.
|
|
17
17
|
export function ButtonSave() {
|
|
18
18
|
const [calls, setCalls] = useState(0);
|
|
19
19
|
const [saved, setSaved] = useState(0);
|
|
@@ -24,6 +24,7 @@ export function ButtonSave() {
|
|
|
24
24
|
<div className="demo-row">
|
|
25
25
|
<Button
|
|
26
26
|
className="demo-btn"
|
|
27
|
+
whilePending="ignore"
|
|
27
28
|
action={async () => {
|
|
28
29
|
addCall(undefined);
|
|
29
30
|
setCalls((c) => c + 1);
|
|
@@ -73,8 +74,8 @@ export function ButtonSave() {
|
|
|
73
74
|
|
|
74
75
|
```css title="button.css"
|
|
75
76
|
/* Button: [data-pending] is the in-flight state, [data-disabled] the consumer's `disabled`. A
|
|
76
|
-
pending Button is also aria-disabled="true", so style "unavailable"
|
|
77
|
-
aria-disabled without data-pending), not from aria-disabled alone. */
|
|
77
|
+
pending Button with whilePending="ignore" is also aria-disabled="true", so style "unavailable"
|
|
78
|
+
from [data-disabled] (or aria-disabled without data-pending), not from aria-disabled alone. */
|
|
78
79
|
.demo-btn {
|
|
79
80
|
display: inline-flex;
|
|
80
81
|
align-items: center;
|
|
@@ -148,7 +149,40 @@ export function ButtonSave() {
|
|
|
148
149
|
}
|
|
149
150
|
```
|
|
150
151
|
|
|
151
|
-
Click Save several times quickly: the action runs once
|
|
152
|
+
Click Save several times quickly: the action runs once, because Save has `whilePending="ignore"`. While it runs the button carries `data-pending` and `aria-disabled="true"` and keeps focus. The second button rejects into an Error Boundary; the third catches the error inside its action, which the library counts as success, and reports it with a toast.
|
|
153
|
+
|
|
154
|
+
```tsx title="ButtonCounter.tsx"
|
|
155
|
+
"use client";
|
|
156
|
+
import { startTransition, useState } from "react";
|
|
157
|
+
import { Button } from "@funstack/ui/button";
|
|
158
|
+
import { fakeSave } from "./fake-api.js";
|
|
159
|
+
|
|
160
|
+
// A "+1" Button with the default whilePending="run": every click runs the action, also while an
|
|
161
|
+
// earlier one is still pending. The Button shows data-pending until the last run has settled and
|
|
162
|
+
// is never aria-disabled meanwhile. Each run awaits a 1 s fake request, then counts.
|
|
163
|
+
export function ButtonCounter() {
|
|
164
|
+
const [count, setCount] = useState(0);
|
|
165
|
+
|
|
166
|
+
return (
|
|
167
|
+
<div className="demo-row">
|
|
168
|
+
<Button
|
|
169
|
+
className="demo-btn"
|
|
170
|
+
action={async () => {
|
|
171
|
+
await fakeSave("the increment", { ms: 1000 });
|
|
172
|
+
startTransition(() => setCount((c) => c + 1));
|
|
173
|
+
}}
|
|
174
|
+
>
|
|
175
|
+
+1
|
|
176
|
+
</Button>
|
|
177
|
+
<output className="demo-readout">Count: {count}</output>
|
|
178
|
+
</div>
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
`button.css`: the same file as above.
|
|
184
|
+
|
|
185
|
+
Without the prop every click runs: click +1 several times quickly and each click counts. The button shows `data-pending` until the last run has settled and is never `aria-disabled` meanwhile, since it still acts. React commits the runs' updates together once they have all finished. Holding Enter on a focused button repeats the click, as it does on any native button, and each repeat is a run.
|
|
152
186
|
|
|
153
187
|
## Anatomy
|
|
154
188
|
|
|
@@ -164,8 +198,9 @@ One element, no parts. It renders `<button type="button">`; `render` substitutes
|
|
|
164
198
|
|
|
165
199
|
| Prop | Type | Default | Description |
|
|
166
200
|
| - | - | - | - |
|
|
167
|
-
| `action` | `Action<[details: ButtonActionDetails]>` | – | Runs inside the Button's own transition on click, Enter or Space. Sync or async; may be a Server Function (`details` carries only the virtual `event`). A rejection reaches the nearest Error Boundary above the Button.
|
|
168
|
-
| `formAction` | `string \| ((formData: FormData) => void \| Promise<void>)` | – | React's `formAction`: run by React instead of the form's `action` when this Button submits the form. With a function the Button is pending
|
|
201
|
+
| `action` | `Action<[details: ButtonActionDetails]>` | – | Runs inside the Button's own transition on click, Enter or Space. Sync or async; may be a Server Function (`details` carries only the virtual `event`). A rejection reaches the nearest Error Boundary above the Button. A click while it is pending runs it again, unless `whilePending` is `"ignore"`. Not combinable with `formAction` (development error). |
|
|
202
|
+
| `formAction` | `string \| ((formData: FormData) => void \| Promise<void>)` | – | React's `formAction`: run by React instead of the form's `action` when this Button submits the form. With a function the Button is pending from its own submission until the form's submissions have all finished (never for another submitter's alone) and defaults to `type="submit"`; a click meanwhile submits again unless `whilePending` is `"ignore"` (see [Forms](#forms)). Prefer a stable function (a Server Function, a `useActionState` dispatch, `useCallback`) when the form is also submitted from script with `requestSubmit(button)`; an inline function works for clicks and Enter. The match is by function identity (React reports no submitter), so Buttons that share one function (one dispatch, different `name` / `value`) all show pending while either submits; give each its own function (`dispatch.bind(null, "draft")`) to tell them apart. |
|
|
203
|
+
| `whilePending` | `"run" \| "ignore"` | `"run"` | What a click, Enter or Space does while this Button's own `action` (or its own function `formAction` submission) is pending. `"run"`: it runs as well; the Button shows `data-pending` until every run has settled. `"ignore"`: it starts nothing, its default action is cancelled (no second submission, navigation or command), and the Button is `aria-disabled="true"` while pending. Use `"ignore"` for an action that must not run twice (Save, Pay, Delete). No effect on a Button with neither `action` nor a function `formAction`. Type `WhilePending`. |
|
|
169
204
|
| `type` | `"button" \| "submit" \| "reset"` | `"button", or "submit" with formAction` | Owned on a `<button>` and on a component `render` element (assumed to render a `<button>`; it should spread the prop): set it here, not on the element. Omitted for a host element of another tag (`<a>`). `action` together with `submit` / `reset` warns in development (one click would do two things). |
|
|
170
205
|
| `disabled` | `boolean` | `false` | Native `disabled` and `data-disabled`; never dispatches, and a disabled link does not navigate. With `focusableWhenDisabled`, inside a [Toolbar](toolbar.md), or when `render` is not a `<button>` (a link, where native `disabled` means nothing), renders `aria-disabled="true"` instead. |
|
|
171
206
|
| `focusableWhenDisabled` | `boolean` | `false (true inside a Toolbar.Root)` | Keep a disabled Button focusable: `aria-disabled="true"` instead of native `disabled`, so keyboard and screen-reader users still find it and a Tooltip on it still opens. |
|
|
@@ -184,9 +219,9 @@ Every other `<button>` prop passes through, including `name`, `value`, `form`, `
|
|
|
184
219
|
|
|
185
220
|
| Hook | Meaning |
|
|
186
221
|
| - | - |
|
|
187
|
-
| `data-pending` | The Button's own `action` is in flight (until the commit that ends it, including a Suspense wait), or
|
|
222
|
+
| `data-pending` | The Button's own `action` is in flight (until the commit that ends it, including a Suspense wait), or it submitted the form with its own function `formAction` and the form's submissions have not all finished. |
|
|
188
223
|
| `data-disabled` | The `disabled` prop. Not set by pending. |
|
|
189
|
-
| `aria-disabled` | `"true"` while pending
|
|
224
|
+
| `aria-disabled` | `"true"` while pending with `whilePending="ignore"`, and while `disabled` with `focusableWhenDisabled`, inside a Toolbar, or on a non-`<button>` `render` element. Never set by pending in the default `"run"` mode. |
|
|
190
225
|
|
|
191
226
|
Pending is not disabled: `[data-disabled]` and `state.disabled` are your `disabled` only, so the two states never have to look alike.
|
|
192
227
|
|
|
@@ -194,7 +229,7 @@ Pending is not disabled: `[data-disabled]` and `state.disabled` are your `disabl
|
|
|
194
229
|
|
|
195
230
|
| Key | Native \<button> | render={\<a href>} |
|
|
196
231
|
| - | - | - |
|
|
197
|
-
| Enter | Click: runs `action` (unless
|
|
232
|
+
| Enter | Click: runs `action` (unless disabled, or pending with `whilePending="ignore"`) | Click: `action` and navigation; while pending with `whilePending="ignore"`, neither |
|
|
198
233
|
| Space | Click on keyup: runs `action` | Nothing (a link); add `role="button"` and a key handler if a link must act on Space |
|
|
199
234
|
| Tab | Sequential, or the Toolbar's single Tab stop inside one | Same |
|
|
200
235
|
|
|
@@ -210,15 +245,17 @@ None: the Button adds no transition types. Its `transition` prop animates the co
|
|
|
210
245
|
|
|
211
246
|
Concept: [Pending & optimistic state](../concepts/pending-and-optimistic.md)
|
|
212
247
|
|
|
213
|
-
A [pure trigger](../concepts/pending-and-optimistic.md#pure-trigger): no optimistic state. `data-pending`
|
|
248
|
+
A [pure trigger](../concepts/pending-and-optimistic.md#pure-trigger): no optimistic state. `data-pending` while its own action is in flight, or from a submission started by its own function `formAction` until the form's submissions have all finished. A second click, Enter or Space meanwhile runs again by default; with `whilePending="ignore"` it is ignored and the Button is `aria-disabled="true"`.
|
|
249
|
+
|
|
250
|
+
### A click while pending
|
|
214
251
|
|
|
215
|
-
|
|
252
|
+
A Button's action is yours alone, so by default (`whilePending="run"`) the Button does what React's `useTransition` does: every click, Enter or Space runs the action, also while an earlier run is pending. The runs overlap; the Button shows `data-pending` until the last has settled and is not `aria-disabled`, because it still acts. When runs overlap, the latest run's rejection reaches the Error Boundary and an older run's goes to `reportError` (see [Overlapping actions](../concepts/action-props.md#overlapping-actions)). A double click on a default Save therefore saves twice: give it `whilePending="ignore"`.
|
|
216
253
|
|
|
217
|
-
|
|
254
|
+
With `whilePending="ignore"`, a click, Enter or Space while the Button's own action is in flight (also a programmatic `click()` and the click an implicit form submission sends) starts no second run and is `preventDefault()`ed, so a link does not navigate again, a form does not submit again and a `command` does not run again. Nothing else is blocked: focus, hover and your own event handlers work as usual, and ancestors still see the click.
|
|
218
255
|
|
|
219
|
-
- The Button is `aria-disabled="true"` meanwhile, so a screen-reader user who presses again, or comes back to it, hears that it is unavailable. It is never natively `disabled`: Chromium and Firefox move focus to the page when a focused button becomes disabled.
|
|
256
|
+
- The ignoring Button is `aria-disabled="true"` meanwhile, so a screen-reader user who presses again, or comes back to it, hears that it is unavailable. It is never natively `disabled`: Chromium and Firefox move focus to the page when a focused button becomes disabled.
|
|
220
257
|
- The guard is the Button's own run, not its look. React may hold the commit that ends the action while another async action elsewhere is pending (or while the result suspends): the button keeps `data-pending` and `aria-disabled` in that window, but its own work has settled, so a click there starts a new run rather than being dropped. A `formAction` Button follows React's form status instead and stays guarded until its submission commits.
|
|
221
|
-
-
|
|
258
|
+
- An ordered sequence whose steps see each other's results is `useActionState` (pass its dispatch as `formAction`, or call it from the action).
|
|
222
259
|
|
|
223
260
|
## Suspense
|
|
224
261
|
|
|
@@ -311,7 +348,9 @@ import { fakeSave } from "./fake-api.js";
|
|
|
311
348
|
|
|
312
349
|
// One form, three submitters. Form.Submit runs the form's own action and is pending for every
|
|
313
350
|
// submission of the form (the form channel). Each Button formAction runs its own function instead
|
|
314
|
-
// and is pending
|
|
351
|
+
// and is pending from its own submission until the form's submissions have all finished (never
|
|
352
|
+
// for another submitter's alone); with whilePending="ignore" a second click on a pending one is
|
|
353
|
+
// ignored (by default it would submit again).
|
|
315
354
|
export function ButtonFormActions() {
|
|
316
355
|
const [log, setLog] = useState<string[]>([]);
|
|
317
356
|
const record = (line: string) => startTransition(() => setLog((l) => [line, ...l].slice(0, 4)));
|
|
@@ -334,6 +373,7 @@ export function ButtonFormActions() {
|
|
|
334
373
|
</Form.Submit>
|
|
335
374
|
<Button
|
|
336
375
|
className="demo-btn"
|
|
376
|
+
whilePending="ignore"
|
|
337
377
|
formAction={async (data: FormData) => {
|
|
338
378
|
await fakeSave("the draft", { ms: 1500 });
|
|
339
379
|
record(`Saved a draft of “${String(data.get("title"))}”.`);
|
|
@@ -343,6 +383,7 @@ export function ButtonFormActions() {
|
|
|
343
383
|
</Button>
|
|
344
384
|
<Button
|
|
345
385
|
className="demo-btn"
|
|
386
|
+
whilePending="ignore"
|
|
346
387
|
formAction={async () => {
|
|
347
388
|
await fakeSave("the discard", { ms: 2500 });
|
|
348
389
|
record("Discarded.");
|
|
@@ -360,16 +401,22 @@ export function ButtonFormActions() {
|
|
|
360
401
|
}
|
|
361
402
|
```
|
|
362
403
|
|
|
363
|
-
A Button is `type="button"` by default, so an `action` Button never submits the form it sits in. With `formAction` it is a submit button that runs its own function instead of the form's `action`: constraint validation, `FormData` and React's automatic form reset all apply. It is pending
|
|
404
|
+
A Button is `type="button"` by default, so an `action` Button never submits the form it sits in. With `formAction` it is a submit button that runs its own function instead of the form's `action`: constraint validation, `FormData` and React's automatic form reset all apply. It is pending from its own submission until the form's submissions have all finished, and never for another submitter's alone (React reports the latest submitter's function through `useFormStatus().action`).
|
|
405
|
+
|
|
406
|
+
> **Overlapping submissions**
|
|
407
|
+
>
|
|
408
|
+
> By default a second click on a pending `Button formAction` submits the form again, as React's own `<button formAction>` does. Those submissions are React's form channel, and React drops the rejection of an older overlapping submission: it reaches no Error Boundary and no `reportError`, and the library cannot see it. For a submission that must not overlap, use `whilePending="ignore"` (as in the example above), or pass a `useActionState` dispatch, which React runs in order.
|
|
409
|
+
>
|
|
410
|
+
> When another submitter (a second `Button formAction`, `Form.Submit`, Enter in a field) submits while a Button's own submission runs, the Button stays pending until every overlapping submission has settled, also when its own finished first (a second `Button formAction` likewise): React holds the form's status, and the results of the actions, until every overlapping submission has finished, as it does for two overlapping `Button action`s. A `whilePending="ignore"` Button therefore keeps ignoring clicks through the overlap. One case cannot be seen: two submissions started by script in the same task (`requestSubmit(a)` then `requestSubmit(b)`) never let React render the status of the first, so its Button is not pending.
|
|
364
411
|
|
|
365
412
|
| | Form.Submit | Button formAction | Button type="submit" |
|
|
366
413
|
| - | - | - | - |
|
|
367
414
|
| Submits | the form's own `action` | its own function instead | the form's own `action` |
|
|
368
|
-
| `pending` | the form channel: any submitter | its own submissions
|
|
369
|
-
|
|
|
415
|
+
| `pending` | the form channel: any submitter | from its own submission until the form's submissions have all finished | none |
|
|
416
|
+
| A click while pending | not blocked (a `useActionState` dispatch queues it, in order) | submits again; ignored with `whilePending="ignore"` | none |
|
|
370
417
|
| Use | the one primary submit button | secondary submitters | rarely; `Form.Submit` is the documented spelling |
|
|
371
418
|
|
|
372
|
-
Inside a [Form.Root](field.md), a `Button formAction` goes React's way: its function runs, the form's `action` does not, and `Form.Root` shows `data-pending` as for any submission (its `errors` are not fed by it; to route field errors, pass the dispatch of the same `useActionState` as `formAction`). Implicit submission (Enter in a text field) clicks the form's first submit button: if that is a pending `Button formAction`, the click is ignored and nothing is submitted twice.
|
|
419
|
+
Inside a [Form.Root](field.md), a `Button formAction` goes React's way: its function runs, the form's `action` does not, and `Form.Root` shows `data-pending` as for any submission (its `errors` are not fed by it; to route field errors, pass the dispatch of the same `useActionState` as `formAction`). Implicit submission (Enter in a text field) clicks the form's first submit button: if that is a pending `Button formAction`, it submits again, or with `whilePending="ignore"` the click is ignored and nothing is submitted twice.
|
|
373
420
|
|
|
374
421
|
> **Which button?**
|
|
375
422
|
>
|
|
@@ -459,6 +506,6 @@ export function ButtonCompose() {
|
|
|
459
506
|
}
|
|
460
507
|
```
|
|
461
508
|
|
|
462
|
-
`<Dialog.Trigger render={<Button action={a} />}>` runs `a` and opens the dialog on one click: the Trigger's handler runs first and cancels the click (its command), and the Button runs its action anyway; a cancelled click is not a veto for a Button. The two updates start in one event, so React commits them together: **an awaited `a` holds the dialog closed until it settles** (the Trigger already shows `data-open` and `data-pending`). For a prefetch, do not await it, as above. The same works with `Popover.Trigger` and `Tooltip.Trigger`; a Tooltip keeps opening on hover and focus while the Button is pending, because a pending Button is not natively disabled and removes no listeners.
|
|
509
|
+
`<Dialog.Trigger render={<Button action={a} />}>` runs `a` and opens the dialog on one click: the Trigger's handler runs first and cancels the click (its command), and the Button runs its action anyway; a cancelled click is not a veto for a Button. The two updates start in one event, so React commits them together: **an awaited `a` holds the dialog closed until it settles** (the Trigger already shows `data-open` and `data-pending`). For a prefetch, do not await it, as above. The same works with `Popover.Trigger` and `Tooltip.Trigger`; a Tooltip keeps opening on hover and focus while the Button is pending, because a pending Button is not natively disabled and removes no listeners. A second click on the Trigger runs `a` again unless the Button has `whilePending="ignore"`.
|
|
463
510
|
|
|
464
|
-
`commandfor` / `command` pass through: without `action` the browser runs the command, before and after hydration. With both, one click runs the action and the command; while pending,
|
|
511
|
+
`commandfor` / `command` pass through: without `action` the browser runs the command, before and after hydration. With both, one click runs the action and the command; a click while pending runs both again, or with `whilePending="ignore"` neither. Inside a [Toolbar](toolbar.md) a disabled Button stays focusable and in the arrow-key sequence (`aria-disabled`, the APG Toolbar rule).
|
|
@@ -202,7 +202,16 @@ import { CheckboxGroup } from "@funstack/ui/checkbox-group";
|
|
|
202
202
|
> }}
|
|
203
203
|
> ```
|
|
204
204
|
>
|
|
205
|
-
> Uncontrolled groups need none of this:
|
|
205
|
+
> Uncontrolled groups need none of this: once every overlapping save has settled, the group commits each change whose save resolved, in click order, and leaves out one whose save rejected.
|
|
206
|
+
>
|
|
207
|
+
> One exception, in both modes: a form reset (`reason: "platform"` with `details.event?.type === "reset"`) replaces the whole value, so save its `next` whole. Its `added` / `removed` are only the diff from what was intended and can be empty, for example when a pending uncheck is reset away. If your saves must not overlap at all, queue them with React's [`useActionState`](https://react.dev/reference/react/useActionState) and call its dispatch from the action.
|
|
208
|
+
>
|
|
209
|
+
> ```tsx
|
|
210
|
+
> valueChangeAction={async (next, details) => {
|
|
211
|
+
> if (details.reason === "platform" && details.event?.type === "reset") await saveAll(next);
|
|
212
|
+
> else await save(details.added, details.removed);
|
|
213
|
+
> }}
|
|
214
|
+
> ```
|
|
206
215
|
|
|
207
216
|
## Props
|
|
208
217
|
|
|
@@ -337,7 +346,7 @@ Items and the Parent render the optimistic set into their native inputs. `data-p
|
|
|
337
346
|
1. Click Ham: the browser checks it; the group dispatches `valueChangeAction(["cheese", "ham"], { reason: "activate", added: ["ham"], removed: [] })` in the Root's transition. The Root and the Ham box get `data-pending`; a Parent over both values shows checked at once.
|
|
338
347
|
2. Resolve: the set is committed (uncontrolled) and the attributes go.
|
|
339
348
|
3. Reject: the optimistic set reverts, React writes `checked` back, the Parent returns to mixed, and the error reaches the nearest Error Boundary.
|
|
340
|
-
4. Clicks while a save is pending stack: each dispatch is computed from what the user sees, and
|
|
349
|
+
4. Clicks while a save is pending stack: each dispatch is computed from what the user sees. Uncontrolled, once every save has settled, the changes whose saves resolved are committed in click order. An earlier click whose save rejected is left out, and its error goes to `reportError` rather than the Error Boundary (see [Overlapping actions](../concepts/action-props.md#overlapping-actions)).
|
|
341
350
|
|
|
342
351
|
## Suspense
|
|
343
352
|
|
|
@@ -452,7 +461,7 @@ export function CheckboxGroupForm() {
|
|
|
452
461
|
- With a real `name`, every checked Item posts `name=value`; read them with `formData.getAll(name)`. Parents post nothing.
|
|
453
462
|
- **`required` means "at least one"**. HTML has no group constraint, so the Root renders native `required` on every Item while no enabled Item is checked (following the optimistic state) and on none once one is. A checked disabled Item and a value with no Item do not count: neither is submitted. Validation, the browser's localised message and `:user-invalid` stay native; the message reads "check this box". Disabled boxes are not validated, so a disabled group never blocks a submit.
|
|
454
463
|
- Before hydration the attribute is whatever the server rendered, and the server cannot know which values have an enabled Item, so it counts any checked value. In an empty required group every box is required, so a user who checks one box and submits before hydration is still blocked by another box until hydration (over-blocking). A group whose only checked values are disabled Items or have no Item renders no `required` on the server, so a submit before hydration is not blocked (under-blocking, until hydration); validate on the server as well.
|
|
455
|
-
- **Form reset** (the Reset button, `form.reset()`, or React's automatic reset after the action succeeds) is one dispatch for the whole group, with `reason: "platform"`, the `reset` event, and the diff in `added` / `removed`. Uncontrolled, the target is the latest `defaultValue
|
|
464
|
+
- **Form reset** (the Reset button, `form.reset()`, or React's automatic reset after the action succeeds) is one dispatch for the whole group, with `reason: "platform"`, the `reset` event, and the diff in `added` / `removed`. Uncontrolled, the target is the latest `defaultValue`, and the reset replaces the value whole: it is dispatched even with an empty diff while a change is still pending, so a pending change that fails later cannot bring its box back after the reset. Controlled, the mount-time values are offered to the parent.
|
|
456
465
|
- **Clicks before hydration** work natively, on Items and on Parents. On hydration the Root dispatches once for everything it finds changed, with no event; a Parent clicked before hydration counts as "check all" (or "uncheck all") of its enabled values. The order of those clicks is not preserved: a Parent click is applied after the Items' state is read, so an Item clicked after the Parent before hydration is overridden by the Parent. Items that hydrate later, inside a Suspense boundary, are reconciled when they do; unlike RadioGroup, a group split across Suspense boundaries works. Firefox restores the Items' checked state on reload, which is reconciled the same way; the Parent is never restored (`autocomplete="off"`), so a restore cannot be taken for a Parent click.
|
|
457
466
|
|
|
458
467
|
### Server Functions and forms
|
|
@@ -241,12 +241,6 @@ export function ComboboxCountry() {
|
|
|
241
241
|
}
|
|
242
242
|
}
|
|
243
243
|
|
|
244
|
-
/* Keep the CSS exit for dismissals, but not while a view transition runs (Chromium would
|
|
245
|
-
capture a fading listbox twice). */
|
|
246
|
-
html:active-view-transition .demo-combobox-popup {
|
|
247
|
-
transition: none;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
244
|
@media (prefers-reduced-motion: reduce) {
|
|
251
245
|
.demo-combobox-popup {
|
|
252
246
|
transition: none;
|
|
@@ -286,22 +280,22 @@ import { Combobox } from "@funstack/ui/combobox";
|
|
|
286
280
|
|
|
287
281
|
### Typing is urgent; everything it causes is not
|
|
288
282
|
|
|
289
|
-
|
|
283
|
+
React requires a controlled text input to update urgently, in the same event as the keystroke: by the time the library hears of it, the text is already in the DOM. So the text is **urgent state**, a [fact](../concepts/action-props.md#fact) rather than a request. It keeps the usual pair, `inputValue` / `defaultInputValue`, but its callback is a handler, not an action: `onInputValueChange` (an [`on*` handler](../concepts/action-props.md#on-handler)) is called synchronously, outside any transition, and never awaited. A controlled parent simply sets its state in the body:
|
|
290
284
|
|
|
291
285
|
```tsx
|
|
292
286
|
const [text, setText] = useState("");
|
|
293
287
|
<Combobox.Root inputValue={text} onInputValueChange={(next) => setText(next)}>
|
|
294
288
|
```
|
|
295
289
|
|
|
296
|
-
Everything downstream of the text
|
|
290
|
+
Everything downstream of the text is a transition again:
|
|
297
291
|
|
|
298
292
|
- **The results** render from `query`, which is `useDeferredValue(inputValue)`. A slow search never blocks a keystroke; the previous results stay on screen (no fallback flash) with `data-stale` and `aria-busy="true"` until the new ones are ready; and only the latest query is ever rendered, so a slow response for "ja" cannot overwrite the results for "jap".
|
|
299
|
-
- **Opening** is a transition (`openChangeAction`).
|
|
293
|
+
- **Opening** is a transition (`openChangeAction`). A dismissal (Escape, a click outside, focus leaving) is a fact, reported to `onOpenChange`.
|
|
300
294
|
- **Choosing** an option is a transition (`valueChangeAction`) with an optimistic selection, exactly as every other value in the library.
|
|
301
295
|
|
|
302
296
|
> **Do not fetch in onInputValueChange**
|
|
303
297
|
>
|
|
304
|
-
> `onInputValueChange={async (q) => setResults(await search(q))}` brings back every problem the deferred query solves: responses land in completion order, nothing marks the results stale, and the urgent handler is not awaited anyway
|
|
298
|
+
> `onInputValueChange={async (q) => setResults(await search(q))}` brings back every problem the deferred query solves: responses land in completion order, nothing marks the results stale, and the urgent handler is not awaited anyway. Read a query-keyed cache with `use()` inside the List instead. (Returning a promise is allowed, for work the UI does not wait for such as logging: like every `on*` handler, its rejection goes to `reportError`.)
|
|
305
299
|
|
|
306
300
|
While any async action is pending in the app (this combobox's own slow save included), React holds every transition. Typing is unaffected (urgent), and so are the results: a deferred render is not held by a pending action (verified in Chromium and Firefox). Opening the listbox while a save is pending is a transition, so it waits for the save: the input shows `data-open` and `data-pending` meanwhile, and its `aria-expanded` turns `"true"` when the listbox is shown.
|
|
307
301
|
|
|
@@ -390,10 +384,11 @@ With `allowCustomValue` the typed text is a value: Enter with no active option,
|
|
|
390
384
|
| `valueChangeAction` | `ChangeAction<string \| null, ComboboxValueChangeDetails>` | – | Runs in the Root's transition when the user accepts an option, commits free text, presses Clear, or the form resets. Awaited; the listbox closes in the commit that ends it; a rejection rolls the text and the selection back and leaves the listbox open. May be a Server Function. A `setState` after your own `await` needs `startTransition`. |
|
|
391
385
|
| `inputValue` | `string` | – | Controlled text. `undefined` means uncontrolled. |
|
|
392
386
|
| `defaultInputValue` | `string` | `""` | Initial text when uncontrolled, and the visible input's form-reset target. Pass the selected option's label together with `defaultValue`. |
|
|
393
|
-
| `onInputValueChange` | `UrgentChangeHandler<string, ComboboxInputValueChangeDetails>` | – | A handler
|
|
394
|
-
| `open` | `boolean` | – | Controlled open state. `undefined` means uncontrolled. |
|
|
387
|
+
| `onInputValueChange` | `UrgentChangeHandler<string, ComboboxInputValueChangeDetails>` | – | A [handler](../concepts/action-props.md#on-handler), not an action: called synchronously, outside any transition, on every change of the text (typing, and the library's own writes). Not awaited, never pending. Set your state in the body. May return a promise; a rejection or a throw goes to `reportError` ([the rule of every on\* handler](../concepts/action-props.md#handlers)). |
|
|
388
|
+
| `open` | `boolean` | – | Controlled open state. `undefined` means uncontrolled. Pass `onOpenChange` too (development warns). |
|
|
395
389
|
| `defaultOpen` | `boolean` | `false` | Initial open state; opens after hydration. |
|
|
396
|
-
| `openChangeAction` | `ChangeAction<boolean, ComboboxOpenChangeDetails>` | – |
|
|
390
|
+
| `openChangeAction` | `ChangeAction<boolean, ComboboxOpenChangeDetails>` | – | Requests only: awaited for opens and for the closes a part asks for (an accepted option, the Trigger, Alt+ArrowUp). Never called for a dismissal (`onOpenChange`). Runs in the Root's transition; may be a Server Function. `details.reason`: `"activate"` (typing, ArrowDown / ArrowUp / Alt+ArrowDown, the Trigger, a click on the input with `openOnClick`, an accepted option, Alt+ArrowUp, a foreign `showPopover()`) or `"platform"` (found open on mount, which only script can cause; `event` is `undefined`). |
|
|
391
|
+
| `onOpenChange` | `UrgentChangeHandler<boolean, ComboboxOpenChangeDetails>` | – | Facts only: the listbox was closed without the library closing it on request. Always `false`. `details.reason`: `"dismiss"` (Escape, focus leaving the input, a click outside, a Clear click while open, another popover opening, script) or `"activate"` (a [foreign invoker](../concepts/browser-owned-state.md#foreign-invoker), whose press does not move focus out of the input, so the text is left as typed; 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 listbox shown again at once, with focus left where the dismissal put it. May return a promise (a Server Function); a rejection or a throw goes to `reportError`. |
|
|
397
392
|
| `allowCustomValue` | `boolean` | `false` | Free text is a value (Enter with no active option, focus leaving), dispatched with `details.custom: true`. Otherwise unmatched text reverts when focus leaves. |
|
|
398
393
|
| `autoHighlight` | `boolean` | `false` | Make the first enabled option active when the results for an open or an edit settle (APG automatic selection): typing then Enter picks the first match. Stale results are never highlighted, so an Enter before they settle commits the typed text (`allowCustomValue`) or does nothing. |
|
|
399
394
|
| `openOnClick` | `boolean` | `false` | Open on a click in the input (never on focus alone). |
|
|
@@ -409,7 +404,7 @@ With `allowCustomValue` the typed text is a value: Enter with no active option,
|
|
|
409
404
|
|
|
410
405
|
`multiple` is not part of this version.
|
|
411
406
|
|
|
412
|
-
`ComboboxValueChangeDetails`: `{ reason, custom, event }`. `reason` is `"activate"` (an accepted option: the `keydown` or `click`; free text: the `keydown` or `focusout`; Clear: the `click`) or `"platform"` (a form reset: the `reset` event). `ComboboxInputValueChangeDetails`: `{ reason, event }`, with `"activate"` for typing (the `input` event), an accepted label and Clear, `"dismiss"` for a revert, `"platform"` for a reset or text found at mount (no event). `ComboboxOpenChangeDetails`: `{ reason, event }
|
|
407
|
+
`ComboboxValueChangeDetails`: `{ reason, custom, event }`. `reason` is `"activate"` (an accepted option: the `keydown` or `click`; free text: the `keydown` or `focusout`; Clear: the `click`) or `"platform"` (a form reset: the `reset` event). `ComboboxInputValueChangeDetails`: `{ reason, event }`, with `"activate"` for typing (the `input` event), an accepted label and Clear, `"dismiss"` for a revert, `"platform"` for a reset or text found at mount (no event). `ComboboxOpenChangeDetails`: `{ reason, event }`; the reasons are listed with `openChangeAction` and `onOpenChange` above.
|
|
413
408
|
|
|
414
409
|
### `Combobox.Label`
|
|
415
410
|
|
|
@@ -460,7 +455,7 @@ Both keep focus in the input when pressed and focus it when clicked. The Trigger
|
|
|
460
455
|
|
|
461
456
|
| Prop | Type | Default | Description |
|
|
462
457
|
| - | - | - | - |
|
|
463
|
-
| `keepMounted` | `boolean` | `false` | `false`: the children render only while open. `true`: they stay mounted in a hidden `<Activity
|
|
458
|
+
| `keepMounted` | `boolean` | `false` | `false`: the children render only while open. `true`: they stay mounted in a hidden `<Activity>`; an action inside that rejects while it is hidden goes to `reportError`, not to an Error Boundary. |
|
|
464
459
|
| `transition` | `ViewTransitionClass` | – | The `<ViewTransition default>` around the popover element. Animates library-driven opens and closes in every engine. A deferred results render activates it too, so use a map with `default: "none"` (below). Keep it static. |
|
|
465
460
|
| `className` | `string \| ((state: ComboboxPopupState) => string \| undefined)` | – | A class name, or a function of the part's state. |
|
|
466
461
|
| `style` | `CSSProperties \| ((state: ComboboxPopupState) => CSSProperties \| undefined)` | – | Inline style, or a function of the part's state. |
|
|
@@ -569,7 +564,79 @@ Every value dispatch: `fsui-combobox` and `fsui-combobox-select`. Opens and clos
|
|
|
569
564
|
|
|
570
565
|
Concept: [Pending & optimistic state](../concepts/pending-and-optimistic.md)
|
|
571
566
|
|
|
572
|
-
The selected value and the open state are optimistic (`data-selected` on the Input and the Option). `data-pending` is on the Input while a selection or an open is in flight, on the Trigger while an open or close is, and on the Option being chosen. The typed text is urgent, not optimistic (
|
|
567
|
+
The selected value and the open state are optimistic (`data-selected` on the Input and the Option). `data-pending` is on the Input while a selection or an open is in flight, on the Trigger while an open or close is, and on the Option being chosen. The typed text is urgent, not optimistic (a [fact](../concepts/action-props.md#fact), reported to `onInputValueChange`).
|
|
568
|
+
|
|
569
|
+
### A slow `openChangeAction`
|
|
570
|
+
|
|
571
|
+
Here every `openChangeAction` call takes 2 seconds, like a server call, and `onOpenChange` logs the dismissals. The Input's `aria-expanded`, and the state the browser exposes on the Trigger, follow the shown listbox:
|
|
572
|
+
|
|
573
|
+
```tsx title="ComboboxSlowOpen.tsx"
|
|
574
|
+
"use client";
|
|
575
|
+
import { startTransition, useState } from "react";
|
|
576
|
+
import { Combobox } from "@funstack/ui/combobox";
|
|
577
|
+
import type { ComboboxOpenChangeDetails } from "@funstack/ui/combobox";
|
|
578
|
+
import { sleep } from "./fake-api.js";
|
|
579
|
+
|
|
580
|
+
const FRUITS = ["Apple", "Banana", "Cherry", "Grape", "Lemon", "Mango", "Orange", "Pear"];
|
|
581
|
+
|
|
582
|
+
// A slow `openChangeAction`: a pretend server call of 2 seconds for every request. Opening
|
|
583
|
+
// (typing, ArrowDown or the Trigger): the Input and the Trigger get data-open and data-pending at
|
|
584
|
+
// once, the listbox is shown when the action settles. Accepting an option or pressing the Trigger
|
|
585
|
+
// again closes it when the close's action settles. Escape, a click outside and focus leaving are
|
|
586
|
+
// the browser's, a fact: the listbox hides at once, nothing is pending and the action is not
|
|
587
|
+
// called; `onOpenChange` reports it. The Input's `aria-expanded` and the state the browser
|
|
588
|
+
// exposes on the Trigger follow the shown listbox. The readout is plain text, not a live region.
|
|
589
|
+
export function ComboboxSlowOpen() {
|
|
590
|
+
const [log, setLog] = useState("(none yet)");
|
|
591
|
+
const slow = async (open: boolean, { reason }: ComboboxOpenChangeDetails) => {
|
|
592
|
+
const call = `openChangeAction(${open}, "${reason}")`;
|
|
593
|
+
setLog(`${call}: running…`);
|
|
594
|
+
await sleep(2000);
|
|
595
|
+
// After an await: wrap the update in startTransition (React limitation).
|
|
596
|
+
startTransition(() => setLog(`${call}: settled`));
|
|
597
|
+
};
|
|
598
|
+
// A fact: called in the browser's event, not awaited. A plain setState here is urgent.
|
|
599
|
+
const dismissed = (open: boolean, { reason }: ComboboxOpenChangeDetails) => {
|
|
600
|
+
setLog(`onOpenChange(${open}, "${reason}")`);
|
|
601
|
+
};
|
|
602
|
+
return (
|
|
603
|
+
<div className="demo-stack">
|
|
604
|
+
<Combobox.Root openChangeAction={slow} onOpenChange={dismissed}>
|
|
605
|
+
<Combobox.Label>Fruit</Combobox.Label>
|
|
606
|
+
<div className="demo-combobox-field">
|
|
607
|
+
<Combobox.Input className="demo-combobox-input" placeholder="Type or press ArrowDown" />
|
|
608
|
+
<Combobox.Trigger className="demo-combobox-icon" aria-label="Show fruits">
|
|
609
|
+
{({ pending }) => (pending ? <span className="demo-spinner" aria-hidden /> : "▾")}
|
|
610
|
+
</Combobox.Trigger>
|
|
611
|
+
<Combobox.Popup className="demo-combobox-popup">
|
|
612
|
+
<Combobox.List>
|
|
613
|
+
{({ query }) =>
|
|
614
|
+
FRUITS.filter((f) => f.toLowerCase().includes(query.toLowerCase())).map((f) => (
|
|
615
|
+
<Combobox.Option key={f} value={f}>
|
|
616
|
+
{f}
|
|
617
|
+
</Combobox.Option>
|
|
618
|
+
))
|
|
619
|
+
}
|
|
620
|
+
</Combobox.List>
|
|
621
|
+
<Combobox.Empty className="demo-combobox-status">No fruit matches.</Combobox.Empty>
|
|
622
|
+
</Combobox.Popup>
|
|
623
|
+
</div>
|
|
624
|
+
</Combobox.Root>
|
|
625
|
+
<p className="demo-readout">
|
|
626
|
+
Last: <code>{log}</code>
|
|
627
|
+
</p>
|
|
628
|
+
</div>
|
|
629
|
+
);
|
|
630
|
+
}
|
|
631
|
+
```
|
|
632
|
+
|
|
633
|
+
`combobox.css`: the same file as above.
|
|
634
|
+
|
|
635
|
+
- Open (type, ArrowDown or the Trigger): the Input and the Trigger get `data-open` and `data-pending` at once and stay collapsed; the listbox is shown and both are expanded when the action settles.
|
|
636
|
+
- Accept an option, or press the Trigger again: the listbox stays shown and both stay expanded until the close's action settles.
|
|
637
|
+
- Escape or a click outside: a fact. The listbox hides and both are collapsed at once; nothing is pending and the slow action is not called; `onOpenChange` is.
|
|
638
|
+
|
|
639
|
+
The readout under the example is plain text, not a live region, so it does not interrupt a screen reader.
|
|
573
640
|
|
|
574
641
|
## Suspense
|
|
575
642
|
|
|
@@ -581,7 +648,7 @@ Results render from a deferred copy of the text (`useDeferredValue`), so an asyn
|
|
|
581
648
|
|
|
582
649
|
Concept: [Browser-owned state](../concepts/browser-owned-state.md)
|
|
583
650
|
|
|
584
|
-
The listbox is a popover: a dismissal (Escape, a click outside, another popover opening) is the browser's. Focus leaving the input is closed by the library
|
|
651
|
+
The listbox is a popover: a dismissal (Escape, a click outside, another popover opening) is the browser's. Focus leaving the input is closed by the library at once, which it cannot hold either. Either way it is a fact: `onOpenChange(false)` with `reason: "dismiss"`, nothing pending.
|
|
585
652
|
|
|
586
653
|
## Before hydration
|
|
587
654
|
|
|
@@ -621,11 +688,7 @@ A plain text field: typing works and the form posts the default selection (and t
|
|
|
621
688
|
|
|
622
689
|
Types: every value dispatch adds `fsui-combobox` and `fsui-combobox-select`; opens and closes add `fsui-combobox-open` / `fsui-combobox-close`.
|
|
623
690
|
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
```css
|
|
627
|
-
html:active-view-transition .listbox { transition: none; }
|
|
628
|
-
```
|
|
691
|
+
Keep the CSS exit above next to `transition`: it animates the dismissals (focus leaving, Escape, a click outside). 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)).
|
|
629
692
|
|
|
630
693
|
## Browser notes
|
|
631
694
|
|
|
@@ -375,15 +375,15 @@ Those options are shipped CSS: a `<style>` React hoists into `<head>` once per p
|
|
|
375
375
|
|
|
376
376
|
### Moving and closing
|
|
377
377
|
|
|
378
|
-
| Input | What happens |
|
|
378
|
+
| Input | What happens | Reported as |
|
|
379
379
|
| - | - | - |
|
|
380
380
|
| Right-click elsewhere in the region while open | The menu moves to the new point: no `openChangeAction`, items keep their state, a pending item action keeps running, the first item is focused again | – |
|
|
381
|
-
| Right-click or middle-click outside the menu | Closes at once, for every menu (a Menu opened from its button too): the browser's own light dismiss ignores those buttons in Chromium, and native menus close on any click | `"dismiss"` |
|
|
381
|
+
| Right-click or middle-click outside the menu | Closes at once, for every menu (a Menu opened from its button too): the browser's own light dismiss ignores those buttons in Chromium, and native menus close on any click | `onOpenChange`, `"dismiss"` |
|
|
382
382
|
| Right-click inside the menu | Nothing: the browser's menu is suppressed, the menu stays where it is | – |
|
|
383
|
-
| Release of the held button or finger over an item, after sliding onto it | The item is activated, as a click would (see Press-drag-release) | `"activate"` |
|
|
384
|
-
| Release of the held button outside the menu, after moving, at least 500 ms after the menu appeared | Closes at once | `"dismiss"` |
|
|
385
|
-
| A scroll of the page, or of a scroller around the region | Closes at once (a menu at a point only; see Scrolling) | `"dismiss"` |
|
|
386
|
-
| An item's activation, Escape, Tab, a left click outside | As Menu | `"activate"
|
|
383
|
+
| Release of the held button or finger over an item, after sliding onto it | The item is activated, as a click would (see Press-drag-release) | `openChangeAction`, `"activate"` |
|
|
384
|
+
| Release of the held button outside the menu, after moving, at least 500 ms after the menu appeared | Closes at once | `onOpenChange`, `"dismiss"` |
|
|
385
|
+
| A scroll of the page, or of a scroller around the region | Closes at once (a menu at a point only; see Scrolling) | `onOpenChange`, `"dismiss"` |
|
|
386
|
+
| An item's activation, Escape, Tab, a left click outside | As Menu | the activation: `openChangeAction`, `"activate"`; the others: `onOpenChange`, `"dismiss"` |
|
|
387
387
|
|
|
388
388
|
Focus after a close is the platform's: the element focused when the menu opened. A right-click on a region that cannot take focus leaves focus on `<body>` (the right-button press already moved it there, as with native menus); with a `Menu.Trigger` in the same Root, focus goes to that button instead.
|
|
389
389
|
|
|
@@ -492,7 +492,7 @@ Items that suspend hold the open, with `data-pending` on the region (and on a Tr
|
|
|
492
492
|
|
|
493
493
|
Concept: [Browser-owned state](../concepts/browser-owned-state.md)
|
|
494
494
|
|
|
495
|
-
As in Menu: light dismiss and Escape are the browser's; a dismissal is
|
|
495
|
+
As in Menu: light dismiss and Escape are the browser's; a dismissal is a fact, reported to `onOpenChange` with `reason: "dismiss"`. So are the closes the library performs at once and cannot hold: a right- or middle-click outside, a scroll under a menu placed at a point, a release outside after a long press.
|
|
496
496
|
|
|
497
497
|
## Before hydration
|
|
498
498
|
|
|
@@ -509,7 +509,7 @@ The browser's own context menu shows. Nothing is half-open and nothing is replay
|
|
|
509
509
|
.menu[data-context] { margin: 0; } /* point-placed: no anchored gap */
|
|
510
510
|
```
|
|
511
511
|
|
|
512
|
-
- The Menu styles apply as they are (`margin: 0; inset: auto` on the popup is what a point-placed menu wants too). Enter and exit CSS and `transition` as Menu: the open and library-driven closes animate with `transition`; dismissals and the outside right-click with CSS; a move is instant.
|
|
512
|
+
- The Menu styles apply as they are (`margin: 0; inset: auto` on the popup is what a point-placed menu wants too). Enter and exit CSS and `transition` as Menu: the open and library-driven closes animate with `transition`; dismissals and the outside right-click are facts and animate with CSS only (no view transition); a move is instant.
|
|
513
513
|
- On iOS a long-press over text starts a selection and the loupe. Only a `user-select: none` that applies before the touch starts prevents it, and then the text cannot be selected by touch, so it is your choice, not a library default. The region already suppresses the link and image callout inline.
|
|
514
514
|
|
|
515
515
|
## Browser notes
|