@funstack/ui 0.1.0-alpha.12 → 0.1.0-alpha.14

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.
Files changed (102) hide show
  1. package/dist/combobox/combobox-context.mjs.map +1 -1
  2. package/dist/combobox/combobox-input.d.mts +6 -5
  3. package/dist/combobox/combobox-input.d.mts.map +1 -1
  4. package/dist/combobox/combobox-input.mjs +15 -7
  5. package/dist/combobox/combobox-input.mjs.map +1 -1
  6. package/dist/combobox/combobox-popup.d.mts +4 -2
  7. package/dist/combobox/combobox-popup.d.mts.map +1 -1
  8. package/dist/combobox/combobox-popup.mjs +19 -3
  9. package/dist/combobox/combobox-popup.mjs.map +1 -1
  10. package/dist/combobox/combobox-root.d.mts.map +1 -1
  11. package/dist/combobox/combobox-root.mjs +71 -4
  12. package/dist/combobox/combobox-root.mjs.map +1 -1
  13. package/dist/combobox/combobox-trigger.d.mts +13 -7
  14. package/dist/combobox/combobox-trigger.d.mts.map +1 -1
  15. package/dist/combobox/combobox-trigger.mjs +38 -21
  16. package/dist/combobox/combobox-trigger.mjs.map +1 -1
  17. package/dist/dialog/dialog-popup.d.mts +2 -1
  18. package/dist/dialog/dialog-popup.d.mts.map +1 -1
  19. package/dist/dialog/dialog-popup.mjs +5 -7
  20. package/dist/dialog/dialog-popup.mjs.map +1 -1
  21. package/dist/dialog/dialog-trigger.d.mts +2 -1
  22. package/dist/dialog/dialog-trigger.d.mts.map +1 -1
  23. package/dist/dialog/dialog-trigger.mjs +15 -8
  24. package/dist/dialog/dialog-trigger.mjs.map +1 -1
  25. package/dist/field/field-root.mjs +1 -1
  26. package/dist/field/field-root.mjs.map +1 -1
  27. package/dist/internal/anchor-position.mjs.map +1 -1
  28. package/dist/internal/announce.mjs +4 -42
  29. package/dist/internal/announce.mjs.map +1 -1
  30. package/dist/internal/focus-first-invalid.mjs +15 -6
  31. package/dist/internal/focus-first-invalid.mjs.map +1 -1
  32. package/dist/internal/invoker-press.mjs +46 -0
  33. package/dist/internal/invoker-press.mjs.map +1 -0
  34. package/dist/internal/platform-attributes.d.mts +2 -1
  35. package/dist/internal/platform-attributes.d.mts.map +1 -1
  36. package/dist/internal/pointer-capture.mjs +20 -0
  37. package/dist/internal/pointer-capture.mjs.map +1 -0
  38. package/dist/internal/render-element.mjs.map +1 -1
  39. package/dist/internal/trigger-ref.mjs +26 -0
  40. package/dist/internal/trigger-ref.mjs.map +1 -0
  41. package/dist/internal/use-overlay-close.mjs +2 -2
  42. package/dist/internal/use-overlay-close.mjs.map +1 -1
  43. package/dist/internal/use-overlay-root.mjs +6 -1
  44. package/dist/internal/use-overlay-root.mjs.map +1 -1
  45. package/dist/internal/use-popover-popup.mjs +92 -12
  46. package/dist/internal/use-popover-popup.mjs.map +1 -1
  47. package/dist/internal/use-popover-trigger.d.mts.map +1 -1
  48. package/dist/internal/use-popover-trigger.mjs +26 -15
  49. package/dist/internal/use-popover-trigger.mjs.map +1 -1
  50. package/dist/internal/use-resolved-placement.mjs +1 -1
  51. package/dist/internal/use-resolved-placement.mjs.map +1 -1
  52. package/dist/menu/menu-context-trigger.d.mts.map +1 -1
  53. package/dist/menu/menu-context-trigger.mjs +2 -1
  54. package/dist/menu/menu-context-trigger.mjs.map +1 -1
  55. package/dist/menu/menu-context.mjs.map +1 -1
  56. package/dist/menu/menu-dom.mjs +1 -15
  57. package/dist/menu/menu-dom.mjs.map +1 -1
  58. package/dist/menu/menu-gestures.mjs +2 -3
  59. package/dist/menu/menu-gestures.mjs.map +1 -1
  60. package/dist/menu/menu-popup.d.mts +3 -1
  61. package/dist/menu/menu-popup.d.mts.map +1 -1
  62. package/dist/menu/menu-popup.mjs +16 -4
  63. package/dist/menu/menu-popup.mjs.map +1 -1
  64. package/dist/menu/menu-radio-item.d.mts +2 -0
  65. package/dist/menu/menu-radio-item.d.mts.map +1 -1
  66. package/dist/menu/menu-radio-item.mjs +1 -0
  67. package/dist/menu/menu-radio-item.mjs.map +1 -1
  68. package/dist/menu/menu-submenu-trigger.d.mts +7 -5
  69. package/dist/menu/menu-submenu-trigger.d.mts.map +1 -1
  70. package/dist/menu/menu-submenu-trigger.mjs +12 -7
  71. package/dist/menu/menu-submenu-trigger.mjs.map +1 -1
  72. package/dist/menu/menu-trigger.d.mts +12 -6
  73. package/dist/menu/menu-trigger.d.mts.map +1 -1
  74. package/dist/menu/menu-trigger.mjs +12 -5
  75. package/dist/menu/menu-trigger.mjs.map +1 -1
  76. package/dist/number-field/number-field-root.d.mts +1 -1
  77. package/dist/number-field/number-field-root.mjs.map +1 -1
  78. package/dist/popover/index.d.mts +1 -1
  79. package/dist/popover/index.mjs +1 -1
  80. package/dist/popover/index.mjs.map +1 -1
  81. package/dist/popover/popover-close.d.mts +3 -1
  82. package/dist/popover/popover-close.d.mts.map +1 -1
  83. package/dist/popover/popover-close.mjs +3 -1
  84. package/dist/popover/popover-close.mjs.map +1 -1
  85. package/dist/popover/popover-popup.d.mts +1 -1
  86. package/dist/popover/popover-popup.mjs +1 -1
  87. package/dist/popover/popover-popup.mjs.map +1 -1
  88. package/dist/popover/popover-root.d.mts +1 -1
  89. package/dist/popover/popover-root.mjs +1 -1
  90. package/dist/popover/popover-root.mjs.map +1 -1
  91. package/dist/popover/popover-trigger.d.mts +15 -10
  92. package/dist/popover/popover-trigger.d.mts.map +1 -1
  93. package/dist/popover/popover-trigger.mjs +10 -8
  94. package/dist/popover/popover-trigger.mjs.map +1 -1
  95. package/dist/toast/toast-root.d.mts.map +1 -1
  96. package/dist/toast/toast-root.mjs +2 -0
  97. package/dist/toast/toast-root.mjs.map +1 -1
  98. package/dist/toggle-group/toggle-group-item.d.mts +2 -0
  99. package/dist/toggle-group/toggle-group-item.d.mts.map +1 -1
  100. package/dist/toggle-group/toggle-group-item.mjs +1 -0
  101. package/dist/toggle-group/toggle-group-item.mjs.map +1 -1
  102. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"combobox-context.mjs","names":[],"sources":["../../src/combobox/combobox-context.ts"],"sourcesContent":["\"use client\";\nimport { createContext, use } from \"react\";\nimport type { RefObject } from \"react\";\nimport type { PopoverRootValue } from \"../internal/use-overlay-root.js\";\n\n/** What a mounted `Combobox.Option` tells its Root (design 2, \"mounted options, labels\"). */\nexport interface ComboboxOptionEntry {\n readonly element: HTMLElement;\n /** The `label` prop; `undefined`: the element's trimmed `textContent` at the moment of use. */\n readonly label: string | undefined;\n readonly disabled: boolean;\n}\n\n/** One Combobox: what its Root provides to every part (design 14, `combobox-context.ts`). */\nexport interface ComboboxContextValue {\n /** The shared popover machinery (`useOverlayRoot`, library mode). */\n readonly popover: PopoverRootValue;\n readonly ids: {\n readonly input: string;\n readonly label: string;\n readonly list: string;\n /** `${root}-option-`: an Option's id is this plus `encodeURIComponent(value)`. */\n readonly optionPrefix: string;\n };\n /** Optimistic selection. */\n readonly value: string | null;\n /** The `valueChangeAction` transition is in flight. */\n readonly valuePending: boolean;\n /** `valuePending` or the open transition is in flight (the Root's `pending`). */\n readonly pending: boolean;\n /** The urgent text. */\n readonly inputValue: string;\n /** `useDeferredValue(inputValue)`: what the mounted results are for. */\n readonly query: string;\n readonly stale: boolean;\n /** The option `aria-activedescendant` points at (urgent virtual focus), or `null`. */\n readonly activeValue: string | null;\n /** No option is mounted and the results are settled (`Empty`, `data-empty`). */\n readonly empty: boolean;\n /** A `Combobox.Status` is mounted inside the List (a Suspense fallback): results are loading. */\n readonly loading: boolean;\n /** A `Combobox.Label` is mounted (the List's `aria-labelledby` names it only then). */\n readonly hasLabel: boolean;\n /** The enclosing `Field.Label`'s id: names the List when no `Combobox.Label` is mounted. */\n readonly fieldLabelId: string | undefined;\n readonly disabled: boolean;\n readonly inputRef: RefObject<HTMLInputElement | null>;\n readonly listRef: RefObject<HTMLElement | null>;\n /** Registers a mounted Option; returns the unregistration. */\n readonly registerOption: (value: string, entry: ComboboxOptionEntry) => () => void;\n /** Registers a mounted `Combobox.Status`; while one is mounted the results count as loading. */\n readonly registerStatus: () => () => void;\n /** Registers a mounted `Combobox.Label`; returns the unregistration. */\n readonly registerLabel: () => () => void;\n /** Make `value` the active option (urgent; never dispatches). */\n readonly setActive: (value: string | null) => void;\n /** Accept an option (design 5.2): urgent text write, dispatch, close when it settles. */\n readonly accept: (value: string, event: Event) => void;\n /** `Combobox.Clear` (design 3.3). */\n readonly clear: (event: Event) => void;\n /** The `change` of the Input: urgent text write and an open request (design 2.2, 5.1). */\n readonly typed: (text: string, event: Event) => void;\n /** Keyboard model of design section 8, run by the Input's `onKeyDown`. */\n readonly keyDown: (event: KeyboardEvent) => boolean;\n /** Focus left the Input (design 5.4): close at once, then revert or commit free text. */\n readonly focusOut: (event: FocusEvent) => void;\n /** A pointer click in the Input (`openOnClick`). */\n readonly inputClick: (event: MouseEvent) => void;\n}\n\nexport const ComboboxContext = createContext<ComboboxContextValue | null>(null);\n\nexport function useComboboxContext(part: string): ComboboxContextValue {\n const context = use(ComboboxContext);\n if (context === null) {\n throw new Error(`${part} must be rendered inside a Combobox.Root.`);\n }\n return context;\n}\n\n/** Provided by `Combobox.Popup` (a List outside a Popup warns). */\nexport const ComboboxPopupContext = createContext<boolean>(false);\n\n/** Provided by `Combobox.List` (an Option outside a List warns). */\nexport const ComboboxListContext = createContext<boolean>(false);\n\n/** `Combobox.Group`: the id its `Combobox.GroupLabel` renders. */\nexport const ComboboxGroupContext = createContext<string | null>(null);\n\n/** The id fragment of an option value: stable across result sets, no whitespace (design 3.5). */\nexport function optionId(prefix: string, value: string): string {\n return `${prefix}${encodeURIComponent(value)}`;\n}\n"],"mappings":";;;AAsEA,MAAa,kBAAkB,cAA2C,IAAI;AAE9E,SAAgB,mBAAmB,MAAoC;CACrE,MAAM,UAAU,IAAI,eAAe;CACnC,IAAI,YAAY,MACd,MAAM,IAAI,MAAM,GAAG,KAAK,0CAA0C;CAEpE,OAAO;AACT;;AAGA,MAAa,uBAAuB,cAAuB,KAAK;;AAGhE,MAAa,sBAAsB,cAAuB,KAAK;;AAG/D,MAAa,uBAAuB,cAA6B,IAAI;;AAGrE,SAAgB,SAAS,QAAgB,OAAuB;CAC9D,OAAO,GAAG,SAAS,mBAAmB,KAAK;AAC7C"}
