@funstack/ui 0.1.0-alpha.19 → 0.1.0-alpha.20
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-item.mjs +2 -2
- package/dist/accordion/accordion-item.mjs.map +1 -1
- package/dist/accordion/accordion-trigger.d.mts.map +1 -1
- package/dist/accordion/accordion-trigger.mjs +3 -20
- package/dist/accordion/accordion-trigger.mjs.map +1 -1
- package/dist/alert-dialog/alert-dialog-action.d.mts +73 -0
- package/dist/alert-dialog/alert-dialog-action.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-action.mjs +23 -0
- package/dist/alert-dialog/alert-dialog-action.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-cancel.d.mts +31 -0
- package/dist/alert-dialog/alert-dialog-cancel.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-cancel.mjs +50 -0
- package/dist/alert-dialog/alert-dialog-cancel.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-context.mjs +24 -0
- package/dist/alert-dialog/alert-dialog-context.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-description.d.mts +25 -0
- package/dist/alert-dialog/alert-dialog-description.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-description.mjs +20 -0
- package/dist/alert-dialog/alert-dialog-description.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-form.d.mts +27 -0
- package/dist/alert-dialog/alert-dialog-form.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-form.mjs +22 -0
- package/dist/alert-dialog/alert-dialog-form.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-popup.d.mts +42 -0
- package/dist/alert-dialog/alert-dialog-popup.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-popup.mjs +53 -0
- package/dist/alert-dialog/alert-dialog-popup.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-root.d.mts +31 -0
- package/dist/alert-dialog/alert-dialog-root.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-root.mjs +22 -0
- package/dist/alert-dialog/alert-dialog-root.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-title.d.mts +23 -0
- package/dist/alert-dialog/alert-dialog-title.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-title.mjs +18 -0
- package/dist/alert-dialog/alert-dialog-title.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-trigger.d.mts +23 -0
- package/dist/alert-dialog/alert-dialog-trigger.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-trigger.mjs +18 -0
- package/dist/alert-dialog/alert-dialog-trigger.mjs.map +1 -0
- package/dist/alert-dialog/index.d.mts +33 -0
- package/dist/alert-dialog/index.d.mts.map +1 -0
- package/dist/alert-dialog/index.mjs +33 -0
- package/dist/alert-dialog/index.mjs.map +1 -0
- package/dist/checkbox-group/checkbox-group-parent.mjs +1 -1
- package/dist/collapsible/collapsible-context.mjs +8 -0
- package/dist/collapsible/collapsible-context.mjs.map +1 -0
- package/dist/collapsible/collapsible-panel.d.mts +53 -0
- package/dist/collapsible/collapsible-panel.d.mts.map +1 -0
- package/dist/collapsible/collapsible-panel.mjs +41 -0
- package/dist/collapsible/collapsible-panel.mjs.map +1 -0
- package/dist/collapsible/collapsible-root.d.mts +108 -0
- package/dist/collapsible/collapsible-root.d.mts.map +1 -0
- package/dist/collapsible/collapsible-root.mjs +147 -0
- package/dist/collapsible/collapsible-root.mjs.map +1 -0
- package/dist/collapsible/collapsible-trigger.d.mts +45 -0
- package/dist/collapsible/collapsible-trigger.d.mts.map +1 -0
- package/dist/collapsible/collapsible-trigger.mjs +62 -0
- package/dist/collapsible/collapsible-trigger.mjs.map +1 -0
- package/dist/collapsible/index.d.mts +21 -0
- package/dist/collapsible/index.d.mts.map +1 -0
- package/dist/collapsible/index.mjs +21 -0
- package/dist/collapsible/index.mjs.map +1 -0
- package/dist/combobox/chip-text.mjs +24 -0
- package/dist/combobox/chip-text.mjs.map +1 -0
- package/dist/combobox/combobox-chips.d.mts +159 -0
- package/dist/combobox/combobox-chips.d.mts.map +1 -0
- package/dist/combobox/combobox-chips.mjs +198 -0
- package/dist/combobox/combobox-chips.mjs.map +1 -0
- package/dist/combobox/combobox-clear.d.mts +5 -2
- package/dist/combobox/combobox-clear.d.mts.map +1 -1
- package/dist/combobox/combobox-clear.mjs +3 -1
- package/dist/combobox/combobox-clear.mjs.map +1 -1
- package/dist/combobox/combobox-context.mjs +4 -5
- package/dist/combobox/combobox-context.mjs.map +1 -1
- package/dist/combobox/combobox-input.d.mts +10 -3
- package/dist/combobox/combobox-input.d.mts.map +1 -1
- package/dist/combobox/combobox-input.mjs +13 -5
- package/dist/combobox/combobox-input.mjs.map +1 -1
- package/dist/combobox/combobox-keyboard.mjs +50 -4
- package/dist/combobox/combobox-keyboard.mjs.map +1 -1
- package/dist/combobox/combobox-list.d.mts +1 -1
- package/dist/combobox/combobox-list.mjs +2 -1
- package/dist/combobox/combobox-list.mjs.map +1 -1
- package/dist/combobox/combobox-option.d.mts +5 -2
- package/dist/combobox/combobox-option.d.mts.map +1 -1
- package/dist/combobox/combobox-option.mjs +4 -3
- package/dist/combobox/combobox-option.mjs.map +1 -1
- package/dist/combobox/combobox-root.d.mts +127 -35
- package/dist/combobox/combobox-root.d.mts.map +1 -1
- package/dist/combobox/combobox-root.mjs +396 -44
- package/dist/combobox/combobox-root.mjs.map +1 -1
- package/dist/combobox/index.d.mts +8 -2
- package/dist/combobox/index.d.mts.map +1 -1
- package/dist/combobox/index.mjs +7 -1
- package/dist/combobox/index.mjs.map +1 -1
- package/dist/combobox/use-combobox-form.mjs +2 -3
- package/dist/combobox/use-combobox-form.mjs.map +1 -1
- package/dist/dialog/dialog-close.d.mts +9 -5
- package/dist/dialog/dialog-close.d.mts.map +1 -1
- package/dist/dialog/dialog-close.mjs +19 -8
- package/dist/dialog/dialog-close.mjs.map +1 -1
- package/dist/dialog/dialog-context.d.mts +2 -0
- package/dist/dialog/dialog-context.mjs +14 -2
- package/dist/dialog/dialog-context.mjs.map +1 -1
- package/dist/dialog/dialog-description.d.mts +2 -1
- package/dist/dialog/dialog-description.d.mts.map +1 -1
- package/dist/dialog/dialog-description.mjs +8 -4
- package/dist/dialog/dialog-description.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 +11 -6
- package/dist/dialog/dialog-form.mjs.map +1 -1
- package/dist/dialog/dialog-popup.d.mts +2 -1
- package/dist/dialog/dialog-popup.d.mts.map +1 -1
- package/dist/dialog/dialog-popup.mjs +23 -14
- package/dist/dialog/dialog-popup.mjs.map +1 -1
- package/dist/dialog/dialog-root.d.mts +2 -1
- package/dist/dialog/dialog-root.d.mts.map +1 -1
- package/dist/dialog/dialog-root.mjs +15 -5
- package/dist/dialog/dialog-root.mjs.map +1 -1
- package/dist/dialog/dialog-title.d.mts +2 -1
- package/dist/dialog/dialog-title.d.mts.map +1 -1
- package/dist/dialog/dialog-title.mjs +8 -4
- package/dist/dialog/dialog-title.mjs.map +1 -1
- package/dist/dialog/dialog-trigger.d.mts +2 -1
- package/dist/dialog/dialog-trigger.d.mts.map +1 -1
- package/dist/dialog/dialog-trigger.mjs +14 -9
- package/dist/dialog/dialog-trigger.mjs.map +1 -1
- package/dist/docs/components/accordion.md +2 -0
- package/dist/docs/components/alert-dialog.md +546 -0
- package/dist/docs/components/collapsible.md +408 -0
- package/dist/docs/components/combobox.md +288 -26
- package/dist/docs/components/dialog.md +7 -5
- package/dist/docs/components/field.md +180 -3
- package/dist/docs/components/hover-card.md +494 -0
- package/dist/docs/components/multi-select.md +622 -0
- package/dist/docs/components/number-field.md +1 -1
- package/dist/docs/components/popover.md +4 -4
- package/dist/docs/components/select.md +9 -1
- package/dist/docs/components/separator.md +182 -0
- package/dist/docs/components/slider.md +1 -1
- package/dist/docs/components/tooltip.md +1 -1
- package/dist/docs/concepts/experimental.md +3 -3
- package/dist/docs/concepts/server-components.md +1 -1
- package/dist/docs/index.md +7 -2
- package/dist/docs/roadmap.md +8 -0
- package/dist/field/field-control.d.mts +13 -4
- package/dist/field/field-control.d.mts.map +1 -1
- package/dist/field/field-control.mjs +39 -10
- package/dist/field/field-control.mjs.map +1 -1
- package/dist/field/field-label.d.mts +6 -2
- package/dist/field/field-label.d.mts.map +1 -1
- package/dist/field/field-label.mjs +12 -2
- package/dist/field/field-label.mjs.map +1 -1
- package/dist/field/field-root.mjs +9 -1
- package/dist/field/field-root.mjs.map +1 -1
- package/dist/hover-card/hover-card-context.mjs +13 -0
- package/dist/hover-card/hover-card-context.mjs.map +1 -0
- package/dist/hover-card/hover-card-popup.d.mts +102 -0
- package/dist/hover-card/hover-card-popup.d.mts.map +1 -0
- package/dist/hover-card/hover-card-popup.mjs +80 -0
- package/dist/hover-card/hover-card-popup.mjs.map +1 -0
- package/dist/hover-card/hover-card-root.d.mts +94 -0
- package/dist/hover-card/hover-card-root.d.mts.map +1 -0
- package/dist/hover-card/hover-card-root.mjs +74 -0
- package/dist/hover-card/hover-card-root.mjs.map +1 -0
- package/dist/hover-card/hover-card-trigger.d.mts +65 -0
- package/dist/hover-card/hover-card-trigger.d.mts.map +1 -0
- package/dist/hover-card/hover-card-trigger.mjs +109 -0
- package/dist/hover-card/hover-card-trigger.mjs.map +1 -0
- package/dist/hover-card/index.d.mts +24 -0
- package/dist/hover-card/index.d.mts.map +1 -0
- package/dist/hover-card/index.mjs +24 -0
- package/dist/hover-card/index.mjs.map +1 -0
- package/dist/hover-card/use-hover-card-interest.mjs +242 -0
- package/dist/hover-card/use-hover-card-interest.mjs.map +1 -0
- package/dist/index.d.mts +38 -9
- package/dist/index.mjs +6 -1
- package/dist/internal/action/use-multiple-selection.mjs +83 -0
- package/dist/internal/action/use-multiple-selection.mjs.map +1 -0
- package/dist/internal/details-summary.mjs +56 -0
- package/dist/internal/details-summary.mjs.map +1 -0
- package/dist/internal/form/field-context.mjs.map +1 -1
- package/dist/internal/form/hidden-values.mjs +29 -0
- package/dist/internal/form/hidden-values.mjs.map +1 -0
- package/dist/internal/form/validity.mjs +3 -1
- package/dist/internal/form/validity.mjs.map +1 -1
- package/dist/internal/overlay/use-interest-dismiss.mjs +2 -1
- package/dist/internal/overlay/use-interest-dismiss.mjs.map +1 -1
- package/dist/internal/overlay/use-overlay-close.mjs +5 -3
- package/dist/internal/overlay/use-overlay-close.mjs.map +1 -1
- package/dist/internal/overlay/use-overlay-root.mjs +4 -1
- package/dist/internal/overlay/use-overlay-root.mjs.map +1 -1
- package/dist/internal/overlay/use-popover-popup.mjs +20 -7
- package/dist/internal/overlay/use-popover-popup.mjs.map +1 -1
- package/dist/internal/overlay/use-popover-trigger.d.mts +1 -1
- package/dist/internal/typeahead.mjs +52 -0
- package/dist/internal/typeahead.mjs.map +1 -0
- package/dist/{combobox → internal}/use-active-option.mjs +8 -6
- package/dist/internal/use-active-option.mjs.map +1 -0
- package/dist/{combobox → internal}/use-deferred-leave.mjs +20 -12
- package/dist/internal/use-deferred-leave.mjs.map +1 -0
- package/dist/internal/use-name-warning.mjs +57 -1
- package/dist/internal/use-name-warning.mjs.map +1 -1
- package/dist/internal/use-option-registry.mjs +70 -0
- package/dist/internal/use-option-registry.mjs.map +1 -0
- package/dist/menu/use-menu-keyboard.mjs +7 -27
- package/dist/menu/use-menu-keyboard.mjs.map +1 -1
- package/dist/multi-select/index.d.mts +37 -0
- package/dist/multi-select/index.d.mts.map +1 -0
- package/dist/multi-select/index.mjs +37 -0
- package/dist/multi-select/index.mjs.map +1 -0
- package/dist/multi-select/multi-select-context.mjs +19 -0
- package/dist/multi-select/multi-select-context.mjs.map +1 -0
- package/dist/multi-select/multi-select-group.d.mts +120 -0
- package/dist/multi-select/multi-select-group.d.mts.map +1 -0
- package/dist/multi-select/multi-select-group.mjs +111 -0
- package/dist/multi-select/multi-select-group.mjs.map +1 -0
- package/dist/multi-select/multi-select-keyboard.mjs +145 -0
- package/dist/multi-select/multi-select-keyboard.mjs.map +1 -0
- package/dist/multi-select/multi-select-label.d.mts +42 -0
- package/dist/multi-select/multi-select-label.d.mts.map +1 -0
- package/dist/multi-select/multi-select-label.mjs +41 -0
- package/dist/multi-select/multi-select-label.mjs.map +1 -0
- package/dist/multi-select/multi-select-list.d.mts +47 -0
- package/dist/multi-select/multi-select-list.d.mts.map +1 -0
- package/dist/multi-select/multi-select-list.mjs +65 -0
- package/dist/multi-select/multi-select-list.mjs.map +1 -0
- package/dist/multi-select/multi-select-option.d.mts +68 -0
- package/dist/multi-select/multi-select-option.d.mts.map +1 -0
- package/dist/multi-select/multi-select-option.mjs +93 -0
- package/dist/multi-select/multi-select-option.mjs.map +1 -0
- package/dist/multi-select/multi-select-popup.d.mts +58 -0
- package/dist/multi-select/multi-select-popup.d.mts.map +1 -0
- package/dist/multi-select/multi-select-popup.mjs +71 -0
- package/dist/multi-select/multi-select-popup.mjs.map +1 -0
- package/dist/multi-select/multi-select-root.d.mts +125 -0
- package/dist/multi-select/multi-select-root.d.mts.map +1 -0
- package/dist/multi-select/multi-select-root.mjs +257 -0
- package/dist/multi-select/multi-select-root.mjs.map +1 -0
- package/dist/multi-select/multi-select-trigger.d.mts +66 -0
- package/dist/multi-select/multi-select-trigger.d.mts.map +1 -0
- package/dist/multi-select/multi-select-trigger.mjs +169 -0
- package/dist/multi-select/multi-select-trigger.mjs.map +1 -0
- package/dist/multi-select/multi-select-value.d.mts +57 -0
- package/dist/multi-select/multi-select-value.d.mts.map +1 -0
- package/dist/multi-select/multi-select-value.mjs +41 -0
- package/dist/multi-select/multi-select-value.mjs.map +1 -0
- package/dist/number-field/number-field-root.mjs +1 -1
- package/dist/number-field/use-step-button.d.mts.map +1 -1
- package/dist/number-field/use-step-button.mjs +11 -2
- package/dist/number-field/use-step-button.mjs.map +1 -1
- package/dist/popover/popover-close.d.mts +6 -3
- package/dist/popover/popover-close.d.mts.map +1 -1
- package/dist/popover/popover-close.mjs +3 -2
- package/dist/popover/popover-close.mjs.map +1 -1
- package/dist/popover/popover-popup.mjs +1 -1
- package/dist/select/select-root.d.mts +1 -1
- package/dist/select/select-root.d.mts.map +1 -1
- package/dist/select/select-root.mjs +5 -1
- package/dist/select/select-root.mjs.map +1 -1
- package/dist/separator/index.d.mts +3 -0
- package/dist/separator/index.mjs +1 -0
- package/dist/separator/separator.d.mts +58 -0
- package/dist/separator/separator.d.mts.map +1 -0
- package/dist/separator/separator.mjs +41 -0
- package/dist/separator/separator.mjs.map +1 -0
- package/dist/slider/slider-root.mjs +1 -0
- package/dist/slider/slider-root.mjs.map +1 -1
- package/dist/toast/toast-viewport.mjs +1 -1
- package/package.json +6 -1
- package/skills/funstack-ui-knowledge/SKILL.md +14 -9
- package/dist/combobox/use-active-option.mjs.map +0 -1
- package/dist/combobox/use-deferred-leave.mjs.map +0 -1
- package/dist/combobox/use-option-registry.mjs +0 -52
- package/dist/combobox/use-option-registry.mjs.map +0 -1
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { dataAttr } from "../internal/data-attr.mjs";
|
|
3
|
+
import { useRender } from "../internal/use-render.mjs";
|
|
4
|
+
import { useElementCheck } from "../internal/use-element-check.mjs";
|
|
5
|
+
import { useMergedRefs } from "../internal/use-merged-refs.mjs";
|
|
6
|
+
import { registerTrigger } from "../internal/overlay/trigger-ref.mjs";
|
|
7
|
+
import { useFieldControl } from "../internal/form/use-field-control.mjs";
|
|
8
|
+
import { supportsUserInvalid } from "../internal/form/validity.mjs";
|
|
9
|
+
import { RESERVED_INVOKER_KEYS } from "../internal/overlay/use-popover-trigger.mjs";
|
|
10
|
+
import { optionId } from "../internal/use-option-registry.mjs";
|
|
11
|
+
import { useMultiSelectContext } from "./multi-select-context.mjs";
|
|
12
|
+
import { collectInvalid } from "../internal/form/focus-first-invalid.mjs";
|
|
13
|
+
import { useCallback } from "react";
|
|
14
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
15
|
+
//#region src/multi-select/multi-select-trigger.tsx
|
|
16
|
+
const isDev = process.env.NODE_ENV !== "production";
|
|
17
|
+
/** Visually hidden, out of the user's reach and out of the accessibility tree (B.10). */
|
|
18
|
+
const VALIDITY_STYLE = {
|
|
19
|
+
position: "absolute",
|
|
20
|
+
width: "1px",
|
|
21
|
+
height: "1px",
|
|
22
|
+
margin: "-1px",
|
|
23
|
+
padding: 0,
|
|
24
|
+
border: 0,
|
|
25
|
+
opacity: 0,
|
|
26
|
+
overflow: "hidden",
|
|
27
|
+
clipPath: "inset(50%)",
|
|
28
|
+
pointerEvents: "none"
|
|
29
|
+
};
|
|
30
|
+
const preventDefault = (event) => event.preventDefault();
|
|
31
|
+
/**
|
|
32
|
+
* The combobox itself: `<button type="button" role="combobox">`, the one Tab stop of the
|
|
33
|
+
* MultiSelect (design/components/multi-select.md B.1, B.4). DOM focus stays here while the listbox
|
|
34
|
+
* is open; the options are virtual focus through `aria-activedescendant`. After hydration it names
|
|
35
|
+
* the Popup as its invoker (`popovertarget`, written through the ref, never server-rendered), so
|
|
36
|
+
* a press on it while the listbox is shown is not a light dismiss; every click is cancelled and
|
|
37
|
+
* toggles the listbox against the state the user saw. It renders `aria-expanded` from the shown
|
|
38
|
+
* listbox (the role requires the state, and before hydration there is no invoker). With
|
|
39
|
+
* `required` it renders the **validity element** right after itself: a visually hidden one-option
|
|
40
|
+
* `<select tabindex="-1" aria-hidden="true">`, `required` while the optimistic selection is empty
|
|
41
|
+
* (B.10). It blocks a submission natively; its
|
|
42
|
+
* `invalid` is cancelled (no browser bubble) and the attempt focuses the button, so the message is
|
|
43
|
+
* `Field.Error`'s. Focus it receives passes to the button.
|
|
44
|
+
*
|
|
45
|
+
* Owned keys (conventions 1.2): `id`, `type`, `role`, `disabled`, `aria-expanded`,
|
|
46
|
+
* `aria-controls` (token-merged), `aria-activedescendant`, `aria-required`, `popovertarget`
|
|
47
|
+
* (written after hydration), `form`, `onClick`, `onKeyDown`, `onFocus`, `onBlur`,
|
|
48
|
+
* `data-open`, `data-pending`, `data-disabled`; inside a `Field.Root` also `aria-describedby`
|
|
49
|
+
* (token-merged), `aria-invalid` and `data-invalid`.
|
|
50
|
+
*
|
|
51
|
+
* @see https://ui.funstack.work/components/multi-select
|
|
52
|
+
*/
|
|
53
|
+
function MultiSelectTrigger({ disabled: ownDisabled = false, className, style, children, render, ...rest }) {
|
|
54
|
+
const part = "MultiSelect.Trigger";
|
|
55
|
+
const ctx = useMultiSelectContext(part);
|
|
56
|
+
const { popover, ids, triggerRef, validityRef, required } = ctx;
|
|
57
|
+
const disabled = ownDisabled || ctx.disabled;
|
|
58
|
+
const readValidity = useCallback(() => validityRef.current, [validityRef]);
|
|
59
|
+
const field = useFieldControl({
|
|
60
|
+
labelable: true,
|
|
61
|
+
required,
|
|
62
|
+
disabled,
|
|
63
|
+
id: rest.id,
|
|
64
|
+
component: part,
|
|
65
|
+
validityElement: required ? readValidity : void 0
|
|
66
|
+
});
|
|
67
|
+
const checkElement = useElementCheck(isDev && ((element) => element.tagName === "BUTTON" ? null : `${part}: rendered a <${element.tagName.toLowerCase()}>. Render a <button>: the popovertarget invoker relationship, which keeps a press on the Trigger from light dismissing the listbox, \`disabled\` and \`<label for>\` are defined for buttons.`));
|
|
68
|
+
const popupId = popover.ids.popup;
|
|
69
|
+
const ref = useCallback((element) => {
|
|
70
|
+
checkElement?.(element);
|
|
71
|
+
triggerRef.current = element;
|
|
72
|
+
const unregister = registerTrigger(popover.triggerRef, element, part);
|
|
73
|
+
const invoker = element.tagName === "BUTTON";
|
|
74
|
+
if (invoker) element.setAttribute("popovertarget", popupId);
|
|
75
|
+
if (isDev) queueMicrotask(() => {
|
|
76
|
+
if (!element.isConnected) return;
|
|
77
|
+
const labels = element.labels;
|
|
78
|
+
if (!(labels !== void 0 && labels !== null && labels.length > 0 || element.hasAttribute("aria-label") || element.hasAttribute("aria-labelledby"))) console.error(`${part}: the combobox has no accessible name (its content is its value). Render a MultiSelect.Label (or a Field.Label), or give the Trigger an \`aria-label\` / \`aria-labelledby\`.`);
|
|
79
|
+
});
|
|
80
|
+
return () => {
|
|
81
|
+
if (invoker) element.removeAttribute("popovertarget");
|
|
82
|
+
if (triggerRef.current === element) triggerRef.current = null;
|
|
83
|
+
unregister();
|
|
84
|
+
};
|
|
85
|
+
}, [
|
|
86
|
+
checkElement,
|
|
87
|
+
triggerRef,
|
|
88
|
+
popover.triggerRef,
|
|
89
|
+
popupId
|
|
90
|
+
]);
|
|
91
|
+
const mergedRef = useMergedRefs(ref, field.ref);
|
|
92
|
+
const validityCallbackRef = useCallback((select) => {
|
|
93
|
+
const onInvalid = (event) => {
|
|
94
|
+
const handled = event.defaultPrevented;
|
|
95
|
+
event.preventDefault();
|
|
96
|
+
if (handled) return;
|
|
97
|
+
if (supportsUserInvalid() ? select.matches(":user-invalid") : true) collectInvalid(triggerRef.current, select.validationMessage, select);
|
|
98
|
+
};
|
|
99
|
+
select.addEventListener("invalid", onInvalid);
|
|
100
|
+
return () => select.removeEventListener("invalid", onInvalid);
|
|
101
|
+
}, [triggerRef]);
|
|
102
|
+
const validityMergedRef = useMergedRefs(validityRef, validityCallbackRef);
|
|
103
|
+
const state = {
|
|
104
|
+
value: ctx.values,
|
|
105
|
+
open: popover.optimistic,
|
|
106
|
+
pending: ctx.pending,
|
|
107
|
+
disabled
|
|
108
|
+
};
|
|
109
|
+
const libraryProps = {
|
|
110
|
+
...field.attributes,
|
|
111
|
+
id: ids.trigger,
|
|
112
|
+
type: "button",
|
|
113
|
+
form: ctx.form,
|
|
114
|
+
role: "combobox",
|
|
115
|
+
disabled,
|
|
116
|
+
"aria-expanded": popover.shown,
|
|
117
|
+
"aria-controls": ids.list,
|
|
118
|
+
"aria-activedescendant": ctx.activeValue === null ? void 0 : optionId(ids.optionPrefix, ctx.activeValue),
|
|
119
|
+
"aria-required": required || void 0,
|
|
120
|
+
popoverTarget: void 0,
|
|
121
|
+
...RESERVED_INVOKER_KEYS,
|
|
122
|
+
onClick: (event) => {
|
|
123
|
+
ctx.triggerClick(event.nativeEvent);
|
|
124
|
+
},
|
|
125
|
+
onKeyDown: (event) => {
|
|
126
|
+
ctx.keyDown(event.nativeEvent);
|
|
127
|
+
},
|
|
128
|
+
onFocus: (event) => {
|
|
129
|
+
ctx.focusIn(event.nativeEvent);
|
|
130
|
+
},
|
|
131
|
+
onBlur: (event) => {
|
|
132
|
+
ctx.focusOut(event.nativeEvent);
|
|
133
|
+
},
|
|
134
|
+
"data-open": dataAttr(popover.optimistic),
|
|
135
|
+
"data-pending": dataAttr(ctx.pending),
|
|
136
|
+
"data-disabled": dataAttr(disabled)
|
|
137
|
+
};
|
|
138
|
+
const button = useRender({
|
|
139
|
+
defaultElement: "button",
|
|
140
|
+
render,
|
|
141
|
+
state,
|
|
142
|
+
className,
|
|
143
|
+
style,
|
|
144
|
+
children,
|
|
145
|
+
props: rest,
|
|
146
|
+
libraryProps,
|
|
147
|
+
ref: mergedRef
|
|
148
|
+
});
|
|
149
|
+
if (!required) return button;
|
|
150
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [button, /* @__PURE__ */ jsx("select", {
|
|
151
|
+
ref: validityMergedRef,
|
|
152
|
+
tabIndex: -1,
|
|
153
|
+
"aria-hidden": "true",
|
|
154
|
+
autoComplete: "off",
|
|
155
|
+
form: ctx.form,
|
|
156
|
+
disabled,
|
|
157
|
+
required: ctx.values.length === 0,
|
|
158
|
+
style: VALIDITY_STYLE,
|
|
159
|
+
onFocus: () => triggerRef.current?.focus(),
|
|
160
|
+
onPointerDown: preventDefault,
|
|
161
|
+
onMouseDown: preventDefault,
|
|
162
|
+
children: /* @__PURE__ */ jsx("option", { value: "" })
|
|
163
|
+
})] });
|
|
164
|
+
}
|
|
165
|
+
MultiSelectTrigger.displayName = "MultiSelectTrigger";
|
|
166
|
+
//#endregion
|
|
167
|
+
export { MultiSelectTrigger };
|
|
168
|
+
|
|
169
|
+
//# sourceMappingURL=multi-select-trigger.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multi-select-trigger.mjs","names":[],"sources":["../../src/multi-select/multi-select-trigger.tsx"],"sourcesContent":["\"use client\";\nimport { useCallback } from \"react\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n FocusEvent,\n KeyboardEvent,\n MouseEvent,\n ReactNode,\n} from \"react\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport { collectInvalid } from \"../internal/form/focus-first-invalid.js\";\nimport { useFieldControl } from \"../internal/form/use-field-control.js\";\nimport { supportsUserInvalid } from \"../internal/form/validity.js\";\nimport { RESERVED_INVOKER_KEYS } from \"../internal/overlay/use-popover-trigger.js\";\nimport { registerTrigger } from \"../internal/overlay/trigger-ref.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useElementCheck } from \"../internal/use-element-check.js\";\nimport { useMergedRefs } from \"../internal/use-merged-refs.js\";\nimport { optionId } from \"../internal/use-option-registry.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { useMultiSelectContext } from \"./multi-select-context.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * State of `MultiSelect.Trigger`, passed to the function forms of `className`, `style`,\n * `children` and `render`.\n */\nexport interface MultiSelectTriggerState {\n /** Optimistic selection, in pick order. */\n readonly value: readonly string[];\n /** Optimistic open state. */\n readonly open: boolean;\n /** The Root's `pending`: a value or open transition is in flight. */\n readonly pending: boolean;\n /** Disabled by its own prop or by the Root. */\n readonly disabled: boolean;\n}\n\n/**\n * Props of `MultiSelect.Trigger`.\n *\n * @see https://ui.funstack.work/components/multi-select\n */\nexport interface MultiSelectTriggerProps extends Omit<\n ComponentPropsWithRef<\"button\">,\n | \"type\"\n | \"role\"\n | \"onClick\"\n | \"onKeyDown\"\n | \"onFocus\"\n | \"onBlur\"\n | \"popoverTarget\"\n | \"popoverTargetAction\"\n | \"commandfor\"\n | \"command\"\n | \"aria-expanded\"\n | \"aria-controls\"\n | \"aria-activedescendant\"\n | \"aria-required\"\n | \"form\"\n | \"disabled\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /**\n * Disables this button; the Root's `disabled` does too. Native `disabled`.\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, MultiSelectTriggerState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, MultiSelectTriggerState>;\n /** Non-interactive content only (a `<button>` may not contain interactive content). Must not suspend. */\n children?: StateValue<ReactNode, MultiSelectTriggerState>;\n /** Must render a `<button>`: the `popovertarget` light-dismiss exemption is defined for buttons. */\n render?: RenderProp<ComponentPropsWithRef<\"button\">, MultiSelectTriggerState>;\n}\n\n/** Visually hidden, out of the user's reach and out of the accessibility tree (B.10). */\nconst VALIDITY_STYLE: CSSProperties = {\n position: \"absolute\",\n width: \"1px\",\n height: \"1px\",\n margin: \"-1px\",\n padding: 0,\n border: 0,\n opacity: 0,\n overflow: \"hidden\",\n clipPath: \"inset(50%)\",\n pointerEvents: \"none\",\n};\n\nconst preventDefault = (event: { preventDefault(): void }) => event.preventDefault();\n\n/**\n * The combobox itself: `<button type=\"button\" role=\"combobox\">`, the one Tab stop of the\n * MultiSelect (design/components/multi-select.md B.1, B.4). DOM focus stays here while the listbox\n * is open; the options are virtual focus through `aria-activedescendant`. After hydration it names\n * the Popup as its invoker (`popovertarget`, written through the ref, never server-rendered), so\n * a press on it while the listbox is shown is not a light dismiss; every click is cancelled and\n * toggles the listbox against the state the user saw. It renders `aria-expanded` from the shown\n * listbox (the role requires the state, and before hydration there is no invoker). With\n * `required` it renders the **validity element** right after itself: a visually hidden one-option\n * `<select tabindex=\"-1\" aria-hidden=\"true\">`, `required` while the optimistic selection is empty\n * (B.10). It blocks a submission natively; its\n * `invalid` is cancelled (no browser bubble) and the attempt focuses the button, so the message is\n * `Field.Error`'s. Focus it receives passes to the button.\n *\n * Owned keys (conventions 1.2): `id`, `type`, `role`, `disabled`, `aria-expanded`,\n * `aria-controls` (token-merged), `aria-activedescendant`, `aria-required`, `popovertarget`\n * (written after hydration), `form`, `onClick`, `onKeyDown`, `onFocus`, `onBlur`,\n * `data-open`, `data-pending`, `data-disabled`; inside a `Field.Root` also `aria-describedby`\n * (token-merged), `aria-invalid` and `data-invalid`.\n *\n * @see https://ui.funstack.work/components/multi-select\n */\nexport function MultiSelectTrigger({\n disabled: ownDisabled = false,\n className,\n style,\n children,\n render,\n ...rest\n}: MultiSelectTriggerProps) {\n const part = \"MultiSelect.Trigger\";\n const ctx = useMultiSelectContext(part);\n const { popover, ids, triggerRef, validityRef, required } = ctx;\n const disabled = ownDisabled || ctx.disabled;\n\n const readValidity = useCallback(() => validityRef.current, [validityRef]);\n // Inside a Field.Root the Trigger is the control and the validity element is the Field's\n // validity element (conventions 3.6, the NumberField case without the message mirror).\n const field = useFieldControl({\n labelable: true,\n required,\n disabled,\n id: rest.id,\n component: part,\n validityElement: required ? readValidity : undefined,\n });\n\n const checkElement = useElementCheck(\n isDev &&\n ((element) =>\n element.tagName === \"BUTTON\"\n ? null\n : `${part}: rendered a <${element.tagName.toLowerCase()}>. Render a <button>: the ` +\n \"popovertarget invoker relationship, which keeps a press on the Trigger from light \" +\n \"dismissing the listbox, `disabled` and `<label for>` are defined for buttons.\"),\n );\n const popupId = popover.ids.popup;\n const ref = useCallback(\n (element: HTMLElement) => {\n checkElement?.(element);\n triggerRef.current = element as HTMLButtonElement;\n // The popover's \"trigger\": `showPopover({ source })` anchors the listbox here and nests it\n // under the Trigger's popover ancestor (B.4).\n const unregister = registerTrigger(popover.triggerRef, element, part);\n // After hydration the button is the popup's invoker (B.4, combobox.md 3.3): the platform's\n // light dismiss exempts a press on an invoker of the open popover. Never server-rendered,\n // so a click before hydration opens nothing.\n const invoker = element.tagName === \"BUTTON\";\n if (invoker) element.setAttribute(\"popovertarget\", popupId);\n if (isDev) {\n // A combobox's name does not come from its content (B.9).\n queueMicrotask(() => {\n if (!element.isConnected) return;\n const labels = (element as HTMLButtonElement).labels;\n const named =\n (labels !== undefined && labels !== null && labels.length > 0) ||\n element.hasAttribute(\"aria-label\") ||\n element.hasAttribute(\"aria-labelledby\");\n if (!named) {\n console.error(\n `${part}: the combobox has no accessible name (its content is its value). Render a ` +\n \"MultiSelect.Label (or a Field.Label), or give the Trigger an `aria-label` / \" +\n \"`aria-labelledby`.\",\n );\n }\n });\n }\n return () => {\n if (invoker) element.removeAttribute(\"popovertarget\");\n if (triggerRef.current === element) triggerRef.current = null;\n unregister();\n };\n },\n [checkElement, triggerRef, popover.triggerRef, popupId],\n );\n const mergedRef = useMergedRefs<HTMLElement>(ref, field.ref);\n\n // The browser's bubble is never shown (B.16, the fallback of memo/architect/\n // select-multiple-notes.md): Firefox keeps the bubble of the hidden element after the focus\n // hand-over, over the place where the listbox opens, and it takes the pointer input there. The\n // `invalid` is cancelled and a submission attempt focuses the Trigger, through the same\n // first-invalid collector a Field uses; `Field.Error` shows the message in the page.\n const validityCallbackRef = useCallback(\n (select: HTMLSelectElement) => {\n const onInvalid = (event: Event) => {\n // Inside a Field with a Field.Error, the Field's capture listener (it runs first) has\n // cancelled the event and reported the Trigger already: a second report would start a\n // new batch of the collector (focus out of document order, a stray announcement).\n const handled = event.defaultPrevented;\n event.preventDefault();\n if (handled) return;\n // A submission attempt sets user validity first; `checkValidity()` does not.\n const attempt = supportsUserInvalid() ? select.matches(\":user-invalid\") : true;\n if (attempt) collectInvalid(triggerRef.current, select.validationMessage, select);\n };\n select.addEventListener(\"invalid\", onInvalid);\n return () => select.removeEventListener(\"invalid\", onInvalid);\n },\n [triggerRef],\n );\n const validityMergedRef = useMergedRefs<HTMLSelectElement>(validityRef, validityCallbackRef);\n\n const state: MultiSelectTriggerState = {\n value: ctx.values,\n open: popover.optimistic,\n pending: ctx.pending,\n disabled,\n };\n\n const libraryProps: ComponentPropsWithRef<\"button\"> & DataAttributes = {\n ...field.attributes,\n id: ids.trigger,\n type: \"button\",\n // The form owner of the reset listener when there is neither `name` nor `required` (B.10).\n form: ctx.form,\n role: \"combobox\",\n disabled,\n // Shown (the listbox is in the top layer); `data-open` is the optimistic one (B.9).\n \"aria-expanded\": popover.shown,\n \"aria-controls\": ids.list,\n \"aria-activedescendant\":\n ctx.activeValue === null ? undefined : optionId(ids.optionPrefix, ctx.activeValue),\n \"aria-required\": required || undefined,\n // Owned: the ref writes `popovertarget` after hydration; a render element sets none of these.\n popoverTarget: undefined,\n ...RESERVED_INVOKER_KEYS,\n onClick: (event: MouseEvent<HTMLButtonElement>) => {\n ctx.triggerClick(event.nativeEvent);\n },\n onKeyDown: (event: KeyboardEvent<HTMLButtonElement>) => {\n ctx.keyDown(event.nativeEvent);\n },\n onFocus: (event: FocusEvent<HTMLButtonElement>) => {\n ctx.focusIn(event.nativeEvent);\n },\n onBlur: (event: FocusEvent<HTMLButtonElement>) => {\n ctx.focusOut(event.nativeEvent);\n },\n \"data-open\": dataAttr(popover.optimistic),\n \"data-pending\": dataAttr(ctx.pending),\n \"data-disabled\": dataAttr(disabled),\n };\n\n const button = useRender<ComponentPropsWithRef<\"button\">, MultiSelectTriggerState>({\n defaultElement: \"button\",\n render,\n state,\n className,\n style,\n children,\n props: rest,\n libraryProps,\n ref: mergedRef,\n });\n\n if (!required) return button;\n return (\n <>\n {button}\n {/* The validity element (B.10): no name (it posts nothing), one empty option, `required`\n only while nothing is selected. A hidden input or a button cannot hold validity. */}\n <select\n ref={validityMergedRef}\n tabIndex={-1}\n aria-hidden=\"true\"\n autoComplete=\"off\"\n form={ctx.form}\n disabled={disabled}\n required={ctx.values.length === 0}\n style={VALIDITY_STYLE}\n onFocus={() => triggerRef.current?.focus()}\n onPointerDown={preventDefault}\n onMouseDown={preventDefault}\n >\n <option value=\"\" />\n </select>\n </>\n );\n}\n\nMultiSelectTrigger.displayName = \"MultiSelectTrigger\";\n"],"mappings":";;;;;;;;;;;;;;;AAwBA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;AA6DvC,MAAM,iBAAgC;CACpC,UAAU;CACV,OAAO;CACP,Q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ACP;EACA,KAAK;CACP,CAAC;CAED,IAAI,CAAC,UAAU,OAAO;CACtB,OACE,qBAAA,UAAA,EAAA,UAAA,CACG,QAGD,oBAAC,UAAD;EACE,KAAK;EACL,UAAU;EACV,eAAY;EACZ,cAAa;EACb,MAAM,IAAI;EACA;EACV,UAAU,IAAI,OAAO,WAAW;EAChC,OAAO;EACP,eAAe,WAAW,SAAS,MAAM;EACzC,eAAe;EACf,aAAa;EAEb,UAAA,oBAAC,UAAD,EAAQ,OAAM,GAAI,CAAA;CACZ,CAAA,CACR,EAAA,CAAA;AAEN;AAEA,mBAAmB,cAAc"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { RenderProp, StateValue } from "../internal/types.mjs";
|
|
2
|
+
import { CSSProperties, ComponentPropsWithRef, ReactNode } from "react";
|
|
3
|
+
//#region src/multi-select/multi-select-value.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* State of `MultiSelect.Value`, passed to the function forms of `className`, `style`, `children`
|
|
6
|
+
* and `render`.
|
|
7
|
+
*/
|
|
8
|
+
export interface MultiSelectValueState {
|
|
9
|
+
/** Optimistic selection, in pick order. */
|
|
10
|
+
readonly value: readonly string[];
|
|
11
|
+
/**
|
|
12
|
+
* For each value, the text of its option as the library last saw it; `undefined` if it never
|
|
13
|
+
* saw one (a default value before the listbox first opened, and always in the server HTML).
|
|
14
|
+
*/
|
|
15
|
+
readonly labels: readonly (string | undefined)[];
|
|
16
|
+
/** The Root's `disabled` (or the Field's). */
|
|
17
|
+
readonly disabled: boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Props of `MultiSelect.Value`.
|
|
21
|
+
*
|
|
22
|
+
* @see https://ui.funstack.work/components/multi-select
|
|
23
|
+
*/
|
|
24
|
+
export interface MultiSelectValueProps extends Omit<ComponentPropsWithRef<"span">, "className" | "style" | "children"> {
|
|
25
|
+
/** Rendered by the default content while the selection is empty (`data-placeholder`). */
|
|
26
|
+
placeholder?: ReactNode;
|
|
27
|
+
/** Class name, or a function of the part's state that returns one. */
|
|
28
|
+
className?: StateValue<string | undefined, MultiSelectValueState>;
|
|
29
|
+
/** Inline style, or a function of the part's state that returns one. */
|
|
30
|
+
style?: StateValue<CSSProperties | undefined, MultiSelectValueState>;
|
|
31
|
+
/**
|
|
32
|
+
* The summary, usually a function of `{ value }` with your own names (the labels are unknown
|
|
33
|
+
* until an option was seen). Rendered from optimistic state; must not suspend.
|
|
34
|
+
*
|
|
35
|
+
* @defaultValue `placeholder` while empty, else each `labels[i] ?? value[i]` joined with `", "`
|
|
36
|
+
*/
|
|
37
|
+
children?: StateValue<ReactNode, MultiSelectValueState>;
|
|
38
|
+
/** Replace the default `<span>` (element form) or take over rendering (function form). */
|
|
39
|
+
render?: RenderProp<ComponentPropsWithRef<"span">, MultiSelectValueState>;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* What the Trigger shows (design/components/multi-select.md B.7): a `<span>` inside
|
|
43
|
+
* `MultiSelect.Trigger`, with `data-placeholder` while the selection is empty. Without
|
|
44
|
+
* `children` it renders `placeholder` while the selection is empty, else the labels of the label
|
|
45
|
+
* cache joined with `", "`, the raw value for a value whose option was never mounted. The Trigger's text content is the combobox's value
|
|
46
|
+
* for assistive technology.
|
|
47
|
+
*
|
|
48
|
+
* Owned key (conventions 1.2): `data-placeholder`.
|
|
49
|
+
*
|
|
50
|
+
* @see https://ui.funstack.work/components/multi-select
|
|
51
|
+
*/
|
|
52
|
+
export declare function MultiSelectValue({ placeholder, className, style, children, render, ...rest }: MultiSelectValueProps): ReactNode;
|
|
53
|
+
export declare namespace MultiSelectValue {
|
|
54
|
+
var displayName: string;
|
|
55
|
+
}
|
|
56
|
+
//#endregion
|
|
57
|
+
//# sourceMappingURL=multi-select-value.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multi-select-value.d.mts","names":[],"sources":["../../src/multi-select/multi-select-value.tsx"],"mappings":";;;;;;;iBAYiB;;WAEN;;;;;WAKA;;WAEA;;;;;;;iBAQM,8BAA8B,KAC7C;;EAIA,cAAc;;EAEd,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;;;;;;EAO9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,+BAA+B;;;;;;;;;;;;;wBAcrC,mBACd,aACA,WACA,OACA,UACA,WACG,QACF,wBAAqB;yBAPR"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { dataAttr } from "../internal/data-attr.mjs";
|
|
3
|
+
import { useRender } from "../internal/use-render.mjs";
|
|
4
|
+
import { useMultiSelectContext } from "./multi-select-context.mjs";
|
|
5
|
+
//#region src/multi-select/multi-select-value.tsx
|
|
6
|
+
/**
|
|
7
|
+
* What the Trigger shows (design/components/multi-select.md B.7): a `<span>` inside
|
|
8
|
+
* `MultiSelect.Trigger`, with `data-placeholder` while the selection is empty. Without
|
|
9
|
+
* `children` it renders `placeholder` while the selection is empty, else the labels of the label
|
|
10
|
+
* cache joined with `", "`, the raw value for a value whose option was never mounted. The Trigger's text content is the combobox's value
|
|
11
|
+
* for assistive technology.
|
|
12
|
+
*
|
|
13
|
+
* Owned key (conventions 1.2): `data-placeholder`.
|
|
14
|
+
*
|
|
15
|
+
* @see https://ui.funstack.work/components/multi-select
|
|
16
|
+
*/
|
|
17
|
+
function MultiSelectValue({ placeholder, className, style, children, render, ...rest }) {
|
|
18
|
+
const ctx = useMultiSelectContext("MultiSelect.Value");
|
|
19
|
+
const state = {
|
|
20
|
+
value: ctx.values,
|
|
21
|
+
labels: ctx.labels,
|
|
22
|
+
disabled: ctx.disabled
|
|
23
|
+
};
|
|
24
|
+
const empty = state.value.length === 0;
|
|
25
|
+
const libraryProps = { "data-placeholder": dataAttr(empty) };
|
|
26
|
+
return useRender({
|
|
27
|
+
defaultElement: "span",
|
|
28
|
+
render,
|
|
29
|
+
state,
|
|
30
|
+
className,
|
|
31
|
+
style,
|
|
32
|
+
children: children ?? ((s) => empty ? placeholder : s.value.map((v, i) => s.labels[i] ?? v).join(", ")),
|
|
33
|
+
props: rest,
|
|
34
|
+
libraryProps
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
MultiSelectValue.displayName = "MultiSelectValue";
|
|
38
|
+
//#endregion
|
|
39
|
+
export { MultiSelectValue };
|
|
40
|
+
|
|
41
|
+
//# sourceMappingURL=multi-select-value.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multi-select-value.mjs","names":[],"sources":["../../src/multi-select/multi-select-value.tsx"],"sourcesContent":["\"use client\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { useMultiSelectContext } from \"./multi-select-context.js\";\n\n/**\n * State of `MultiSelect.Value`, passed to the function forms of `className`, `style`, `children`\n * and `render`.\n */\nexport interface MultiSelectValueState {\n /** Optimistic selection, in pick order. */\n readonly value: readonly string[];\n /**\n * For each value, the text of its option as the library last saw it; `undefined` if it never\n * saw one (a default value before the listbox first opened, and always in the server HTML).\n */\n readonly labels: readonly (string | undefined)[];\n /** The Root's `disabled` (or the Field's). */\n readonly disabled: boolean;\n}\n\n/**\n * Props of `MultiSelect.Value`.\n *\n * @see https://ui.funstack.work/components/multi-select\n */\nexport interface MultiSelectValueProps extends Omit<\n ComponentPropsWithRef<\"span\">,\n \"className\" | \"style\" | \"children\"\n> {\n /** Rendered by the default content while the selection is empty (`data-placeholder`). */\n placeholder?: ReactNode;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, MultiSelectValueState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, MultiSelectValueState>;\n /**\n * The summary, usually a function of `{ value }` with your own names (the labels are unknown\n * until an option was seen). Rendered from optimistic state; must not suspend.\n *\n * @defaultValue `placeholder` while empty, else each `labels[i] ?? value[i]` joined with `\", \"`\n */\n children?: StateValue<ReactNode, MultiSelectValueState>;\n /** Replace the default `<span>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"span\">, MultiSelectValueState>;\n}\n\n/**\n * What the Trigger shows (design/components/multi-select.md B.7): a `<span>` inside\n * `MultiSelect.Trigger`, with `data-placeholder` while the selection is empty. Without\n * `children` it renders `placeholder` while the selection is empty, else the labels of the label\n * cache joined with `\", \"`, the raw value for a value whose option was never mounted. The Trigger's text content is the combobox's value\n * for assistive technology.\n *\n * Owned key (conventions 1.2): `data-placeholder`.\n *\n * @see https://ui.funstack.work/components/multi-select\n */\nexport function MultiSelectValue({\n placeholder,\n className,\n style,\n children,\n render,\n ...rest\n}: MultiSelectValueProps) {\n const ctx = useMultiSelectContext(\"MultiSelect.Value\");\n const state: MultiSelectValueState = {\n value: ctx.values,\n labels: ctx.labels,\n disabled: ctx.disabled,\n };\n const empty = state.value.length === 0;\n const libraryProps: ComponentPropsWithRef<\"span\"> & DataAttributes = {\n \"data-placeholder\": dataAttr(empty),\n };\n return useRender<ComponentPropsWithRef<\"span\">, MultiSelectValueState>({\n defaultElement: \"span\",\n render,\n state,\n className,\n style,\n children:\n children ??\n ((s) => (empty ? placeholder : s.value.map((v, i) => s.labels[i] ?? v).join(\", \"))),\n props: rest,\n libraryProps,\n });\n}\n\nMultiSelectValue.displayName = \"MultiSelectValue\";\n"],"mappings":";;;;;;;;;;;;;;;;AA6DA,SAAgB,iBAAiB,EAC/B,aACA,WACA,OACA,UACA,QACA,GAAG,QACqB;CACxB,MAAM,MAAM,sBAAsB,mBAAmB;CACrD,MAAM,QAA+B;EACnC,OAAO,IAAI;EACX,QAAQ,IAAI;EACZ,UAAU,IAAI;CAChB;CACA,MAAM,QAAQ,MAAM,MAAM,WAAW;CACrC,MAAM,eAA+D,EACnE,oBAAoB,SAAS,KAAK,EACpC;CACA,OAAO,UAAgE;EACrE,gBAAgB;EAChB;EACA;EACA;EACA;EACA,UACE,cACE,MAAO,QAAQ,cAAc,EAAE,MAAM,KAAK,GAAG,MAAM,EAAE,OAAO,MAAM,CAAC,CAAC,CAAC,KAAK,IAAI;EAClF,OAAO;EACP;CACF,CAAC;AACH;AAEA,iBAAiB,cAAc"}
|
|
@@ -8,8 +8,8 @@ import { FieldContext } from "../internal/form/field-context.mjs";
|
|
|
8
8
|
import { resolveFieldDefaults, useFieldValueChange } from "../internal/form/use-field-control.mjs";
|
|
9
9
|
import { useResetTarget } from "../internal/form/use-form-reset.mjs";
|
|
10
10
|
import { useNativeGroupReconciliation } from "../internal/form/use-native-group-reconciliation.mjs";
|
|
11
|
-
import { announce } from "../internal/announce.mjs";
|
|
12
11
|
import { useRegisterCount } from "../internal/use-register-count.mjs";
|
|
12
|
+
import { announce } from "../internal/announce.mjs";
|
|
13
13
|
import { useStepCommit } from "../internal/action/use-step-commit.mjs";
|
|
14
14
|
import { keyStep, stepValue } from "./number-field-arithmetic.mjs";
|
|
15
15
|
import { NumberFieldContext } from "./number-field-context.mjs";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-step-button.d.mts","names":[],"sources":["../../src/number-field/use-step-button.ts"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"use-step-button.d.mts","names":[],"sources":["../../src/number-field/use-step-button.ts"],"mappings":";;;;;;;;iBAwKiB;;WAEN;;WAEA;;;;;;;iBAQM,kCAAkC,KACjD;;;;;;;EAkBA;;EAEA,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,iCAAiC;;;;;;;YAQ3C,4BAA4B"}
|
|
@@ -12,6 +12,15 @@ const isDev = process.env.NODE_ENV !== "production";
|
|
|
12
12
|
const HOLD_DELAY = 400;
|
|
13
13
|
const HOLD_INTERVAL = 60;
|
|
14
14
|
/**
|
|
15
|
+
* Disabled by the platform rather than by a prop: an ancestor `<fieldset disabled>` disables the
|
|
16
|
+
* button and the visible input, which then match `:disabled` while the part's state does not see
|
|
17
|
+
* it. Pointer events still reach a natively disabled button (Chromium and Firefox, #180), so the
|
|
18
|
+
* press handler reads this at the press (conventions 3.6).
|
|
19
|
+
*/
|
|
20
|
+
function inheritsDisabled(ctx, element) {
|
|
21
|
+
return element.matches(":disabled") || (ctx.visibleRef.current?.matches(":disabled") ?? false);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
15
24
|
* The press-and-hold of `NumberField.Increment` / `Decrement` (design 4.3): one step at
|
|
16
25
|
* `pointerdown`, a repeat after 400 ms then every 60 ms, one commit at the release
|
|
17
26
|
* (`pointerup`, `pointercancel`, `lostpointercapture`, or `blur` on the window). The press is
|
|
@@ -38,7 +47,7 @@ function useStepButton(ctx, direction, disabled) {
|
|
|
38
47
|
}, []);
|
|
39
48
|
const onPointerDown = (event) => {
|
|
40
49
|
if (event.button !== 0 || !event.isPrimary) return;
|
|
41
|
-
if (disabled) {
|
|
50
|
+
if (disabled || inheritsDisabled(ctx, event.currentTarget)) {
|
|
42
51
|
event.preventDefault();
|
|
43
52
|
return;
|
|
44
53
|
}
|
|
@@ -105,7 +114,7 @@ function useStepButton(ctx, direction, disabled) {
|
|
|
105
114
|
pointerSeen.current = false;
|
|
106
115
|
return;
|
|
107
116
|
}
|
|
108
|
-
if (disabled) return;
|
|
117
|
+
if (disabled || inheritsDisabled(ctx, event.currentTarget)) return;
|
|
109
118
|
ctx.activate(direction, event.nativeEvent);
|
|
110
119
|
};
|
|
111
120
|
const onContextMenu = (event) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-step-button.mjs","names":[],"sources":["../../src/number-field/use-step-button.ts"],"sourcesContent":["\"use client\";\nimport { useEffect, useRef } from \"react\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n MouseEvent as ReactMouseEvent,\n PointerEvent as ReactPointerEvent,\n ReactNode,\n} from \"react\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { disabledButton, rendersButton, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { isAtBound } from \"./number-field-arithmetic.js\";\nimport { useNumberFieldContext } from \"./number-field-context.js\";\nimport type { NumberFieldContextValue, StepDirection } from \"./number-field-context.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** First repeat after the press, then the interval between repeats (Base UI, React Aria). */\nconst HOLD_DELAY = 400;\nconst HOLD_INTERVAL = 60;\n\ninterface ActiveHold {\n readonly pointerId: number;\n readonly detach: () => void;\n}\n\nexport interface StepButtonHandlers {\n readonly onPointerDown: (event: ReactPointerEvent<HTMLElement>) => void;\n readonly onClick: (event: ReactMouseEvent<HTMLElement>) => void;\n readonly onContextMenu: (event: ReactMouseEvent<HTMLElement>) => void;\n}\n\n/**\n * The press-and-hold of `NumberField.Increment` / `Decrement` (design 4.3): one step at\n * `pointerdown`, a repeat after 400 ms then every 60 ms, one commit at the release\n * (`pointerup`, `pointercancel`, `lostpointercapture`, or `blur` on the window). The press is\n * `preventDefault()`ed so focus stays where it is. A `click` with no pointer gesture before it\n * (assistive technology: `detail === 0`) is a one-step gesture.\n */\nexport function useStepButton(\n ctx: NumberFieldContextValue,\n direction: StepDirection,\n disabled: boolean,\n): StepButtonHandlers {\n const active = useRef<ActiveHold | null>(null);\n /** A pointer gesture started on this button; the click that follows it is not an activation. */\n const pointerSeen = useRef(false);\n const latest = useRef({ ctx, disabled });\n useEffect(() => {\n latest.current = { ctx, disabled };\n });\n\n // An unmount mid-hold leaves no timer or listener behind.\n useEffect(\n () => () => {\n active.current?.detach();\n active.current = null;\n },\n [],\n );\n\n const onPointerDown = (event: ReactPointerEvent<HTMLElement>): void => {\n if (event.button !== 0 || !event.isPrimary) return;\n if (disabled) {\n // A focusable disabled render (`aria-disabled`) must not take focus from the input\n // either; native `disabled` focused nothing.\n event.preventDefault();\n return;\n }\n if (active.current !== null) return;\n const element = event.currentTarget;\n const native = event.nativeEvent;\n // No focus move off the input, no touch keyboard, no text selection.\n event.preventDefault();\n pointerSeen.current = true;\n const pointerId = native.pointerId;\n try {\n element.setPointerCapture(pointerId);\n } catch {\n // An inactive pointer id (a synthetic event): the hold still follows the element.\n }\n\n let timer: ReturnType<typeof setTimeout> | undefined;\n const view = element.ownerDocument.defaultView;\n const detach = (): void => {\n if (timer !== undefined) clearTimeout(timer);\n timer = undefined;\n element.removeEventListener(\"pointerup\", onEnd);\n element.removeEventListener(\"pointercancel\", onEnd);\n element.removeEventListener(\"lostpointercapture\", onEnd);\n view?.removeEventListener(\"blur\", onBlur);\n if (active.current?.pointerId === pointerId) active.current = null;\n // A click that follows this release (same task, or a touch tap later) is ignored; an\n // activation without a pointer afterwards is not.\n setTimeout(() => {\n pointerSeen.current = false;\n }, 0);\n };\n function onEnd(endEvent: Event): void {\n if ((endEvent as PointerEvent).pointerId !== pointerId) return;\n detach();\n latest.current.ctx.endHold(direction, endEvent);\n }\n function onBlur(blurEvent: Event): void {\n detach();\n latest.current.ctx.endHold(direction, blurEvent);\n }\n const tick = (): void => {\n timer = setTimeout(() => {\n timer = undefined;\n if (latest.current.ctx.tickHold(direction, undefined)) tick();\n else detach();\n }, HOLD_INTERVAL);\n };\n\n if (!ctx.beginHold(direction, native)) {\n // The first step reached the bound: the hold already committed.\n detach();\n return;\n }\n element.addEventListener(\"pointerup\", onEnd);\n element.addEventListener(\"pointercancel\", onEnd);\n element.addEventListener(\"lostpointercapture\", onEnd);\n view?.addEventListener(\"blur\", onBlur);\n active.current = { pointerId, detach };\n timer = setTimeout(() => {\n timer = undefined;\n if (latest.current.ctx.tickHold(direction, undefined)) tick();\n else detach();\n }, HOLD_DELAY);\n };\n\n const onClick = (event: ReactMouseEvent<HTMLElement>): void => {\n // A disabled link or component render (`aria-disabled`) must not navigate either.\n if (disabled) event.preventDefault();\n if (pointerSeen.current || active.current !== null || event.detail !== 0) {\n pointerSeen.current = false;\n return;\n }\n if (disabled) return;\n ctx.activate(direction, event.nativeEvent);\n };\n\n const onContextMenu = (event: ReactMouseEvent<HTMLElement>): void => {\n // A touch long-press would open the context menu mid-hold.\n if (active.current !== null) event.preventDefault();\n };\n\n return { onPointerDown, onClick, onContextMenu };\n}\n\n/**\n * State of `NumberField.Increment`, `NumberField.Decrement`, passed to the function forms of\n * `className`, `style`, `children` and `render`.\n */\nexport interface NumberFieldButtonState {\n /** The Root is pending and the latest step or commit came from this button. */\n readonly pending: boolean;\n /** The prop, the Root's `disabled` or `readOnly`, or the next step would change nothing. */\n readonly disabled: boolean;\n}\n\n/**\n * Props of `NumberField.Increment` (`NumberField.Decrement` takes the same props).\n *\n * @see https://ui.funstack.work/components/number-field\n */\nexport interface NumberFieldIncrementProps extends Omit<\n ComponentPropsWithRef<\"button\">,\n | \"type\"\n | \"tabIndex\"\n | \"disabled\"\n | \"onPointerDown\"\n | \"onClick\"\n | \"onContextMenu\"\n | \"aria-controls\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /**\n * Never steps. Native `disabled` on a `<button>` (also at the bound and under `readOnly`); with\n * a link or component `render`, `aria-disabled=\"true\"` instead.\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, NumberFieldButtonState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, NumberFieldButtonState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, NumberFieldButtonState>;\n /** Replace the default `<button>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"button\">, NumberFieldButtonState>;\n}\n\n/**\n * Props of `NumberField.Decrement`: the same as `NumberFieldIncrementProps`.\n *\n * @see https://ui.funstack.work/components/number-field\n */\nexport type NumberFieldDecrementProps = NumberFieldIncrementProps;\n\nconst LABELS: Record<StepDirection, string> = { increment: \"Increase\", decrement: \"Decrease\" };\n\n/** Shared by `NumberField.Increment` and `NumberField.Decrement` (design 3.3, 4.3). */\nexport function useStepButtonElement(\n direction: StepDirection,\n part: string,\n props: NumberFieldIncrementProps,\n): ReactNode {\n const { disabled: disabledProp = false, className, style, children, render, ...rest } = props;\n const ctx = useNumberFieldContext(part);\n const { state } = ctx;\n const atBound = isAtBound(ctx.stepBase, direction === \"increment\" ? 1 : -1, ctx.bounds);\n const disabled = disabledProp || state.disabled || state.readOnly || atBound;\n const pending = ctx.pendingSource === direction;\n const buttonState: NumberFieldButtonState = { pending, disabled };\n const handlers = useStepButton(ctx, direction, disabled);\n\n useDevWarning(\n rest[\"aria-label\"] === \"\",\n isDev &&\n `${part}: \\`aria-label=\"\"\\` leaves the button without a name. Pass the label text instead ` +\n `(the default is \"${LABELS[direction]}\").`,\n );\n\n // The built-in name is a default the consumer's `aria-label` or `aria-labelledby` replaces.\n const props$ = {\n ...(rest[\"aria-labelledby\"] === undefined ? { \"aria-label\": LABELS[direction] } : {}),\n ...rest,\n };\n\n return useRender<ComponentPropsWithRef<\"button\">, NumberFieldButtonState>({\n defaultElement: \"button\",\n render,\n state: buttonState,\n className,\n style,\n children,\n props: props$,\n libraryProps: {\n ...(rendersButton(render) ? { type: \"button\" as const } : {}),\n tabIndex: -1,\n \"aria-controls\": ctx.inputId,\n // A link or component render: native `disabled` would mean nothing on a link; the press and\n // click handlers refuse, so `aria-disabled`. The at-bound case follows the same branch.\n ...disabledButton(render, disabled).props,\n onPointerDown: handlers.onPointerDown,\n onClick: handlers.onClick,\n onContextMenu: handlers.onContextMenu,\n \"data-pending\": dataAttr(pending),\n \"data-disabled\": dataAttr(disabled),\n } as Partial<ComponentPropsWithRef<\"button\">> & DataAttributes,\n });\n}\n"],"mappings":";;;;;;;;;AAkBA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;AAGvC,MAAM,aAAa;AACnB,MAAM,gBAAgB;;;;;;;;AAoBtB,SAAgB,cACd,KACA,WACA,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AQ;CAEvD,cACE,KAAK,kBAAkB,IACvB,SACE,GAAG,KAAK,qGACc,OAAO,WAAW,IAC5C;CAGA,MAAM,SAAS;EACb,GAAI,KAAK,uBAAuB,KAAA,IAAY,EAAE,cAAc,OAAO,WAAW,IAAI,CAAC;EACnF,GAAG;CACL;CAEA,OAAO,UAAmE;EACxE,gBAAgB;EAChB;EACA,OAAO;EACP;EACA;EACA;EACA,OAAO;EACP,cAAc;GACZ,GAAI,cAAc,MAAM,IAAI,EAAE,MAAM,SAAkB,IAAI,CAAC;GAC3D,UAAU;GACV,iBAAiB,IAAI;GAGrB,GAAG,eAAe,QAAQ,QAAQ,CAAC,CAAC;GACpC,eAAe,SAAS;GACxB,SAAS,SAAS;GAClB,eAAe,SAAS;GACxB,gBAAgB,SAAS,OAAO;GAChC,iBAAiB,SAAS,QAAQ;EACpC;CACF,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"use-step-button.mjs","names":[],"sources":["../../src/number-field/use-step-button.ts"],"sourcesContent":["\"use client\";\nimport { useEffect, useRef } from \"react\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n MouseEvent as ReactMouseEvent,\n PointerEvent as ReactPointerEvent,\n ReactNode,\n} from \"react\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { disabledButton, rendersButton, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { isAtBound } from \"./number-field-arithmetic.js\";\nimport { useNumberFieldContext } from \"./number-field-context.js\";\nimport type { NumberFieldContextValue, StepDirection } from \"./number-field-context.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** First repeat after the press, then the interval between repeats (Base UI, React Aria). */\nconst HOLD_DELAY = 400;\nconst HOLD_INTERVAL = 60;\n\ninterface ActiveHold {\n readonly pointerId: number;\n readonly detach: () => void;\n}\n\nexport interface StepButtonHandlers {\n readonly onPointerDown: (event: ReactPointerEvent<HTMLElement>) => void;\n readonly onClick: (event: ReactMouseEvent<HTMLElement>) => void;\n readonly onContextMenu: (event: ReactMouseEvent<HTMLElement>) => void;\n}\n\n/**\n * Disabled by the platform rather than by a prop: an ancestor `<fieldset disabled>` disables the\n * button and the visible input, which then match `:disabled` while the part's state does not see\n * it. Pointer events still reach a natively disabled button (Chromium and Firefox, #180), so the\n * press handler reads this at the press (conventions 3.6).\n */\nfunction inheritsDisabled(ctx: NumberFieldContextValue, element: HTMLElement): boolean {\n return element.matches(\":disabled\") || (ctx.visibleRef.current?.matches(\":disabled\") ?? false);\n}\n\n/**\n * The press-and-hold of `NumberField.Increment` / `Decrement` (design 4.3): one step at\n * `pointerdown`, a repeat after 400 ms then every 60 ms, one commit at the release\n * (`pointerup`, `pointercancel`, `lostpointercapture`, or `blur` on the window). The press is\n * `preventDefault()`ed so focus stays where it is. A `click` with no pointer gesture before it\n * (assistive technology: `detail === 0`) is a one-step gesture.\n */\nexport function useStepButton(\n ctx: NumberFieldContextValue,\n direction: StepDirection,\n disabled: boolean,\n): StepButtonHandlers {\n const active = useRef<ActiveHold | null>(null);\n /** A pointer gesture started on this button; the click that follows it is not an activation. */\n const pointerSeen = useRef(false);\n const latest = useRef({ ctx, disabled });\n useEffect(() => {\n latest.current = { ctx, disabled };\n });\n\n // An unmount mid-hold leaves no timer or listener behind.\n useEffect(\n () => () => {\n active.current?.detach();\n active.current = null;\n },\n [],\n );\n\n const onPointerDown = (event: ReactPointerEvent<HTMLElement>): void => {\n if (event.button !== 0 || !event.isPrimary) return;\n if (disabled || inheritsDisabled(ctx, event.currentTarget)) {\n // A focusable disabled render (`aria-disabled`) must not take focus from the input\n // either; native `disabled` focused nothing.\n event.preventDefault();\n return;\n }\n if (active.current !== null) return;\n const element = event.currentTarget;\n const native = event.nativeEvent;\n // No focus move off the input, no touch keyboard, no text selection.\n event.preventDefault();\n pointerSeen.current = true;\n const pointerId = native.pointerId;\n try {\n element.setPointerCapture(pointerId);\n } catch {\n // An inactive pointer id (a synthetic event): the hold still follows the element.\n }\n\n let timer: ReturnType<typeof setTimeout> | undefined;\n const view = element.ownerDocument.defaultView;\n const detach = (): void => {\n if (timer !== undefined) clearTimeout(timer);\n timer = undefined;\n element.removeEventListener(\"pointerup\", onEnd);\n element.removeEventListener(\"pointercancel\", onEnd);\n element.removeEventListener(\"lostpointercapture\", onEnd);\n view?.removeEventListener(\"blur\", onBlur);\n if (active.current?.pointerId === pointerId) active.current = null;\n // A click that follows this release (same task, or a touch tap later) is ignored; an\n // activation without a pointer afterwards is not.\n setTimeout(() => {\n pointerSeen.current = false;\n }, 0);\n };\n function onEnd(endEvent: Event): void {\n if ((endEvent as PointerEvent).pointerId !== pointerId) return;\n detach();\n latest.current.ctx.endHold(direction, endEvent);\n }\n function onBlur(blurEvent: Event): void {\n detach();\n latest.current.ctx.endHold(direction, blurEvent);\n }\n const tick = (): void => {\n timer = setTimeout(() => {\n timer = undefined;\n if (latest.current.ctx.tickHold(direction, undefined)) tick();\n else detach();\n }, HOLD_INTERVAL);\n };\n\n if (!ctx.beginHold(direction, native)) {\n // The first step reached the bound: the hold already committed.\n detach();\n return;\n }\n element.addEventListener(\"pointerup\", onEnd);\n element.addEventListener(\"pointercancel\", onEnd);\n element.addEventListener(\"lostpointercapture\", onEnd);\n view?.addEventListener(\"blur\", onBlur);\n active.current = { pointerId, detach };\n timer = setTimeout(() => {\n timer = undefined;\n if (latest.current.ctx.tickHold(direction, undefined)) tick();\n else detach();\n }, HOLD_DELAY);\n };\n\n const onClick = (event: ReactMouseEvent<HTMLElement>): void => {\n // A disabled link or component render (`aria-disabled`) must not navigate either.\n if (disabled) event.preventDefault();\n if (pointerSeen.current || active.current !== null || event.detail !== 0) {\n pointerSeen.current = false;\n return;\n }\n if (disabled || inheritsDisabled(ctx, event.currentTarget)) return;\n ctx.activate(direction, event.nativeEvent);\n };\n\n const onContextMenu = (event: ReactMouseEvent<HTMLElement>): void => {\n // A touch long-press would open the context menu mid-hold.\n if (active.current !== null) event.preventDefault();\n };\n\n return { onPointerDown, onClick, onContextMenu };\n}\n\n/**\n * State of `NumberField.Increment`, `NumberField.Decrement`, passed to the function forms of\n * `className`, `style`, `children` and `render`.\n */\nexport interface NumberFieldButtonState {\n /** The Root is pending and the latest step or commit came from this button. */\n readonly pending: boolean;\n /** The prop, the Root's `disabled` or `readOnly`, or the next step would change nothing. */\n readonly disabled: boolean;\n}\n\n/**\n * Props of `NumberField.Increment` (`NumberField.Decrement` takes the same props).\n *\n * @see https://ui.funstack.work/components/number-field\n */\nexport interface NumberFieldIncrementProps extends Omit<\n ComponentPropsWithRef<\"button\">,\n | \"type\"\n | \"tabIndex\"\n | \"disabled\"\n | \"onPointerDown\"\n | \"onClick\"\n | \"onContextMenu\"\n | \"aria-controls\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /**\n * Never steps. Native `disabled` on a `<button>` (also at the bound and under `readOnly`); with\n * a link or component `render`, `aria-disabled=\"true\"` instead.\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, NumberFieldButtonState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, NumberFieldButtonState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, NumberFieldButtonState>;\n /** Replace the default `<button>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"button\">, NumberFieldButtonState>;\n}\n\n/**\n * Props of `NumberField.Decrement`: the same as `NumberFieldIncrementProps`.\n *\n * @see https://ui.funstack.work/components/number-field\n */\nexport type NumberFieldDecrementProps = NumberFieldIncrementProps;\n\nconst LABELS: Record<StepDirection, string> = { increment: \"Increase\", decrement: \"Decrease\" };\n\n/** Shared by `NumberField.Increment` and `NumberField.Decrement` (design 3.3, 4.3). */\nexport function useStepButtonElement(\n direction: StepDirection,\n part: string,\n props: NumberFieldIncrementProps,\n): ReactNode {\n const { disabled: disabledProp = false, className, style, children, render, ...rest } = props;\n const ctx = useNumberFieldContext(part);\n const { state } = ctx;\n const atBound = isAtBound(ctx.stepBase, direction === \"increment\" ? 1 : -1, ctx.bounds);\n const disabled = disabledProp || state.disabled || state.readOnly || atBound;\n const pending = ctx.pendingSource === direction;\n const buttonState: NumberFieldButtonState = { pending, disabled };\n const handlers = useStepButton(ctx, direction, disabled);\n\n useDevWarning(\n rest[\"aria-label\"] === \"\",\n isDev &&\n `${part}: \\`aria-label=\"\"\\` leaves the button without a name. Pass the label text instead ` +\n `(the default is \"${LABELS[direction]}\").`,\n );\n\n // The built-in name is a default the consumer's `aria-label` or `aria-labelledby` replaces.\n const props$ = {\n ...(rest[\"aria-labelledby\"] === undefined ? { \"aria-label\": LABELS[direction] } : {}),\n ...rest,\n };\n\n return useRender<ComponentPropsWithRef<\"button\">, NumberFieldButtonState>({\n defaultElement: \"button\",\n render,\n state: buttonState,\n className,\n style,\n children,\n props: props$,\n libraryProps: {\n ...(rendersButton(render) ? { type: \"button\" as const } : {}),\n tabIndex: -1,\n \"aria-controls\": ctx.inputId,\n // A link or component render: native `disabled` would mean nothing on a link; the press and\n // click handlers refuse, so `aria-disabled`. The at-bound case follows the same branch.\n ...disabledButton(render, disabled).props,\n onPointerDown: handlers.onPointerDown,\n onClick: handlers.onClick,\n onContextMenu: handlers.onContextMenu,\n \"data-pending\": dataAttr(pending),\n \"data-disabled\": dataAttr(disabled),\n } as Partial<ComponentPropsWithRef<\"button\">> & DataAttributes,\n });\n}\n"],"mappings":";;;;;;;;;AAkBA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;AAGvC,MAAM,aAAa;AACnB,MAAM,gBAAgB;;;;;;;AAmBtB,SAAS,iBAAiB,KAA8B,SAA+B;CACrF,OAAO,QAAQ,QAAQ,WAAW,MAAM,IAAI,WAAW,SAAS,QAAQ,WAAW,KAAK;AAC1F;;;;;;;;AASA,SAAgB,cACd,KACA,WACA,UACoB;CACpB,MAAM,SAAS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CAAS;CAChE,MAAM,WAAW,cAAc,KAAK,WAAW,QAAQ;CAEvD,cACE,KAAK,kBAAkB,IACvB,SACE,GAAG,KAAK,qGACc,OAAO,WAAW,IAC5C;CAGA,MAAM,SAAS;EACb,GAAI,KAAK,uBAAuB,KAAA,IAAY,EAAE,cAAc,OAAO,WAAW,IAAI,CAAC;EACnF,GAAG;CACL;CAEA,OAAO,UAAmE;EACxE,gBAAgB;EAChB;EACA,OAAO;EACP;EACA;EACA;EACA,OAAO;EACP,cAAc;GACZ,GAAI,cAAc,MAAM,IAAI,EAAE,MAAM,SAAkB,IAAI,CAAC;GAC3D,UAAU;GACV,iBAAiB,IAAI;GAGrB,GAAG,eAAe,QAAQ,QAAQ,CAAC,CAAC;GACpC,eAAe,SAAS;GACxB,SAAS,SAAS;GAClB,eAAe,SAAS;GACxB,gBAAgB,SAAS,OAAO;GAChC,iBAAiB,SAAS,QAAQ;EACpC;CACF,CAAC;AACH"}
|
|
@@ -22,7 +22,9 @@ export interface PopoverCloseProps extends Omit<ComponentPropsWithRef<"button">,
|
|
|
22
22
|
* popover: in library mode through the Root (`openChangeAction(false)` awaited, view
|
|
23
23
|
* transition if set), in JS-free mode with `hidePopover()`. A rejection reaches the nearest
|
|
24
24
|
* Error Boundary above the Close part and leaves the popover open. If the popover was
|
|
25
|
-
* dismissed and opened again while the action ran, the close is dropped.
|
|
25
|
+
* dismissed and opened again while the action ran, the close is dropped. With `action` the
|
|
26
|
+
* button is no native close invoker (no `commandfor` / `command`), so a click before hydration
|
|
27
|
+
* does nothing instead of hiding the popover without running the action. Without `action` in
|
|
26
28
|
* JS-free mode the button is a native `command="hide-popover"` invoker.
|
|
27
29
|
*/
|
|
28
30
|
action?: Action<[details: ActionDetails]>;
|
|
@@ -54,7 +56,8 @@ export interface PopoverCloseProps extends Omit<ComponentPropsWithRef<"button">,
|
|
|
54
56
|
render?: RenderProp<ComponentPropsWithRef<"button">, PopoverCloseState>;
|
|
55
57
|
}
|
|
56
58
|
/**
|
|
57
|
-
* A close button: `<button type="button" commandfor command="hide-popover"
|
|
59
|
+
* A close button: `<button type="button" commandfor command="hide-popover">`, or a plain
|
|
60
|
+
* `<button type="button">` with `action` (it does nothing before hydration). In JS-free mode
|
|
58
61
|
* without `action` the browser hides the popover. In library mode the click is always cancelled
|
|
59
62
|
* and the close goes through the Root (`openChangeAction(false)` awaited, `hidePopover()` in the
|
|
60
63
|
* commit). With `action` the action runs first in this part's own transition (`data-pending` on
|
|
@@ -65,7 +68,7 @@ export interface PopoverCloseProps extends Omit<ComponentPropsWithRef<"button">,
|
|
|
65
68
|
* foreign hide's reason.
|
|
66
69
|
*
|
|
67
70
|
* Owned keys (conventions 1.2): `type` (on a `<button>` only), `disabled`, `commandfor`,
|
|
68
|
-
* `command
|
|
71
|
+
* `command` (neither rendered with `action`), `onClick` (library mode, or with `action`), `aria-disabled`, `data-pending`,
|
|
69
72
|
* `data-disabled`.
|
|
70
73
|
*
|
|
71
74
|
* @see https://ui.funstack.work/components/popover
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"popover-close.d.mts","names":[],"sources":["../../src/popover/popover-close.tsx"],"mappings":";;;;;;;iBAkBiB;;WAEN;;WAEA;;;;;;;iBAQM,0BAA0B,KACzC
|
|
1
|
+
{"version":3,"file":"popover-close.d.mts","names":[],"sources":["../../src/popover/popover-close.tsx"],"mappings":";;;;;;;iBAkBiB;;WAEN;;WAEA;;;;;;;iBAQM,0BAA0B,KACzC;;;;;;;;;;;EAaA,SAAS,QAAQ,SAAS;;;;;;;;;;EAU1B,eAAe;;;;;;;;EAQf;;EAEA,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,iCAAiC;;;;;;;;;;;;;;;;;;;;wBAqBvC,eACd,QACA,cACA,UACA,WACA,OACA,UACA,WACG,QACF,oBAAiB;yBATJ"}
|
|
@@ -5,7 +5,8 @@ import { useOverlayClose } from "../internal/overlay/use-overlay-close.mjs";
|
|
|
5
5
|
import { usePopoverContext } from "./popover-context.mjs";
|
|
6
6
|
//#region src/popover/popover-close.tsx
|
|
7
7
|
/**
|
|
8
|
-
* A close button: `<button type="button" commandfor command="hide-popover"
|
|
8
|
+
* A close button: `<button type="button" commandfor command="hide-popover">`, or a plain
|
|
9
|
+
* `<button type="button">` with `action` (it does nothing before hydration). In JS-free mode
|
|
9
10
|
* without `action` the browser hides the popover. In library mode the click is always cancelled
|
|
10
11
|
* and the close goes through the Root (`openChangeAction(false)` awaited, `hidePopover()` in the
|
|
11
12
|
* commit). With `action` the action runs first in this part's own transition (`data-pending` on
|
|
@@ -16,7 +17,7 @@ import { usePopoverContext } from "./popover-context.mjs";
|
|
|
16
17
|
* foreign hide's reason.
|
|
17
18
|
*
|
|
18
19
|
* Owned keys (conventions 1.2): `type` (on a `<button>` only), `disabled`, `commandfor`,
|
|
19
|
-
* `command
|
|
20
|
+
* `command` (neither rendered with `action`), `onClick` (library mode, or with `action`), `aria-disabled`, `data-pending`,
|
|
20
21
|
* `data-disabled`.
|
|
21
22
|
*
|
|
22
23
|
* @see https://ui.funstack.work/components/popover
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"popover-close.mjs","names":[],"sources":["../../src/popover/popover-close.tsx"],"sourcesContent":["\"use client\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { createActionDetails } from \"../internal/action/action-details.js\";\nimport { isPopoverOpen } from \"../internal/overlay/popover-open.js\";\nimport type {\n Action,\n ActionDetails,\n RenderProp,\n StateValue,\n WhilePending,\n} from \"../internal/types.js\";\nimport { useOverlayClose } from \"../internal/overlay/use-overlay-close.js\";\nimport { usePopoverContext } from \"./popover-context.js\";\n\n/**\n * State of `Popover.Close`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface PopoverCloseState {\n /** The `action` is in flight. */\n readonly pending: boolean;\n /** The `disabled` prop. */\n readonly disabled: boolean;\n}\n\n/**\n * Props of `Popover.Close`.\n *\n * @see https://ui.funstack.work/components/popover\n */\nexport interface PopoverCloseProps extends Omit<\n ComponentPropsWithRef<\"button\">,\n \"onClick\" | \"className\" | \"style\" | \"children\"\n> {\n /**\n * Runs inside this part's own transition (`data-pending` on the button), then closes the\n * popover: in library mode through the Root (`openChangeAction(false)` awaited, view\n * transition if set), in JS-free mode with `hidePopover()`. A rejection reaches the nearest\n * Error Boundary above the Close part and leaves the popover open. If the popover was\n * dismissed and opened again while the action ran, the close is dropped. Without `action` in\n * JS-free mode the button is a native `command=\"hide-popover\"` invoker.\n */\n action?: Action<[details: ActionDetails]>;\n /**\n * What a click does while this part's `action` is pending. `\"ignore\"`: nothing (the click is\n * cancelled, `aria-disabled=\"true\"` meanwhile). `\"run\"`: the action runs again (`data-pending`\n * until every run has settled); the popover closes once, when the last run settles and only\n * if the latest run resolved (a rejection leaves it open, as in `\"ignore\"` mode). No effect\n * without `action`.\n *\n * @defaultValue `\"ignore\"`\n */\n whilePending?: WhilePending;\n /**\n * Never closes. Native `disabled` on a `<button>`; owned, so a `render` element cannot\n * re-enable it. With a link or component `render` whose click this part handles (library mode,\n * or with `action`), `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, PopoverCloseState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, PopoverCloseState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, PopoverCloseState>;\n /** Replace the default `<button>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"button\">, PopoverCloseState>;\n}\n\n/**\n * A close button: `<button type=\"button\" commandfor command=\"hide-popover\"
|
|
1
|
+
{"version":3,"file":"popover-close.mjs","names":[],"sources":["../../src/popover/popover-close.tsx"],"sourcesContent":["\"use client\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { createActionDetails } from \"../internal/action/action-details.js\";\nimport { isPopoverOpen } from \"../internal/overlay/popover-open.js\";\nimport type {\n Action,\n ActionDetails,\n RenderProp,\n StateValue,\n WhilePending,\n} from \"../internal/types.js\";\nimport { useOverlayClose } from \"../internal/overlay/use-overlay-close.js\";\nimport { usePopoverContext } from \"./popover-context.js\";\n\n/**\n * State of `Popover.Close`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface PopoverCloseState {\n /** The `action` is in flight. */\n readonly pending: boolean;\n /** The `disabled` prop. */\n readonly disabled: boolean;\n}\n\n/**\n * Props of `Popover.Close`.\n *\n * @see https://ui.funstack.work/components/popover\n */\nexport interface PopoverCloseProps extends Omit<\n ComponentPropsWithRef<\"button\">,\n \"onClick\" | \"className\" | \"style\" | \"children\"\n> {\n /**\n * Runs inside this part's own transition (`data-pending` on the button), then closes the\n * popover: in library mode through the Root (`openChangeAction(false)` awaited, view\n * transition if set), in JS-free mode with `hidePopover()`. A rejection reaches the nearest\n * Error Boundary above the Close part and leaves the popover open. If the popover was\n * dismissed and opened again while the action ran, the close is dropped. With `action` the\n * button is no native close invoker (no `commandfor` / `command`), so a click before hydration\n * does nothing instead of hiding the popover without running the action. Without `action` in\n * JS-free mode the button is a native `command=\"hide-popover\"` invoker.\n */\n action?: Action<[details: ActionDetails]>;\n /**\n * What a click does while this part's `action` is pending. `\"ignore\"`: nothing (the click is\n * cancelled, `aria-disabled=\"true\"` meanwhile). `\"run\"`: the action runs again (`data-pending`\n * until every run has settled); the popover closes once, when the last run settles and only\n * if the latest run resolved (a rejection leaves it open, as in `\"ignore\"` mode). No effect\n * without `action`.\n *\n * @defaultValue `\"ignore\"`\n */\n whilePending?: WhilePending;\n /**\n * Never closes. Native `disabled` on a `<button>`; owned, so a `render` element cannot\n * re-enable it. With a link or component `render` whose click this part handles (library mode,\n * or with `action`), `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, PopoverCloseState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, PopoverCloseState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, PopoverCloseState>;\n /** Replace the default `<button>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"button\">, PopoverCloseState>;\n}\n\n/**\n * A close button: `<button type=\"button\" commandfor command=\"hide-popover\">`, or a plain\n * `<button type=\"button\">` with `action` (it does nothing before hydration). In JS-free mode\n * without `action` the browser hides the popover. In library mode the click is always cancelled\n * and the close goes through the Root (`openChangeAction(false)` awaited, `hidePopover()` in the\n * commit). With `action` the action runs first in this part's own transition (`data-pending` on\n * the button, with `aria-disabled`; a second click meanwhile is ignored unless\n * `whilePending=\"run\"`); a rejection leaves the\n * popover open. It keeps `commandfor` where the Trigger has `popovertarget`: an invoker\n * inside its own popover exposes no state either way, and the `command` event tells the Popup a\n * foreign hide's reason.\n *\n * Owned keys (conventions 1.2): `type` (on a `<button>` only), `disabled`, `commandfor`,\n * `command` (neither rendered with `action`), `onClick` (library mode, or with `action`), `aria-disabled`, `data-pending`,\n * `data-disabled`.\n *\n * @see https://ui.funstack.work/components/popover\n */\nexport function PopoverClose({\n action,\n whilePending,\n disabled = false,\n className,\n style,\n children,\n render,\n ...rest\n}: PopoverCloseProps) {\n const ctx = usePopoverContext(\"Popover.Close\");\n const { popupRef, recordCloseIntent } = ctx;\n const isLibrary = ctx.mode === \"library\";\n return useOverlayClose({\n part: \"Popover.Close\",\n noun: \"popover\",\n isLibrary,\n popupId: ctx.ids.popup,\n command: \"hide-popover\",\n openGeneration: ctx.openGeneration,\n action,\n whilePending,\n details: (event) => createActionDetails(event, {}),\n close: (event) => {\n if (isLibrary) {\n // A library-owned close (design 2.3): awaited, then hidden in the commit.\n ctx.requestClose(event, \"activate\");\n return;\n }\n // JS-free mode with `action`: a browser-owned close; there is no Root state to notify.\n const popup = popupRef.current;\n if (popup === null || !popup.isConnected || !isPopoverOpen(popup)) return;\n recordCloseIntent({ reason: \"activate\", event });\n popup.hidePopover();\n },\n disabled,\n className,\n style,\n children,\n render,\n rest,\n });\n}\n\nPopoverClose.displayName = \"PopoverClose\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA2FA,SAAgB,aAAa,EAC3B,QACA,cACA,WAAW,OACX,WACA,OACA,UACA,QACA,GAAG,QACiB;CACpB,MAAM,MAAM,kBAAkB,eAAe;CAC7C,MAAM,EAAE,UAAU,sBAAsB;CACxC,MAAM,YAAY,IAAI,SAAS;CAC/B,OAAO,gBAAgB;EACrB,MAAM;EACN,MAAM;EACN;EACA,SAAS,IAAI,IAAI;EACjB,SAAS;EACT,gBAAgB,IAAI;EACpB;EACA;EACA,UAAU,UAAU,oBAAoB,OAAO,CAAC,CAAC;EACjD,QAAQ,UAAU;GAChB,IAAI,WAAW;IAEb,IAAI,aAAa,OAAO,UAAU;IAClC;GACF;GAEA,MAAM,QAAQ,SAAS;GACvB,IAAI,UAAU,QAAQ,CAAC,MAAM,eAAe,CAAC,cAAc,KAAK,GAAG;GACnE,kBAAkB;IAAE,QAAQ;IAAY;GAAM,CAAC;GAC/C,MAAM,YAAY;EACpB;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;AACH;AAEA,aAAa,cAAc"}
|
|
@@ -5,8 +5,8 @@ import { useRender } from "../internal/use-render.mjs";
|
|
|
5
5
|
import { useMergedRefs } from "../internal/use-merged-refs.mjs";
|
|
6
6
|
import { useAnchoredPlacement } from "../internal/overlay/use-resolved-placement.mjs";
|
|
7
7
|
import { useJsFreePropWarnings } from "../internal/overlay/overlay-popup.mjs";
|
|
8
|
-
import { PopoverPopupContext, usePopoverContext } from "./popover-context.mjs";
|
|
9
8
|
import { usePopoverPopup } from "../internal/overlay/use-popover-popup.mjs";
|
|
9
|
+
import { PopoverPopupContext, usePopoverContext } from "./popover-context.mjs";
|
|
10
10
|
import { jsx } from "react/jsx-runtime";
|
|
11
11
|
//#region src/popover/popover-popup.tsx
|
|
12
12
|
/**
|
|
@@ -83,7 +83,7 @@ export interface SelectRootProps extends Omit<ComponentPropsWithRef<"select">, "
|
|
|
83
83
|
*
|
|
84
84
|
* @see https://ui.funstack.work/components/select
|
|
85
85
|
*/
|
|
86
|
-
export declare function SelectRoot({ value, defaultValue, valueChangeAction, disabled: disabledProp, className, style, children, render, ...
|
|
86
|
+
export declare function SelectRoot({ value, defaultValue, valueChangeAction, disabled: disabledProp, className, style, children, render, ...restWithMultiple }: SelectRootProps): import("react").JSX.Element;
|
|
87
87
|
export declare namespace SelectRoot {
|
|
88
88
|
var displayName: string;
|
|
89
89
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select-root.d.mts","names":[],"sources":["../../src/select/select-root.tsx"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"select-root.d.mts","names":[],"sources":["../../src/select/select-root.tsx"],"mappings":";;;;iBA+BiB,iCAAiC;;;;;;;;WAQvC,QAAQ;;;;;;;iBAQF;;WAEN;;WAEA;;WAEA;;;;;;;iBAQM,wBAAwB,KACvC;;EAYA;;;;;;;;;;EAUA;;;;;;;;;;;EAWA,oBAAoB,qBAAqB;;;;;;EAMzC;;EAEA,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;;;EAI9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,iCAAiC;;;;;;;;;;;;;;wBAevC,aACd,OACA,cACA,mBACA,UAAU,cACV,WACA,OACA,UACA,WACG,oBACF,kCAAe,IAAA;yBAVF"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { createActionDetails } from "../internal/action/action-details.mjs";
|
|
3
3
|
import { dataAttr } from "../internal/data-attr.mjs";
|
|
4
|
+
import { useDevWarning } from "../internal/use-dev-warning.mjs";
|
|
4
5
|
import { useRender } from "../internal/use-render.mjs";
|
|
5
6
|
import { transitionTypes } from "../internal/transition-types.mjs";
|
|
6
7
|
import { useControllableAction } from "../internal/action/use-controllable-action.mjs";
|
|
@@ -13,6 +14,7 @@ import { useNativeSelectValue } from "../internal/form/use-native-select-value.m
|
|
|
13
14
|
import { useMemo, useRef } from "react";
|
|
14
15
|
import { jsx } from "react/jsx-runtime";
|
|
15
16
|
//#region src/select/select-root.tsx
|
|
17
|
+
const isDev = process.env.NODE_ENV !== "production";
|
|
16
18
|
/**
|
|
17
19
|
* The `<select>` itself: owns the value, the transition, the form-reset listener, the mount
|
|
18
20
|
* reconciliation and the re-apply of late options (design/components/select.md 15.2). Renders
|
|
@@ -25,7 +27,9 @@ import { jsx } from "react/jsx-runtime";
|
|
|
25
27
|
*
|
|
26
28
|
* @see https://ui.funstack.work/components/select
|
|
27
29
|
*/
|
|
28
|
-
function SelectRoot({ value, defaultValue, valueChangeAction, disabled: disabledProp, className, style, children, render, ...
|
|
30
|
+
function SelectRoot({ value, defaultValue, valueChangeAction, disabled: disabledProp, className, style, children, render, ...restWithMultiple }) {
|
|
31
|
+
const { multiple, ...rest } = restWithMultiple;
|
|
32
|
+
useDevWarning(multiple !== void 0 && multiple !== false, isDev && "Select.Root: `multiple` is not supported; it is ignored. Select is a native single <select>. For several values use MultiSelect (`@funstack/ui/multi-select`), or CheckboxGroup for a short list shown in the page.");
|
|
29
33
|
const { ref: libraryRef, node: selectRef } = useSelectPartRef("Select.Root", "select");
|
|
30
34
|
const field = useFieldControl({
|
|
31
35
|
labelable: true,
|