1
+ {"version":3,"file":"combobox-context.mjs","names":[],"sources":["../../src/combobox/combobox-context.ts"],"sourcesContent":["\"use client\";\nimport { createContext, use } from \"react\";\nimport type { RefObject } from \"react\";\nimport type { PopoverRootValue } from \"../internal/use-overlay-root.js\";\n\n/** What a mounted `Combobox.Option` tells its Root (design 2, \"mounted options, labels\"). */\nexport interface ComboboxOptionEntry {\n readonly element: HTMLElement;\n /** The `label` prop; `undefined`: the element's trimmed `textContent` at the moment of use. */\n readonly label: string | undefined;\n readonly disabled: boolean;\n}\n\n/** One Combobox: what its Root provides to every part (design 14, `combobox-context.ts`). */\nexport interface ComboboxContextValue {\n /** The shared popover machinery (`useOverlayRoot`, library mode). */\n readonly popover: PopoverRootValue;\n readonly ids: {\n readonly input: string;\n readonly label: string;\n readonly list: string;\n /** `${root}-option-`: an Option's id is this plus `encodeURIComponent(value)`. */\n readonly optionPrefix: string;\n };\n /** Optimistic selection. */\n readonly value: string | null;\n /** The `valueChangeAction` transition is in flight. */\n readonly valuePending: boolean;\n /** `valuePending` or the open transition is in flight (the Root's `pending`). */\n readonly pending: boolean;\n /** The urgent text. */\n readonly inputValue: string;\n /** `useDeferredValue(inputValue)`: what the mounted results are for. */\n readonly query: string;\n readonly stale: boolean;\n /** The option `aria-activedescendant` points at (urgent virtual focus), or `null`. */\n readonly activeValue: string | null;\n /** No option is mounted and the results are settled (`Empty`, `data-empty`). */\n readonly empty: boolean;\n /** A `Combobox.Status` is mounted inside the List (a Suspense fallback): results are loading. */\n readonly loading: boolean;\n /** A `Combobox.Label` is mounted (the List's `aria-labelledby` names it only then). */\n readonly hasLabel: boolean;\n /** The enclosing `Field.Label`'s id: names the List when no `Combobox.Label` is mounted. */\n readonly fieldLabelId: string | undefined;\n readonly disabled: boolean;\n readonly inputRef: RefObject<HTMLInputElement | null>;\n readonly listRef: RefObject<HTMLElement | null>;\n /** Registers a mounted Option; returns the unregistration. */\n readonly registerOption: (value: string, entry: ComboboxOptionEntry) => () => void;\n /** Registers a mounted `Combobox.Status`; while one is mounted the results count as loading. */\n readonly registerStatus: () => () => void;\n /** Registers a mounted `Combobox.Label`; returns the unregistration. */\n readonly registerLabel: () => () => void;\n /** Make `value` the active option (urgent; never dispatches). */\n readonly setActive: (value: string | null) => void;\n /** Accept an option (design 5.2): urgent text write, dispatch, close when it settles. */\n readonly accept: (value: string, event: Event) => void;\n /** `Combobox.Clear` (design 3.3). */\n readonly clear: (event: Event) => void;\n /** The `change` of the Input: urgent text write and an open request (design 2.2, 5.1). */\n readonly typed: (text: string, event: Event) => void;\n /** Keyboard model of design section 8, run by the Input's `onKeyDown`. */\n readonly keyDown: (event: KeyboardEvent) => boolean;\n /** Focus arrived in the Input: track presses until a leave is decided (#111). */\n readonly focusIn: (event: FocusEvent) => void;\n /** Focus left the Input (design 5.4): close at once, then revert or commit free text. */\n readonly focusOut: (event: FocusEvent) => void;\n /** A pointer click in the Input (`openOnClick`). */\n readonly inputClick: (event: MouseEvent) => void;\n /** A press on the Input: captures the pointer to the shown Popup (design 5.4, #123). */\n readonly inputPointerDown: (event: PointerEvent) => void;\n}\n\nexport const ComboboxContext = createContext<ComboboxContextValue | null>(null);\n\nexport function useComboboxContext(part: string): ComboboxContextValue {\n const context = use(ComboboxContext);\n if (context === null) {\n throw new Error(`${part} must be rendered inside a Combobox.Root.`);\n }\n return context;\n}\n\n/** Provided by `Combobox.Popup` (a List outside a Popup warns). */\nexport const ComboboxPopupContext = createContext<boolean>(false);\n\n/** Provided by `Combobox.List` (an Option outside a List warns). */\nexport const ComboboxListContext = createContext<boolean>(false);\n\n/** `Combobox.Group`: the id its `Combobox.GroupLabel` renders. */\nexport const ComboboxGroupContext = createContext<string | null>(null);\n\n/** The id fragment of an option value: stable across result sets, no whitespace (design 3.5). */\nexport function optionId(prefix: string, value: string): string {\n return `${prefix}${encodeURIComponent(value)}`;\n}\n"],"mappings":";;;AA0EA,MAAa,kBAAkB,cAA2C,IAAI;AAE9E,SAAgB,mBAAmB,MAAoC;CACrE,MAAM,UAAU,IAAI,eAAe;CACnC,IAAI,YAAY,MACd,MAAM,IAAI,MAAM,GAAG,KAAK,0CAA0C;CAEpE,OAAO;AACT;;AAGA,MAAa,uBAAuB,cAAuB,KAAK;;AAGhE,MAAa,sBAAsB,cAAuB,KAAK;;AAG/D,MAAa,uBAAuB,cAA6B,IAAI;;AAGrE,SAAgB,SAAS,QAAgB,OAAuB;CAC9D,OAAO,GAAG,SAAS,mBAAmB,KAAK;AAC7C"}
@@ -14,7 +14,7 @@ export interface ComboboxInputState {
14
14
  readonly stale: boolean;
15
15
  readonly disabled: boolean;
16
16
  }
17
- export interface ComboboxInputProps extends Omit<ComponentPropsWithRef<"input">, "value" | "defaultValue" | "onChange" | "onInput" | "onKeyDown" | "onBlur" | "onClick" | "role" | "aria-autocomplete" | "aria-expanded" | "aria-controls" | "aria-activedescendant" | "autoComplete" | "disabled" | "className" | "style" | "children"> {
17
+ export interface ComboboxInputProps extends Omit<ComponentPropsWithRef<"input">, "value" | "defaultValue" | "onChange" | "onInput" | "onKeyDown" | "onBlur" | "onClick" | "onPointerDown" | "role" | "aria-autocomplete" | "aria-expanded" | "aria-controls" | "aria-activedescendant" | "autoComplete" | "disabled" | "className" | "style" | "children"> {
18
18
  /** Native `required`: empty text is `valueMissing`. */
19
19
  required?: boolean;
20
20
  className?: StateValue<string | undefined, ComboboxInputState>;
@@ -29,10 +29,11 @@ export interface ComboboxInputProps extends Omit<ComponentPropsWithRef<"input">,
29
29
  *
30
30
  * Owned keys (conventions 1.2): `id`, `type`, `role`, `value`, `autoComplete`,
31
31
  * `aria-autocomplete`, `aria-expanded`, `aria-controls` (token-merged), `aria-activedescendant`,
32
- * `disabled`, `onChange`, `onKeyDown`, `onBlur`, `onClick`, `data-open`, `data-pending`,
33
- * `data-selected`, `data-stale`, `data-disabled`; inside a `Field.Root` (whose control id it
34
- * takes) also `required` (own or the Field's), `aria-describedby` (token-merged), `aria-invalid`
35
- * and `data-invalid`.
32
+ * `disabled`, `onChange`, `onKeyDown`, `onBlur`, `onClick`, `onPointerDown` (a primary-button
33
+ * press while the listbox is shown captures the pointer to the Popup, so it is no light dismiss,
34
+ * #123), `data-open`, `data-pending`, `data-selected`, `data-stale`, `data-disabled`; inside a
35
+ * `Field.Root` (whose control id it takes) also `required` (own or the Field's),
36
+ * `aria-describedby` (token-merged), `aria-invalid` and `data-invalid`.
36
37
  */
37
38
  export declare function ComboboxInput({ className, style, render, ...rest }: ComboboxInputProps): import("react").ReactNode;
38
39
  export declare namespace ComboboxInput {
@@ -1 +1 @@
1
- {"version":3,"file":"combobox-input.d.mts","names":[],"sources":["../../src/combobox/combobox-input.tsx"],"mappings":";;;iBAqBiB;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;WACA;;iBAGM,2BAA2B,KAC1C;;EAoBA;EACA,YAAY,+BAA+B;EAC3C,QAAQ,WAAW,2BAA2B;;EAE9C,SAAS,WAAW,gCAAgC;;;;;;;;;;;;;;wBAetC,gBAAgB,WAAW,OAAO,WAAW,QAAQ,qCAAkB;yBAAvE"}
1
+ {"version":3,"file":"combobox-input.d.mts","names":[],"sources":["../../src/combobox/combobox-input.tsx"],"mappings":";;;iBAuBiB;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;WACA;;iBAGM,2BAA2B,KAC1C;;EAqBA;EACA,YAAY,+BAA+B;EAC3C,QAAQ,WAAW,2BAA2B;;EAE9C,SAAS,WAAW,gCAAgC;;;;;;;;;;;;;;;wBAgBtC,gBAAgB,WAAW,OAAO,WAAW,QAAQ,qCAAkB;yBAAvE"}
@@ -4,6 +4,7 @@ import { useRender } from "../internal/use-render.mjs";
4
4
  import { useElementCheck } from "../internal/use-element-check.mjs";
5
5
  import { useMergedRefs } from "../internal/use-merged-refs.mjs";
6
6
  import { useFieldControl } from "../internal/use-field-control.mjs";
7
+ import { registerTrigger } from "../internal/trigger-ref.mjs";
7
8
  import { optionId, useComboboxContext } from "./combobox-context.mjs";
8
9
  import { isValidElement, useCallback } from "react";
9
10
  //#region src/combobox/combobox-input.tsx
@@ -15,10 +16,11 @@ const isDev = process.env.NODE_ENV !== "production";
15
16
  *
16
17
  * Owned keys (conventions 1.2): `id`, `type`, `role`, `value`, `autoComplete`,
17
18
  * `aria-autocomplete`, `aria-expanded`, `aria-controls` (token-merged), `aria-activedescendant`,
18
- * `disabled`, `onChange`, `onKeyDown`, `onBlur`, `onClick`, `data-open`, `data-pending`,
19
- * `data-selected`, `data-stale`, `data-disabled`; inside a `Field.Root` (whose control id it
20
- * takes) also `required` (own or the Field's), `aria-describedby` (token-merged), `aria-invalid`
21
- * and `data-invalid`.
19
+ * `disabled`, `onChange`, `onKeyDown`, `onBlur`, `onClick`, `onPointerDown` (a primary-button
20
+ * press while the listbox is shown captures the pointer to the Popup, so it is no light dismiss,
21
+ * #123), `data-open`, `data-pending`, `data-selected`, `data-stale`, `data-disabled`; inside a
22
+ * `Field.Root` (whose control id it takes) also `required` (own or the Field's),
23
+ * `aria-describedby` (token-merged), `aria-invalid` and `data-invalid`.
22
24
  */
23
25
  function ComboboxInput({ className, style, render, ...rest }) {
24
26
  const ctx = useComboboxContext("Combobox.Input");
@@ -39,10 +41,10 @@ function ComboboxInput({ className, style, render, ...rest }) {
39
41
  const ref = useCallback((element) => {
40
42
  checkElement?.(element);
41
43
  inputRef.current = element;
42
- triggerRef.current = element;
44
+ const unregister = registerTrigger(triggerRef, element, "Combobox.Input");
43
45
  return () => {
44
46
  if (inputRef.current === element) inputRef.current = null;
45
- if (triggerRef.current === element) triggerRef.current = null;
47
+ unregister();
46
48
  };
47
49
  }, [
48
50
  checkElement,
@@ -68,7 +70,7 @@ function ComboboxInput({ className, style, render, ...rest }) {
68
70
  value: ctx.inputValue,
69
71
  autoComplete: "off",
70
72
  "aria-autocomplete": "list",
71
- "aria-expanded": popover.optimistic,
73
+ "aria-expanded": popover.shown,
72
74
  "aria-controls": ids.list,
73
75
  "aria-activedescendant": ctx.activeValue === null ? void 0 : optionId(ids.optionPrefix, ctx.activeValue),
74
76
  disabled: ctx.disabled,
@@ -78,12 +80,18 @@ function ComboboxInput({ className, style, render, ...rest }) {
78
80
  onKeyDown: (event) => {
79
81
  ctx.keyDown(event.nativeEvent);
80
82
  },
83
+ onFocus: (event) => {
84
+ ctx.focusIn(event.nativeEvent);
85
+ },
81
86
  onBlur: (event) => {
82
87
  ctx.focusOut(event.nativeEvent);
83
88
  },
84
89
  onClick: (event) => {
85
90
  ctx.inputClick(event.nativeEvent);
86
91
  },
92
+ onPointerDown: (event) => {
93
+ ctx.inputPointerDown(event.nativeEvent);
94
+ },
87
95
  "data-open": dataAttr(popover.optimistic),
88
96
  "data-pending": dataAttr(state.pending),
89
97
  "data-selected": dataAttr(ctx.value !== null),
@@ -1 +1 @@
1
- {"version":3,"file":"combobox-input.mjs","names":[],"sources":["../../src/combobox/combobox-input.tsx"],"sourcesContent":["\"use client\";\nimport { isValidElement, useCallback } from \"react\";\nimport type {\n ChangeEvent,\n ComponentPropsWithRef,\n CSSProperties,\n FocusEvent,\n KeyboardEvent,\n MouseEvent,\n} from \"react\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useElementCheck } from \"../internal/use-element-check.js\";\nimport { useFieldControl } from \"../internal/use-field-control.js\";\nimport { useMergedRefs } from \"../internal/use-merged-refs.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { optionId, useComboboxContext } from \"./combobox-context.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\nexport interface ComboboxInputState {\n /** Optimistic selection. */\n readonly value: string | null;\n /** The urgent text. */\n readonly inputValue: string;\n /** Optimistic open state. */\n readonly open: boolean;\n /** The Root is pending (a selection or an open in flight). */\n readonly pending: boolean;\n /** The results shown are for an older text. */\n readonly stale: boolean;\n readonly disabled: boolean;\n}\n\nexport interface ComboboxInputProps extends Omit<\n ComponentPropsWithRef<\"input\">,\n | \"value\"\n | \"defaultValue\"\n | \"onChange\"\n | \"onInput\"\n | \"onKeyDown\"\n | \"onBlur\"\n | \"onClick\"\n | \"role\"\n | \"aria-autocomplete\"\n | \"aria-expanded\"\n | \"aria-controls\"\n | \"aria-activedescendant\"\n | \"autoComplete\"\n | \"disabled\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /** Native `required`: empty text is `valueMissing`. */\n required?: boolean;\n className?: StateValue<string | undefined, ComboboxInputState>;\n style?: StateValue<CSSProperties | undefined, ComboboxInputState>;\n /** Must render an `<input>` of type `text` or `search`. */\n render?: RenderProp<ComponentPropsWithRef<\"input\">, ComboboxInputState>;\n}\n\n/**\n * The text field: `<input role=\"combobox\" aria-autocomplete=\"list\" aria-expanded aria-controls\n * aria-activedescendant autocomplete=\"off\">`. DOM focus stays here while the active option moves\n * virtually (design 7.1). Its text is the Root's urgent `inputValue`; typing opens the listbox.\n *\n * Owned keys (conventions 1.2): `id`, `type`, `role`, `value`, `autoComplete`,\n * `aria-autocomplete`, `aria-expanded`, `aria-controls` (token-merged), `aria-activedescendant`,\n * `disabled`, `onChange`, `onKeyDown`, `onBlur`, `onClick`, `data-open`, `data-pending`,\n * `data-selected`, `data-stale`, `data-disabled`; inside a `Field.Root` (whose control id it\n * takes) also `required` (own or the Field's), `aria-describedby` (token-merged), `aria-invalid`\n * and `data-invalid`.\n */\nexport function ComboboxInput({ className, style, render, ...rest }: ComboboxInputProps) {\n const ctx = useComboboxContext(\"Combobox.Input\");\n const { popover, ids, inputRef } = ctx;\n const { triggerRef } = popover;\n\n const state: ComboboxInputState = {\n value: ctx.value,\n inputValue: ctx.inputValue,\n open: popover.optimistic,\n pending: ctx.pending,\n stale: ctx.stale,\n disabled: ctx.disabled,\n };\n\n const checkElement = useElementCheck(\n isDev &&\n ((element) => {\n const type = element.tagName === \"INPUT\" ? (element as HTMLInputElement).type : \"\";\n return type !== \"text\" && type !== \"search\"\n ? `Combobox.Input: rendered <${element.tagName.toLowerCase()}` +\n `${type === \"\" ? \"\" : ` type=\"${type}\"`}>. Render an <input> of type \"text\" or ` +\n '\"search\": `role=\"combobox\"`, `aria-activedescendant` and the caret keys depend on it.'\n : null;\n }),\n );\n const ref = useCallback(\n (element: HTMLElement) => {\n checkElement?.(element);\n inputRef.current = element as HTMLInputElement;\n // The popover's \"trigger\" is the input: `showPopover({ source: input })` anchors the\n // listbox to it and makes clicks on it not light-dismiss (design 5.1).\n triggerRef.current = element;\n return () => {\n if (inputRef.current === element) inputRef.current = null;\n if (triggerRef.current === element) triggerRef.current = null;\n };\n },\n [checkElement, inputRef, triggerRef],\n );\n\n // Inside a Field.Root (design/components/field-form.md 7.2) the Input is the Field's control:\n // the Root already took the Field's id for it; `required` and the ARIA wiring land here.\n const field = useFieldControl({\n labelable: true,\n required: rest.required,\n disabled: ctx.disabled,\n id: rest.id,\n component: \"Combobox.Input\",\n });\n const fieldRef = field.ref;\n const mergedRef = useMergedRefs<HTMLElement>(ref, fieldRef);\n\n const searchType = isValidElement<{ type?: unknown }>(render) && render.props.type === \"search\";\n\n const libraryProps: ComponentPropsWithRef<\"input\"> & DataAttributes = {\n ...field.attributes,\n ...(field.inField && { required: field.required }),\n id: ids.input,\n type: searchType ? \"search\" : \"text\",\n role: \"combobox\",\n value: ctx.inputValue,\n autoComplete: \"off\",\n \"aria-autocomplete\": \"list\",\n \"aria-expanded\": popover.optimistic,\n \"aria-controls\": ids.list,\n \"aria-activedescendant\":\n ctx.activeValue === null ? undefined : optionId(ids.optionPrefix, ctx.activeValue),\n disabled: ctx.disabled,\n onChange: (event: ChangeEvent<HTMLInputElement>) => {\n ctx.typed(event.currentTarget.value, event.nativeEvent);\n },\n onKeyDown: (event: KeyboardEvent<HTMLInputElement>) => {\n ctx.keyDown(event.nativeEvent);\n },\n onBlur: (event: FocusEvent<HTMLInputElement>) => {\n ctx.focusOut(event.nativeEvent);\n },\n onClick: (event: MouseEvent<HTMLInputElement>) => {\n ctx.inputClick(event.nativeEvent);\n },\n \"data-open\": dataAttr(popover.optimistic),\n \"data-pending\": dataAttr(state.pending),\n \"data-selected\": dataAttr(ctx.value !== null),\n \"data-stale\": dataAttr(ctx.stale),\n \"data-disabled\": dataAttr(ctx.disabled),\n };\n\n return useRender<ComponentPropsWithRef<\"input\">, ComboboxInputState>({\n defaultElement: \"input\",\n render,\n state,\n className,\n style,\n children: undefined,\n props: rest,\n libraryProps,\n ref: mergedRef,\n });\n}\n\nComboboxInput.displayName = \"ComboboxInput\";\n"],"mappings":";;;;;;;;;AAmBA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;;;;;;;;;AAwDvC,SAAgB,cAAc,EAAE,WAAW,OAAO,QAAQ,GAAG,QAA4B;CACvF,MAAM,MAAM,mBAAmB,gBAAgB;CAC/C,MAAM,EAAE,SAAS,KAAK,aAAa;CACnC,MAAM,EAAE,eAAe;CAEvB,MAAM,QAA4B;EAChC,OAAO,IAAI;EACX,YAAY,IAAI;EAChB,MAAM,QAAQ;EACd,SAAS,IAAI;EACb,OAAO,IAAI;EACX,UAAU,IAAI;CAChB;CAEA,MAAM,eAAe,gBACnB,WACI,YAAY;EACZ,MAAM,OAAO,QAAQ,YAAY,UAAW,QAA6B,OAAO;EAChF,OAAO,SAAS,UAAU,SAAS,WAC/B,6BAA6B,QAAQ,QAAQ,YAAY,IACpD,SAAS,KAAK,KAAK,UAAU,KAAK,GAAG,oIAE1C;CACN,EACJ;CACA,MAAM,MAAM,aACT,YAAyB;EACxB,eAAe,OAAO;EACtB,SAAS,UAAU;EAGnB,WAAW,UAAU;EACrB,aAAa;GACX,IAAI,SAAS,YAAY,SAAS,SAAS,UAAU;GACrD,IAAI,WAAW,YAAY,SAAS,WAAW,UAAU;EAC3D;CACF,GACA;EAAC;EAAc;EAAU;CAAU,CACrC;CAIA,MAAM,QAAQ,gBAAgB;EAC5B,WAAW;EACX,UAAU,KAAK;EACf,UAAU,IAAI;EACd,IAAI,KAAK;EACT,WAAW;CACb,CAAC;CACD,MAAM,WAAW,MAAM;CACvB,MAAM,YAAY,cAA2B,KAAK,QAAQ;CAE1D,MAAM,aAAa,eAAmC,MAAM,KAAK,OAAO,MAAM,SAAS;CAEvF,MAAM,eAAgE;EACpE,GAAG,MAAM;EACT,GAAI,MAAM,WAAW,EAAE,UAAU,MAAM,SAAS;EAChD,IAAI,IAAI;EACR,MAAM,aAAa,WAAW;EAC9B,MAAM;EACN,OAAO,IAAI;EACX,cAAc;EACd,qBAAqB;EACrB,iBAAiB,QAAQ;EACzB,iBAAiB,IAAI;EACrB,yBACE,IAAI,gBAAgB,OAAO,KAAA,IAAY,SAAS,IAAI,cAAc,IAAI,WAAW;EACnF,UAAU,IAAI;EACd,WAAW,UAAyC;GAClD,IAAI,MAAM,MAAM,cAAc,OAAO,MAAM,WAAW;EACxD;EACA,YAAY,UAA2C;GACrD,IAAI,QAAQ,MAAM,WAAW;EAC/B;EACA,SAAS,UAAwC;GAC/C,IAAI,SAAS,MAAM,WAAW;EAChC;EACA,UAAU,UAAwC;GAChD,IAAI,WAAW,MAAM,WAAW;EAClC;EACA,aAAa,SAAS,QAAQ,UAAU;EACxC,gBAAgB,SAAS,MAAM,OAAO;EACtC,iBAAiB,SAAS,IAAI,UAAU,IAAI;EAC5C,cAAc,SAAS,IAAI,KAAK;EAChC,iBAAiB,SAAS,IAAI,QAAQ;CACxC;CAEA,OAAO,UAA8D;EACnE,gBAAgB;EAChB;EACA;EACA;EACA;EACA,UAAU,KAAA;EACV,OAAO;EACP;EACA,KAAK;CACP,CAAC;AACH;AAEA,cAAc,cAAc"}
1
+ {"version":3,"file":"combobox-input.mjs","names":[],"sources":["../../src/combobox/combobox-input.tsx"],"sourcesContent":["\"use client\";\nimport { isValidElement, useCallback } from \"react\";\nimport type {\n ChangeEvent,\n ComponentPropsWithRef,\n CSSProperties,\n FocusEvent,\n KeyboardEvent,\n MouseEvent,\n PointerEvent,\n} 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 { useFieldControl } from \"../internal/use-field-control.js\";\nimport { useMergedRefs } from \"../internal/use-merged-refs.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { optionId, useComboboxContext } from \"./combobox-context.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\nexport interface ComboboxInputState {\n /** Optimistic selection. */\n readonly value: string | null;\n /** The urgent text. */\n readonly inputValue: string;\n /** Optimistic open state. */\n readonly open: boolean;\n /** The Root is pending (a selection or an open in flight). */\n readonly pending: boolean;\n /** The results shown are for an older text. */\n readonly stale: boolean;\n readonly disabled: boolean;\n}\n\nexport interface ComboboxInputProps extends Omit<\n ComponentPropsWithRef<\"input\">,\n | \"value\"\n | \"defaultValue\"\n | \"onChange\"\n | \"onInput\"\n | \"onKeyDown\"\n | \"onBlur\"\n | \"onClick\"\n | \"onPointerDown\"\n | \"role\"\n | \"aria-autocomplete\"\n | \"aria-expanded\"\n | \"aria-controls\"\n | \"aria-activedescendant\"\n | \"autoComplete\"\n | \"disabled\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /** Native `required`: empty text is `valueMissing`. */\n required?: boolean;\n className?: StateValue<string | undefined, ComboboxInputState>;\n style?: StateValue<CSSProperties | undefined, ComboboxInputState>;\n /** Must render an `<input>` of type `text` or `search`. */\n render?: RenderProp<ComponentPropsWithRef<\"input\">, ComboboxInputState>;\n}\n\n/**\n * The text field: `<input role=\"combobox\" aria-autocomplete=\"list\" aria-expanded aria-controls\n * aria-activedescendant autocomplete=\"off\">`. DOM focus stays here while the active option moves\n * virtually (design 7.1). Its text is the Root's urgent `inputValue`; typing opens the listbox.\n *\n * Owned keys (conventions 1.2): `id`, `type`, `role`, `value`, `autoComplete`,\n * `aria-autocomplete`, `aria-expanded`, `aria-controls` (token-merged), `aria-activedescendant`,\n * `disabled`, `onChange`, `onKeyDown`, `onBlur`, `onClick`, `onPointerDown` (a primary-button\n * press while the listbox is shown captures the pointer to the Popup, so it is no light dismiss,\n * #123), `data-open`, `data-pending`, `data-selected`, `data-stale`, `data-disabled`; inside a\n * `Field.Root` (whose control id it takes) also `required` (own or the Field's),\n * `aria-describedby` (token-merged), `aria-invalid` and `data-invalid`.\n */\nexport function ComboboxInput({ className, style, render, ...rest }: ComboboxInputProps) {\n const ctx = useComboboxContext(\"Combobox.Input\");\n const { popover, ids, inputRef } = ctx;\n const { triggerRef } = popover;\n\n const state: ComboboxInputState = {\n value: ctx.value,\n inputValue: ctx.inputValue,\n open: popover.optimistic,\n pending: ctx.pending,\n stale: ctx.stale,\n disabled: ctx.disabled,\n };\n\n const checkElement = useElementCheck(\n isDev &&\n ((element) => {\n const type = element.tagName === \"INPUT\" ? (element as HTMLInputElement).type : \"\";\n return type !== \"text\" && type !== \"search\"\n ? `Combobox.Input: rendered <${element.tagName.toLowerCase()}` +\n `${type === \"\" ? \"\" : ` type=\"${type}\"`}>. Render an <input> of type \"text\" or ` +\n '\"search\": `role=\"combobox\"`, `aria-activedescendant` and the caret keys depend on it.'\n : null;\n }),\n );\n const ref = useCallback(\n (element: HTMLElement) => {\n checkElement?.(element);\n inputRef.current = element as HTMLInputElement;\n // The popover's \"trigger\" is the input: `showPopover({ source: input })` anchors the\n // listbox to it and stacks a nested listbox under its popover (design 5.1). It does not\n // exempt presses on the input from light dismiss; `onPointerDown` does that (#123).\n const unregister = registerTrigger(triggerRef, element, \"Combobox.Input\");\n return () => {\n if (inputRef.current === element) inputRef.current = null;\n unregister();\n };\n },\n [checkElement, inputRef, triggerRef],\n );\n\n // Inside a Field.Root (design/components/field-form.md 7.2) the Input is the Field's control:\n // the Root already took the Field's id for it; `required` and the ARIA wiring land here.\n const field = useFieldControl({\n labelable: true,\n required: rest.required,\n disabled: ctx.disabled,\n id: rest.id,\n component: \"Combobox.Input\",\n });\n const fieldRef = field.ref;\n const mergedRef = useMergedRefs<HTMLElement>(ref, fieldRef);\n\n const searchType = isValidElement<{ type?: unknown }>(render) && render.props.type === \"search\";\n\n const libraryProps: ComponentPropsWithRef<\"input\"> & DataAttributes = {\n ...field.attributes,\n ...(field.inField && { required: field.required }),\n id: ids.input,\n type: searchType ? \"search\" : \"text\",\n role: \"combobox\",\n value: ctx.inputValue,\n autoComplete: \"off\",\n \"aria-autocomplete\": \"list\",\n // Shown (the listbox is in the top layer); `data-open` is the optimistic one (#118).\n \"aria-expanded\": popover.shown,\n \"aria-controls\": ids.list,\n \"aria-activedescendant\":\n ctx.activeValue === null ? undefined : optionId(ids.optionPrefix, ctx.activeValue),\n disabled: ctx.disabled,\n onChange: (event: ChangeEvent<HTMLInputElement>) => {\n ctx.typed(event.currentTarget.value, event.nativeEvent);\n },\n onKeyDown: (event: KeyboardEvent<HTMLInputElement>) => {\n ctx.keyDown(event.nativeEvent);\n },\n onFocus: (event: FocusEvent<HTMLInputElement>) => {\n ctx.focusIn(event.nativeEvent);\n },\n onBlur: (event: FocusEvent<HTMLInputElement>) => {\n ctx.focusOut(event.nativeEvent);\n },\n onClick: (event: MouseEvent<HTMLInputElement>) => {\n ctx.inputClick(event.nativeEvent);\n },\n onPointerDown: (event: PointerEvent<HTMLInputElement>) => {\n ctx.inputPointerDown(event.nativeEvent);\n },\n \"data-open\": dataAttr(popover.optimistic),\n \"data-pending\": dataAttr(state.pending),\n \"data-selected\": dataAttr(ctx.value !== null),\n \"data-stale\": dataAttr(ctx.stale),\n \"data-disabled\": dataAttr(ctx.disabled),\n };\n\n return useRender<ComponentPropsWithRef<\"input\">, ComboboxInputState>({\n defaultElement: \"input\",\n render,\n state,\n className,\n style,\n children: undefined,\n props: rest,\n libraryProps,\n ref: mergedRef,\n });\n}\n\nComboboxInput.displayName = \"ComboboxInput\";\n"],"mappings":";;;;;;;;;;AAqBA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;;;;;;;;;;AA0DvC,SAAgB,cAAc,EAAE,WAAW,OAAO,QAAQ,GAAG,QAA4B;CACvF,MAAM,MAAM,mBAAmB,gBAAgB;CAC/C,MAAM,EAAE,SAAS,KAAK,aAAa;CACnC,MAAM,EAAE,eAAe;CAEvB,MAAM,QAA4B;EAChC,OAAO,IAAI;EACX,YAAY,IAAI;EAChB,MAAM,QAAQ;EACd,SAAS,IAAI;EACb,OAAO,IAAI;EACX,UAAU,IAAI;CAChB;CAEA,MAAM,eAAe,gBACnB,WACI,YAAY;EACZ,MAAM,OAAO,QAAQ,YAAY,UAAW,QAA6B,OAAO;EAChF,OAAO,SAAS,UAAU,SAAS,WAC/B,6BAA6B,QAAQ,QAAQ,YAAY,IACpD,SAAS,KAAK,KAAK,UAAU,KAAK,GAAG,oIAE1C;CACN,EACJ;CACA,MAAM,MAAM,aACT,YAAyB;EACxB,eAAe,OAAO;EACtB,SAAS,UAAU;EAInB,MAAM,aAAa,gBAAgB,YAAY,SAAS,gBAAgB;EACxE,aAAa;GACX,IAAI,SAAS,YAAY,SAAS,SAAS,UAAU;GACrD,WAAW;EACb;CACF,GACA;EAAC;EAAc;EAAU;CAAU,CACrC;CAIA,MAAM,QAAQ,gBAAgB;EAC5B,WAAW;EACX,UAAU,KAAK;EACf,UAAU,IAAI;EACd,IAAI,KAAK;EACT,WAAW;CACb,CAAC;CACD,MAAM,WAAW,MAAM;CACvB,MAAM,YAAY,cAA2B,KAAK,QAAQ;CAE1D,MAAM,aAAa,eAAmC,MAAM,KAAK,OAAO,MAAM,SAAS;CAEvF,MAAM,eAAgE;EACpE,GAAG,MAAM;EACT,GAAI,MAAM,WAAW,EAAE,UAAU,MAAM,SAAS;EAChD,IAAI,IAAI;EACR,MAAM,aAAa,WAAW;EAC9B,MAAM;EACN,OAAO,IAAI;EACX,cAAc;EACd,qBAAqB;EAErB,iBAAiB,QAAQ;EACzB,iBAAiB,IAAI;EACrB,yBACE,IAAI,gBAAgB,OAAO,KAAA,IAAY,SAAS,IAAI,cAAc,IAAI,WAAW;EACnF,UAAU,IAAI;EACd,WAAW,UAAyC;GAClD,IAAI,MAAM,MAAM,cAAc,OAAO,MAAM,WAAW;EACxD;EACA,YAAY,UAA2C;GACrD,IAAI,QAAQ,MAAM,WAAW;EAC/B;EACA,UAAU,UAAwC;GAChD,IAAI,QAAQ,MAAM,WAAW;EAC/B;EACA,SAAS,UAAwC;GAC/C,IAAI,SAAS,MAAM,WAAW;EAChC;EACA,UAAU,UAAwC;GAChD,IAAI,WAAW,MAAM,WAAW;EAClC;EACA,gBAAgB,UAA0C;GACxD,IAAI,iBAAiB,MAAM,WAAW;EACxC;EACA,aAAa,SAAS,QAAQ,UAAU;EACxC,gBAAgB,SAAS,MAAM,OAAO;EACtC,iBAAiB,SAAS,IAAI,UAAU,IAAI;EAC5C,cAAc,SAAS,IAAI,KAAK;EAChC,iBAAiB,SAAS,IAAI,QAAQ;CACxC;CAEA,OAAO,UAA8D;EACnE,gBAAgB;EAChB;EACA;EACA;EACA;EACA,UAAU,KAAA;EACV,OAAO;EACP;EACA,KAAK;CACP,CAAC;AACH;AAEA,cAAc,cAAc"}
@@ -33,8 +33,10 @@ export interface ComboboxPopupProps extends Omit<ComponentPropsWithRef<"div">, "
33
33
  * The listbox's container: `<div popover="auto">`, opened by the library with
34
34
  * `showPopover({ source: input })` and placed below (or, flipped, above) the input with CSS
35
35
  * Anchor Positioning, at least as wide as the input. Focus never enters it: a press anywhere in
36
- * it is `preventDefault()`ed so the input keeps focus (design 7.1). Holds the `List` and, outside
37
- * it, `Empty` and `Status`. Style it with `:popover-open`; it emits `data-stale` but no
36
+ * it is `preventDefault()`ed so the input keeps focus (design 7.1), and so is a press on a button
37
+ * of the consumer's that names the popup (`popovertarget`, `commandfor`) while it is shown: its
38
+ * click closes the listbox as `"activate"` with the text untouched (#126). Holds the `List` and,
39
+ * outside it, `Empty` and `Status`. Style it with `:popover-open`; it emits `data-stale` but no
38
40
  * `data-open`.
39
41
  *
40
42
  * Owned keys (conventions 1.2): `id`, `popover`, `onPointerDown`, `onMouseDown`, `data-stale`.
@@ -1 +1 @@
1
- {"version":3,"file":"combobox-popup.d.mts","names":[],"sources":["../../src/combobox/combobox-popup.tsx"],"mappings":";;;iBAqBiB;;WAEN;;WAEA;;WAEA;;iBAGM,2BAA2B,KAC1C;;;;;EAeA;;;;;;;;EAQA,aAAa;EACb,YAAY,+BAA+B;EAC3C,QAAQ,WAAW,2BAA2B;EAC9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,8BAA8B;;;;;;;;;;;;;;wBAiBpC,gBACd,aACA,YACA,WACA,OACA,UACA,WACG,QACF,qBAAkB;yBARL"}
1
+ {"version":3,"file":"combobox-popup.d.mts","names":[],"sources":["../../src/combobox/combobox-popup.tsx"],"mappings":";;;iBAwBiB;;WAEN;;WAEA;;WAEA;;iBAGM,2BAA2B,KAC1C;;;;;EAeA;;;;;;;;EAQA,aAAa;EACb,YAAY,+BAA+B;EAC3C,QAAQ,WAAW,2BAA2B;EAC9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,8BAA8B;;;;;;;;;;;;;;;;wBAmBpC,gBACd,aACA,YACA,WACA,OACA,UACA,WACG,QACF,qBAAkB;yBARL"}
@@ -5,8 +5,11 @@ import { resolveStateValue } from "../internal/render-element.mjs";
5
5
  import { useRender } from "../internal/use-render.mjs";
6
6
  import { useElementCheck } from "../internal/use-element-check.mjs";
7
7
  import { useMergedRefs } from "../internal/use-merged-refs.mjs";
8
+ import { isPopoverOpen } from "../internal/popover-open.mjs";
8
9
  import { usePopoverPopup } from "../internal/use-popover-popup.mjs";
10
+ import { listenInvokerPresses } from "../internal/invoker-press.mjs";
9
11
  import { ComboboxPopupContext, useComboboxContext } from "./combobox-context.mjs";
12
+ import { useCallback, useEffect, useRef } from "react";
10
13
  import { jsx } from "react/jsx-runtime";
11
14
  //#region src/combobox/combobox-popup.tsx
12
15
  const isDev = process.env.NODE_ENV !== "production";
@@ -15,8 +18,10 @@ const preventDefault = (event) => event.preventDefault();
15
18
  * The listbox's container: `<div popover="auto">`, opened by the library with
16
19
  * `showPopover({ source: input })` and placed below (or, flipped, above) the input with CSS
17
20
  * Anchor Positioning, at least as wide as the input. Focus never enters it: a press anywhere in
18
- * it is `preventDefault()`ed so the input keeps focus (design 7.1). Holds the `List` and, outside
19
- * it, `Empty` and `Status`. Style it with `:popover-open`; it emits `data-stale` but no
21
+ * it is `preventDefault()`ed so the input keeps focus (design 7.1), and so is a press on a button
22
+ * of the consumer's that names the popup (`popovertarget`, `commandfor`) while it is shown: its
23
+ * click closes the listbox as `"activate"` with the text untouched (#126). Holds the `List` and,
24
+ * outside it, `Empty` and `Status`. Style it with `:popover-open`; it emits `data-stale` but no
20
25
  * `data-open`.
21
26
  *
22
27
  * Owned keys (conventions 1.2): `id`, `popover`, `onPointerDown`, `onMouseDown`, `data-stale`.
@@ -26,11 +31,22 @@ const preventDefault = (event) => event.preventDefault();
26
31
  function ComboboxPopup({ keepMounted, transition, className, style, children, render, ...rest }) {
27
32
  const ctx = useComboboxContext("Combobox.Popup");
28
33
  const { popover } = ctx;
34
+ const invokerPresses = useRef(null);
35
+ const stopInvokerPresses = useCallback(() => {
36
+ invokerPresses.current?.();
37
+ invokerPresses.current = null;
38
+ }, []);
39
+ useEffect(() => stopInvokerPresses, [stopInvokerPresses]);
29
40
  const { setElement, renderContent } = usePopoverPopup(popover, {
30
41
  part: "Combobox.Popup",
31
42
  resolveInitialFocus: () => null,
32
43
  keepMounted,
33
- transition
44
+ transition,
45
+ onToggle: (event) => {
46
+ const element = popover.popupRef.current;
47
+ if (event.newState === "open" && element !== null && isPopoverOpen(element)) invokerPresses.current ??= listenInvokerPresses(element);
48
+ else if (event.newState === "closed") stopInvokerPresses();
49
+ }
34
50
  });
35
51
  const devRef = useElementCheck(isDev && ((element) => element.tagName !== "DIV" ? `Combobox.Popup: rendered a <${element.tagName.toLowerCase()}>. Render a <div>: a <dialog popover> runs the dialog focusing steps and takes focus out of the input.` : null));
36
52
  const ref = useMergedRefs(setElement, devRef);
@@ -1 +1 @@
1
- {"version":3,"file":"combobox-popup.mjs","names":[],"sources":["../../src/combobox/combobox-popup.tsx"],"sourcesContent":["\"use client\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n MouseEvent,\n PointerEvent,\n ReactNode,\n ViewTransitionClass,\n} from \"react\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport { useTransitionBoundary } from \"../internal/transition-boundary.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 { usePopoverPopup } from \"../internal/use-popover-popup.js\";\nimport { resolveStateValue, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { ComboboxPopupContext, useComboboxContext } from \"./combobox-context.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\nexport interface ComboboxPopupState {\n /** Committed open state. Read `:popover-open` for the DOM truth. */\n readonly open: boolean;\n /** The results shown are for an older text. */\n readonly stale: boolean;\n /** The deferred text the results are for. */\n readonly query: string;\n}\n\nexport interface ComboboxPopupProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n | \"id\"\n | \"popover\"\n | \"onToggle\"\n | \"onBeforeToggle\"\n | \"onPointerDown\"\n | \"onMouseDown\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /**\n * `false` (default): the children are not rendered while the listbox is closed. `true`: they\n * stay mounted inside `<Activity mode=\"hidden\">`.\n */\n keepMounted?: boolean;\n /**\n * Forwarded to the `<ViewTransition default>` around the popover element itself. Animates\n * library-driven opens and closes (typing, the Trigger, an accepted option) in every engine;\n * dismissals are the browser's (CSS only). **A deferred results render also activates the\n * boundary** (React: updates from `useDeferredValue` animate), so use a type map with\n * `default: \"none\"` unless every result change should cross-fade. Static.\n */\n transition?: ViewTransitionClass;\n className?: StateValue<string | undefined, ComboboxPopupState>;\n style?: StateValue<CSSProperties | undefined, ComboboxPopupState>;\n children?: StateValue<ReactNode, ComboboxPopupState>;\n /** Must render a `<div>`: a `<dialog>` would pull focus out of the input. */\n render?: RenderProp<ComponentPropsWithRef<\"div\">, ComboboxPopupState>;\n}\n\nconst preventDefault = (event: { preventDefault(): void }) => event.preventDefault();\n\n/**\n * The listbox's container: `<div popover=\"auto\">`, opened by the library with\n * `showPopover({ source: input })` and placed below (or, flipped, above) the input with CSS\n * Anchor Positioning, at least as wide as the input. Focus never enters it: a press anywhere in\n * it is `preventDefault()`ed so the input keeps focus (design 7.1). Holds the `List` and, outside\n * it, `Empty` and `Status`. Style it with `:popover-open`; it emits `data-stale` but no\n * `data-open`.\n *\n * Owned keys (conventions 1.2): `id`, `popover`, `onPointerDown`, `onMouseDown`, `data-stale`.\n * Inline `position-area`, `position-try-fallbacks` and `min-width` sit under the consumer's\n * `style` (`style={{ positionTryFallbacks: \"none\" }}` removes the flip).\n */\nexport function ComboboxPopup({\n keepMounted,\n transition,\n className,\n style,\n children,\n render,\n ...rest\n}: ComboboxPopupProps) {\n const ctx = useComboboxContext(\"Combobox.Popup\");\n const { popover } = ctx;\n\n const { setElement, renderContent } = usePopoverPopup(popover, {\n part: \"Combobox.Popup\",\n // Focus stays in the input: nothing inside the popup is ever focused.\n resolveInitialFocus: () => null,\n keepMounted,\n transition,\n });\n\n const devRef = useElementCheck(\n isDev &&\n ((element) =>\n element.tagName !== \"DIV\"\n ? `Combobox.Popup: rendered a <${element.tagName.toLowerCase()}>. Render a <div>: a ` +\n \"<dialog popover> runs the dialog focusing steps and takes focus out of the input.\"\n : null),\n );\n const ref = useMergedRefs(setElement, devRef);\n\n const state: ComboboxPopupState = {\n open: popover.committed,\n stale: ctx.stale,\n query: ctx.query,\n };\n\n const libraryProps: ComponentPropsWithRef<\"div\"> & DataAttributes = {\n id: popover.ids.popup,\n popover: \"auto\",\n onPointerDown: (event: PointerEvent<HTMLDivElement>) => preventDefault(event),\n onMouseDown: (event: MouseEvent<HTMLDivElement>) => preventDefault(event),\n \"data-stale\": dataAttr(ctx.stale),\n };\n\n const content = (s: ComboboxPopupState): ReactNode => (\n <ComboboxPopupContext value={true}>\n {renderContent(() => resolveStateValue(children, s))}\n </ComboboxPopupContext>\n );\n\n const element = useRender<ComponentPropsWithRef<\"div\">, ComboboxPopupState>({\n defaultElement: \"div\",\n render,\n state,\n className,\n // `self-*` keywords resolve against the popup's own inherited direction, so a `dir=\"rtl\"`\n // page or container flips the listbox with no JS; plain logical keywords would follow the\n // root only (design 7.2, conventions 13.1). The consumer wins.\n style: (s) => ({\n positionArea: \"self-block-end span-self-inline-end\",\n positionTryFallbacks: \"flip-block\",\n minWidth: \"anchor-size(width)\",\n ...resolveStateValue(style, s),\n }),\n children: content,\n props: rest,\n libraryProps,\n ref,\n });\n\n return useTransitionBoundary(\"Combobox.Popup\", transition, element);\n}\n\nComboboxPopup.displayName = \"ComboboxPopup\";\n"],"mappings":";;;;;;;;;;;AAmBA,MAAM,QAAQ,QAAQ,IAAI,aAAa;AA2CvC,MAAM,kBAAkB,UAAsC,MAAM,eAAe;;;;;;;;;;;;;AAcnF,SAAgB,cAAc,EAC5B,aACA,YACA,WACA,OACA,UACA,QACA,GAAG,QACkB;CACrB,MAAM,MAAM,mBAAmB,gBAAgB;CAC/C,MAAM,EAAE,YAAY;CAEpB,MAAM,EAAE,YAAY,kBAAkB,gBAAgB,SAAS;EAC7D,MAAM;EAEN,2BAA2B;EAC3B;EACA;CACF,CAAC;CAED,MAAM,SAAS,gBACb,WACI,YACA,QAAQ,YAAY,QAChB,+BAA+B,QAAQ,QAAQ,YAAY,EAAE,0GAE7D,KACV;CACA,MAAM,MAAM,cAAc,YAAY,MAAM;CAE5C,MAAM,QAA4B;EAChC,MAAM,QAAQ;EACd,OAAO,IAAI;EACX,OAAO,IAAI;CACb;CAEA,MAAM,eAA8D;EAClE,IAAI,QAAQ,IAAI;EAChB,SAAS;EACT,gBAAgB,UAAwC,eAAe,KAAK;EAC5E,cAAc,UAAsC,eAAe,KAAK;EACxE,cAAc,SAAS,IAAI,KAAK;CAClC;CAEA,MAAM,WAAW,MACf,oBAAC,sBAAD;EAAsB,OAAO;EAC1B,UAAA,oBAAoB,kBAAkB,UAAU,CAAC,CAAC;CAC/B,CAAA;CAGxB,MAAM,UAAU,UAA4D;EAC1E,gBAAgB;EAChB;EACA;EACA;EAIA,QAAQ,OAAO;GACb,cAAc;GACd,sBAAsB;GACtB,UAAU;GACV,GAAG,kBAAkB,OAAO,CAAC;EAC/B;EACA,UAAU;EACV,OAAO;EACP;EACA;CACF,CAAC;CAED,OAAO,sBAAsB,kBAAkB,YAAY,OAAO;AACpE;AAEA,cAAc,cAAc"}
1
+ {"version":3,"file":"combobox-popup.mjs","names":[],"sources":["../../src/combobox/combobox-popup.tsx"],"sourcesContent":["\"use client\";\nimport { useCallback, useEffect, useRef } from \"react\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n MouseEvent,\n PointerEvent,\n ReactNode,\n ViewTransitionClass,\n} from \"react\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport { listenInvokerPresses } from \"../internal/invoker-press.js\";\nimport { isPopoverOpen } from \"../internal/popover-open.js\";\nimport { useTransitionBoundary } from \"../internal/transition-boundary.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 { usePopoverPopup } from \"../internal/use-popover-popup.js\";\nimport { resolveStateValue, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { ComboboxPopupContext, useComboboxContext } from \"./combobox-context.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\nexport interface ComboboxPopupState {\n /** Committed open state. Read `:popover-open` for the DOM truth. */\n readonly open: boolean;\n /** The results shown are for an older text. */\n readonly stale: boolean;\n /** The deferred text the results are for. */\n readonly query: string;\n}\n\nexport interface ComboboxPopupProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n | \"id\"\n | \"popover\"\n | \"onToggle\"\n | \"onBeforeToggle\"\n | \"onPointerDown\"\n | \"onMouseDown\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /**\n * `false` (default): the children are not rendered while the listbox is closed. `true`: they\n * stay mounted inside `<Activity mode=\"hidden\">`.\n */\n keepMounted?: boolean;\n /**\n * Forwarded to the `<ViewTransition default>` around the popover element itself. Animates\n * library-driven opens and closes (typing, the Trigger, an accepted option) in every engine;\n * dismissals are the browser's (CSS only). **A deferred results render also activates the\n * boundary** (React: updates from `useDeferredValue` animate), so use a type map with\n * `default: \"none\"` unless every result change should cross-fade. Static.\n */\n transition?: ViewTransitionClass;\n className?: StateValue<string | undefined, ComboboxPopupState>;\n style?: StateValue<CSSProperties | undefined, ComboboxPopupState>;\n children?: StateValue<ReactNode, ComboboxPopupState>;\n /** Must render a `<div>`: a `<dialog>` would pull focus out of the input. */\n render?: RenderProp<ComponentPropsWithRef<\"div\">, ComboboxPopupState>;\n}\n\nconst preventDefault = (event: { preventDefault(): void }) => event.preventDefault();\n\n/**\n * The listbox's container: `<div popover=\"auto\">`, opened by the library with\n * `showPopover({ source: input })` and placed below (or, flipped, above) the input with CSS\n * Anchor Positioning, at least as wide as the input. Focus never enters it: a press anywhere in\n * it is `preventDefault()`ed so the input keeps focus (design 7.1), and so is a press on a button\n * of the consumer's that names the popup (`popovertarget`, `commandfor`) while it is shown: its\n * click closes the listbox as `\"activate\"` with the text untouched (#126). Holds the `List` and,\n * outside it, `Empty` and `Status`. Style it with `:popover-open`; it emits `data-stale` but no\n * `data-open`.\n *\n * Owned keys (conventions 1.2): `id`, `popover`, `onPointerDown`, `onMouseDown`, `data-stale`.\n * Inline `position-area`, `position-try-fallbacks` and `min-width` sit under the consumer's\n * `style` (`style={{ positionTryFallbacks: \"none\" }}` removes the flip).\n */\nexport function ComboboxPopup({\n keepMounted,\n transition,\n className,\n style,\n children,\n render,\n ...rest\n}: ComboboxPopupProps) {\n const ctx = useComboboxContext(\"Combobox.Popup\");\n const { popover } = ctx;\n\n // While shown, a press on a foreign invoker of the popup keeps focus in the input (design 5.4,\n // #126).\n const invokerPresses = useRef<(() => void) | null>(null);\n const stopInvokerPresses = useCallback(() => {\n invokerPresses.current?.();\n invokerPresses.current = null;\n }, []);\n useEffect(() => stopInvokerPresses, [stopInvokerPresses]);\n\n const { setElement, renderContent } = usePopoverPopup(popover, {\n part: \"Combobox.Popup\",\n // Focus stays in the input: nothing inside the popup is ever focused.\n resolveInitialFocus: () => null,\n keepMounted,\n transition,\n onToggle: (event) => {\n const element = popover.popupRef.current;\n if (event.newState === \"open\" && element !== null && isPopoverOpen(element)) {\n invokerPresses.current ??= listenInvokerPresses(element);\n } else if (event.newState === \"closed\") {\n stopInvokerPresses();\n }\n },\n });\n\n const devRef = useElementCheck(\n isDev &&\n ((element) =>\n element.tagName !== \"DIV\"\n ? `Combobox.Popup: rendered a <${element.tagName.toLowerCase()}>. Render a <div>: a ` +\n \"<dialog popover> runs the dialog focusing steps and takes focus out of the input.\"\n : null),\n );\n const ref = useMergedRefs(setElement, devRef);\n\n const state: ComboboxPopupState = {\n open: popover.committed,\n stale: ctx.stale,\n query: ctx.query,\n };\n\n const libraryProps: ComponentPropsWithRef<\"div\"> & DataAttributes = {\n id: popover.ids.popup,\n popover: \"auto\",\n onPointerDown: (event: PointerEvent<HTMLDivElement>) => preventDefault(event),\n onMouseDown: (event: MouseEvent<HTMLDivElement>) => preventDefault(event),\n \"data-stale\": dataAttr(ctx.stale),\n };\n\n const content = (s: ComboboxPopupState): ReactNode => (\n <ComboboxPopupContext value={true}>\n {renderContent(() => resolveStateValue(children, s))}\n </ComboboxPopupContext>\n );\n\n const element = useRender<ComponentPropsWithRef<\"div\">, ComboboxPopupState>({\n defaultElement: \"div\",\n render,\n state,\n className,\n // `self-*` keywords resolve against the popup's own inherited direction, so a `dir=\"rtl\"`\n // page or container flips the listbox with no JS; plain logical keywords would follow the\n // root only (design 7.2, conventions 13.1). The consumer wins.\n style: (s) => ({\n positionArea: \"self-block-end span-self-inline-end\",\n positionTryFallbacks: \"flip-block\",\n minWidth: \"anchor-size(width)\",\n ...resolveStateValue(style, s),\n }),\n children: content,\n props: rest,\n libraryProps,\n ref,\n });\n\n return useTransitionBoundary(\"Combobox.Popup\", transition, element);\n}\n\nComboboxPopup.displayName = \"ComboboxPopup\";\n"],"mappings":";;;;;;;;;;;;;;AAsBA,MAAM,QAAQ,QAAQ,IAAI,aAAa;AA2CvC,MAAM,kBAAkB,UAAsC,MAAM,eAAe;;;;;;;;;;;;;;;AAgBnF,SAAgB,cAAc,EAC5B,aACA,YACA,WACA,OACA,UACA,QACA,GAAG,QACkB;CACrB,MAAM,MAAM,mBAAmB,gBAAgB;CAC/C,MAAM,EAAE,YAAY;CAIpB,MAAM,iBAAiB,OAA4B,IAAI;CACvD,MAAM,qBAAqB,kBAAkB;EAC3C,eAAe,UAAU;EACzB,eAAe,UAAU;CAC3B,GAAG,CAAC,CAAC;CACL,gBAAgB,oBAAoB,CAAC,kBAAkB,CAAC;CAExD,MAAM,EAAE,YAAY,kBAAkB,gBAAgB,SAAS;EAC7D,MAAM;EAEN,2BAA2B;EAC3B;EACA;EACA,WAAW,UAAU;GACnB,MAAM,UAAU,QAAQ,SAAS;GACjC,IAAI,MAAM,aAAa,UAAU,YAAY,QAAQ,cAAc,OAAO,GACxE,eAAe,YAAY,qBAAqB,OAAO;QAClD,IAAI,MAAM,aAAa,UAC5B,mBAAmB;EAEvB;CACF,CAAC;CAED,MAAM,SAAS,gBACb,WACI,YACA,QAAQ,YAAY,QAChB,+BAA+B,QAAQ,QAAQ,YAAY,EAAE,0GAE7D,KACV;CACA,MAAM,MAAM,cAAc,YAAY,MAAM;CAE5C,MAAM,QAA4B;EAChC,MAAM,QAAQ;EACd,OAAO,IAAI;EACX,OAAO,IAAI;CACb;CAEA,MAAM,eAA8D;EAClE,IAAI,QAAQ,IAAI;EAChB,SAAS;EACT,gBAAgB,UAAwC,eAAe,KAAK;EAC5E,cAAc,UAAsC,eAAe,KAAK;EACxE,cAAc,SAAS,IAAI,KAAK;CAClC;CAEA,MAAM,WAAW,MACf,oBAAC,sBAAD;EAAsB,OAAO;EAC1B,UAAA,oBAAoB,kBAAkB,UAAU,CAAC,CAAC;CAC/B,CAAA;CAGxB,MAAM,UAAU,UAA4D;EAC1E,gBAAgB;EAChB;EACA;EACA;EAIA,QAAQ,OAAO;GACb,cAAc;GACd,sBAAsB;GACtB,UAAU;GACV,GAAG,kBAAkB,OAAO,CAAC;EAC/B;EACA,UAAU;EACV,OAAO;EACP;EACA;CACF,CAAC;CAED,OAAO,sBAAsB,kBAAkB,YAAY,OAAO;AACpE;AAEA,cAAc,cAAc"}
@@ -1 +1 @@
1
- {"version":3,"file":"combobox-root.d.mts","names":[],"sources":["../../src/combobox/combobox-root.tsx"],"mappings":";;;;iBAuCiB,mCAAmC;;;;;;;WAOzC,QAAQ;;WAER;;;iBAIM,wCAAwC;;;;;;;WAO9C,QAAQ;;;iBAIF,kCAAkC;;;;;;;WAOxC,QAAQ;;iBAGF;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;WACA;;iBAGM;;EAEf;;EAEA;;;;;;;;EAQA,oBAAoB,4BAA4B;;EAGhD;;;;;EAKA;;;;;;;;;EASA,qBAAqB,4BAA4B;;EAGjD;;EAEA;;;;;EAKA,mBAAmB,sBAAsB;;;;;;;EAQzC;;;;;EAKA;;EAEA;;EAEA;;;;;;;EAOA,YAAY,eAAe,OAAO;;EAGlC;;EAEA;;EAEA;EACA,WAAW,WAAW,WAAW;;;;;;;;;;;wBAkDnB,aAAa,OAAO,oCAAiB,IAAA;yBAArC"}
1
+ {"version":3,"file":"combobox-root.d.mts","names":[],"sources":["../../src/combobox/combobox-root.tsx"],"mappings":";;;;iBAwCiB,mCAAmC;;;;;;;WAOzC,QAAQ;;WAER;;;iBAIM,wCAAwC;;;;;;;WAO9C,QAAQ;;;iBAIF,kCAAkC;;;;;;;WAOxC,QAAQ;;iBAGF;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;WACA;;iBAGM;;EAEf;;EAEA;;;;;;;;EAQA,oBAAoB,4BAA4B;;EAGhD;;;;;EAKA;;;;;;;;;EASA,qBAAqB,4BAA4B;;EAGjD;;EAEA;;;;;EAKA,mBAAmB,sBAAsB;;;;;;;EAQzC;;;;;EAKA;;EAEA;;EAEA;;;;;;;EAOA,YAAY,eAAe,OAAO;;EAGlC;;EAEA;;EAEA;EACA,WAAW,WAAW,WAAW;;;;;;;;;;;wBAkDnB,aAAa,OAAO,oCAAiB,IAAA;yBAArC"}
@@ -9,6 +9,7 @@ import { isPopoverOpen } from "../internal/popover-open.mjs";
9
9
  import { FieldContext } from "../internal/field-context.mjs";
10
10
  import { useFieldValueChange } from "../internal/use-field-control.mjs";
11
11
  import { popoverDetails, useOverlayRoot } from "../internal/use-overlay-root.mjs";
12
+ import { capturePointer } from "../internal/pointer-capture.mjs";
12
13
  import { ComboboxContext } from "./combobox-context.mjs";
13
14
  import { useComboboxForm } from "./use-combobox-form.mjs";
14
15
  import { useOptionRegistry } from "./use-option-registry.mjs";
@@ -383,28 +384,92 @@ function ComboboxRoot(props) {
383
384
  if (textRef.current !== label) writeText(label, "dismiss", event);
384
385
  };
385
386
  const leaveRef = useLatest(leave);
387
+ const presses = useRef(/* @__PURE__ */ new Set());
388
+ const afterPress = useRef(null);
389
+ const unwatchPresses = useRef(null);
390
+ const unwatch = () => {
391
+ unwatchPresses.current?.();
392
+ unwatchPresses.current = null;
393
+ presses.current.clear();
394
+ afterPress.current = null;
395
+ };
396
+ const watchPresses = (input) => {
397
+ presses.current.clear();
398
+ if (unwatchPresses.current !== null) return;
399
+ const doc = input.ownerDocument;
400
+ const win = doc.defaultView;
401
+ const released = () => {
402
+ const check = afterPress.current;
403
+ if (check === null || presses.current.size > 0) return;
404
+ unwatch();
405
+ setTimeout(check, 0);
406
+ };
407
+ const down = (event) => {
408
+ presses.current.add(event.pointerId);
409
+ };
410
+ const up = (event) => {
411
+ presses.current.delete(event.pointerId);
412
+ released();
413
+ };
414
+ const blur = () => {
415
+ presses.current.clear();
416
+ released();
417
+ };
418
+ doc.addEventListener("pointerdown", down, true);
419
+ doc.addEventListener("pointerup", up, true);
420
+ doc.addEventListener("pointercancel", up, true);
421
+ win?.addEventListener("blur", blur);
422
+ unwatchPresses.current = () => {
423
+ doc.removeEventListener("pointerdown", down, true);
424
+ doc.removeEventListener("pointerup", up, true);
425
+ doc.removeEventListener("pointercancel", up, true);
426
+ win?.removeEventListener("blur", blur);
427
+ };
428
+ };
429
+ useEffect(() => {
430
+ const input = inputRef.current;
431
+ if (input !== null && input.ownerDocument.activeElement === input) watchPresses(input);
432
+ return unwatch;
433
+ }, []);
434
+ const focusIn = (event) => {
435
+ watchPresses(event.currentTarget);
436
+ };
386
437
  const focusOut = (event) => {
387
438
  const input = inputRef.current;
388
439
  const popup = popover.popupRef.current;
389
440
  const next = event.relatedTarget;
390
441
  if (next instanceof Node) {
391
442
  if (next === input || popup !== null && popup.contains(next)) return;
443
+ unwatch();
392
444
  leave(event);
393
445
  return;
394
446
  }
395
- if (input === null) return;
447
+ if (input === null) {
448
+ unwatch();
449
+ return;
450
+ }
396
451
  const doc = input.ownerDocument;
397
- setTimeout(() => {
452
+ const check = () => {
398
453
  if (!doc.hasFocus()) return;
399
454
  const active = doc.activeElement;
400
455
  if (active === input || active !== null && popup !== null && popup.contains(active)) return;
401
456
  if (input.isConnected) leaveRef.current(event);
402
- }, 0);
457
+ };
458
+ if (presses.current.size > 0) afterPress.current = check;
459
+ else {
460
+ unwatch();
461
+ setTimeout(check, 0);
462
+ }
403
463
  };
404
464
  const inputClick = (event) => {
405
465
  if (disabled || !openOnClick) return;
406
466
  popover.requestOpen(event, "activate");
407
467
  };
468
+ const inputPointerDown = (event) => {
469
+ if (disabled || event.button !== 0) return;
470
+ const popup = popover.popupRef.current;
471
+ if (popup !== null && isPopoverOpen(popup)) capturePointer(popup, event.pointerId);
472
+ };
408
473
  const context = {
409
474
  popover,
410
475
  ids,
@@ -430,8 +495,10 @@ function ComboboxRoot(props) {
430
495
  clear,
431
496
  typed,
432
497
  keyDown,
498
+ focusIn,
433
499
  focusOut,
434
- inputClick
500
+ inputClick,
501
+ inputPointerDown
435
502
  };
436
503
  return /* @__PURE__ */ jsxs(ComboboxContext, {
437
504
  value: context,