@ariakit/react-core 0.3.7 → 0.3.8

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 (117) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/cjs/__chunks/{VEG6PRAG.cjs → 3WCBE6SU.cjs} +3 -1
  3. package/cjs/__chunks/{CILQPSH2.cjs → FA25CV2I.cjs} +2 -2
  4. package/cjs/__chunks/{AYDXWQBF.cjs → L3WS5HGI.cjs} +2 -0
  5. package/cjs/__chunks/{QU2266CJ.cjs → WH4I6OSN.cjs} +12 -4
  6. package/cjs/__chunks/{LVOI2KVN.cjs → XGKLTARH.cjs} +2 -2
  7. package/cjs/checkbox/checkbox-provider.cjs +2 -2
  8. package/cjs/combobox/combobox-cancel.cjs +2 -2
  9. package/cjs/combobox/combobox-context.cjs +4 -2
  10. package/cjs/combobox/combobox-context.d.cts +6 -5
  11. package/cjs/combobox/combobox-context.d.ts +6 -5
  12. package/cjs/combobox/combobox-disclosure.cjs +2 -2
  13. package/cjs/combobox/combobox-item-check.cjs +50 -0
  14. package/cjs/combobox/combobox-item-check.d.cts +60 -0
  15. package/cjs/combobox/combobox-item-check.d.ts +60 -0
  16. package/cjs/combobox/combobox-item-value.cjs +3 -3
  17. package/cjs/combobox/combobox-item.cjs +45 -8
  18. package/cjs/combobox/combobox-item.d.cts +31 -13
  19. package/cjs/combobox/combobox-item.d.ts +31 -13
  20. package/cjs/combobox/combobox-label.cjs +55 -0
  21. package/cjs/combobox/combobox-label.d.cts +42 -0
  22. package/cjs/combobox/combobox-label.d.ts +42 -0
  23. package/cjs/combobox/combobox-list.cjs +3 -3
  24. package/cjs/combobox/combobox-popover.cjs +5 -5
  25. package/cjs/combobox/combobox-provider.cjs +4 -4
  26. package/cjs/combobox/combobox-provider.d.cts +8 -4
  27. package/cjs/combobox/combobox-provider.d.ts +8 -4
  28. package/cjs/combobox/combobox-row.cjs +2 -2
  29. package/cjs/combobox/combobox-separator.cjs +2 -2
  30. package/cjs/combobox/combobox-store.cjs +2 -2
  31. package/cjs/combobox/combobox-store.d.cts +26 -8
  32. package/cjs/combobox/combobox-store.d.ts +26 -8
  33. package/cjs/combobox/combobox.cjs +22 -12
  34. package/cjs/composite/composite-hover.d.cts +3 -0
  35. package/cjs/composite/composite-hover.d.ts +3 -0
  36. package/cjs/composite/composite-item.d.cts +3 -0
  37. package/cjs/composite/composite-item.d.ts +3 -0
  38. package/cjs/disclosure/disclosure-content.d.cts +1 -0
  39. package/cjs/disclosure/disclosure-content.d.ts +1 -0
  40. package/cjs/disclosure/disclosure.d.cts +3 -0
  41. package/cjs/disclosure/disclosure.d.ts +3 -0
  42. package/cjs/focusable/focusable.d.cts +1 -0
  43. package/cjs/focusable/focusable.d.ts +1 -0
  44. package/cjs/form/form-checkbox.cjs +1 -1
  45. package/cjs/hovercard/hovercard-anchor.d.cts +3 -0
  46. package/cjs/hovercard/hovercard-anchor.d.ts +3 -0
  47. package/cjs/menu/menu-item-checkbox.cjs +1 -1
  48. package/cjs/menu/menu-provider.cjs +3 -3
  49. package/cjs/menu/menu-store.cjs +3 -3
  50. package/cjs/menu/menu-store.d.cts +5 -11
  51. package/cjs/menu/menu-store.d.ts +5 -11
  52. package/cjs/popover/popover.d.cts +4 -0
  53. package/cjs/popover/popover.d.ts +4 -0
  54. package/cjs/portal/portal.d.cts +3 -0
  55. package/cjs/portal/portal.d.ts +3 -0
  56. package/cjs/select/select-item.cjs +3 -3
  57. package/cjs/select/select-label.cjs +1 -1
  58. package/cjs/select/select-provider.cjs +3 -3
  59. package/cjs/select/select-store.cjs +3 -3
  60. package/cjs/select/select-store.d.cts +1 -7
  61. package/cjs/select/select-store.d.ts +1 -7
  62. package/combobox/combobox-item-check/package.json +8 -0
  63. package/combobox/combobox-label/package.json +8 -0
  64. package/esm/__chunks/{KFUKDUTY.js → 4AMOOZBQ.js} +10 -2
  65. package/esm/__chunks/{PHTJ3BCW.js → 7HYEBVZE.js} +1 -1
  66. package/esm/__chunks/{NE6JAKK6.js → P3UZS6BC.js} +1 -1
  67. package/esm/__chunks/{MTC2KUZZ.js → W76OTZCC.js} +3 -1
  68. package/esm/__chunks/{24AKC2LC.js → ZETMAOTK.js} +2 -0
  69. package/esm/checkbox/checkbox-provider.js +3 -3
  70. package/esm/combobox/combobox-cancel.js +1 -1
  71. package/esm/combobox/combobox-context.d.ts +6 -5
  72. package/esm/combobox/combobox-context.js +3 -1
  73. package/esm/combobox/combobox-disclosure.js +1 -1
  74. package/esm/combobox/combobox-item-check.d.ts +60 -0
  75. package/esm/combobox/combobox-item-check.js +50 -0
  76. package/esm/combobox/combobox-item-value.js +1 -1
  77. package/esm/combobox/combobox-item.d.ts +31 -13
  78. package/esm/combobox/combobox-item.js +44 -7
  79. package/esm/combobox/combobox-label.d.ts +42 -0
  80. package/esm/combobox/combobox-label.js +55 -0
  81. package/esm/combobox/combobox-list.js +2 -2
  82. package/esm/combobox/combobox-popover.js +2 -2
  83. package/esm/combobox/combobox-provider.d.ts +8 -4
  84. package/esm/combobox/combobox-provider.js +2 -2
  85. package/esm/combobox/combobox-row.js +1 -1
  86. package/esm/combobox/combobox-separator.js +1 -1
  87. package/esm/combobox/combobox-store.d.ts +26 -8
  88. package/esm/combobox/combobox-store.js +1 -1
  89. package/esm/combobox/combobox.js +21 -11
  90. package/esm/composite/composite-hover.d.ts +3 -0
  91. package/esm/composite/composite-item.d.ts +3 -0
  92. package/esm/disclosure/disclosure-content.d.ts +1 -0
  93. package/esm/disclosure/disclosure.d.ts +3 -0
  94. package/esm/focusable/focusable.d.ts +1 -0
  95. package/esm/form/form-checkbox.js +1 -1
  96. package/esm/hovercard/hovercard-anchor.d.ts +3 -0
  97. package/esm/menu/menu-item-checkbox.js +1 -1
  98. package/esm/menu/menu-provider.js +2 -2
  99. package/esm/menu/menu-store.d.ts +5 -11
  100. package/esm/menu/menu-store.js +2 -2
  101. package/esm/popover/popover.d.ts +4 -0
  102. package/esm/portal/portal.d.ts +3 -0
  103. package/esm/select/select-item.js +3 -3
  104. package/esm/select/select-label.js +2 -2
  105. package/esm/select/select-provider.js +2 -2
  106. package/esm/select/select-store.d.ts +1 -7
  107. package/esm/select/select-store.js +2 -2
  108. package/package.json +16 -2
  109. package/cjs/collection/collection-context.d.cts +0 -34
  110. package/cjs/collection/collection-context.d.ts +0 -34
  111. package/cjs/composite/utils.d.cts +0 -69
  112. package/cjs/composite/utils.d.ts +0 -69
  113. package/cjs/tab/tab-store.d.cts +0 -74
  114. package/cjs/tab/tab-store.d.ts +0 -74
  115. package/esm/collection/collection-context.d.ts +0 -34
  116. package/esm/composite/utils.d.ts +0 -69
  117. package/esm/tab/tab-store.d.ts +0 -74
@@ -0,0 +1,50 @@
1
+ "use client";
2
+ import {
3
+ useCheckboxCheck
4
+ } from "../__chunks/MW2F7SEA.js";
5
+ import "../__chunks/6XBVQI3K.js";
6
+ import {
7
+ ComboboxItemCheckedContext
8
+ } from "../__chunks/W76OTZCC.js";
9
+ import "../__chunks/IB7YUKH5.js";
10
+ import "../__chunks/4UUKJZ4V.js";
11
+ import "../__chunks/7H5KSHHF.js";
12
+ import "../__chunks/G6BJYYBK.js";
13
+ import "../__chunks/OAYFXAQ2.js";
14
+ import {
15
+ createComponent,
16
+ createElement,
17
+ createHook
18
+ } from "../__chunks/3ORBWXWF.js";
19
+ import "../__chunks/6O5OEQGF.js";
20
+ import "../__chunks/XM66DUTO.js";
21
+ import {
22
+ __objRest,
23
+ __spreadProps,
24
+ __spreadValues
25
+ } from "../__chunks/4R3V3JGP.js";
26
+
27
+ // src/combobox/combobox-item-check.ts
28
+ import { useContext } from "react";
29
+ var useComboboxItemCheck = createHook(
30
+ (_a) => {
31
+ var _b = _a, { store, checked } = _b, props = __objRest(_b, ["store", "checked"]);
32
+ const context = useContext(ComboboxItemCheckedContext);
33
+ checked = checked != null ? checked : context;
34
+ props = useCheckboxCheck(__spreadProps(__spreadValues({}, props), { checked }));
35
+ return props;
36
+ }
37
+ );
38
+ var ComboboxItemCheck = createComponent(
39
+ (props) => {
40
+ const htmlProps = useComboboxItemCheck(props);
41
+ return createElement("span", htmlProps);
42
+ }
43
+ );
44
+ if (process.env.NODE_ENV !== "production") {
45
+ ComboboxItemCheck.displayName = "ComboboxItemCheck";
46
+ }
47
+ export {
48
+ ComboboxItemCheck,
49
+ useComboboxItemCheck
50
+ };
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  ComboboxItemValueContext,
4
4
  useComboboxScopedContext
5
- } from "../__chunks/MTC2KUZZ.js";
5
+ } from "../__chunks/W76OTZCC.js";
6
6
  import "../__chunks/IB7YUKH5.js";
7
7
  import "../__chunks/4UUKJZ4V.js";
8
8
  import "../__chunks/7H5KSHHF.js";
@@ -52,15 +52,15 @@ export interface ComboboxItemOptions<T extends As = "div"> extends CompositeItem
52
52
  store?: ComboboxStore;
53
53
  /**
54
54
  * The value of the item. This will be rendered as the children by default.
55
- * - If
56
- * [`setValueOnClick`](https://ariakit.org/reference/combobox-item#setvalueonclick)
57
- * is set to `true`, this will be the value of the combobox input when the
58
- * user clicks on this item.
59
- * - If the
60
- * [`autoComplete`](https://ariakit.org/reference/combobox#autocomplete)
61
- * prop on the [`Combobox`](https://ariakit.org/reference/combobox)
62
- * component is set to `both` or `inline`, this will be the value of the
63
- * combobox input when the combobox loses focus.
55
+ * - If
56
+ * [`setValueOnClick`](https://ariakit.org/reference/combobox-item#setvalueonclick)
57
+ * is set to `true`, this will be the value of the combobox input when the
58
+ * user clicks on this item.
59
+ * - If the
60
+ * [`autoComplete`](https://ariakit.org/reference/combobox#autocomplete)
61
+ * prop on the [`Combobox`](https://ariakit.org/reference/combobox)
62
+ * component is set to `both` or `inline`, this will be the value of the
63
+ * combobox input when the combobox loses focus.
64
64
  *
65
65
  * Live examples:
66
66
  * - [Animated Combobox](https://ariakit.org/examples/combobox-animated)
@@ -73,18 +73,36 @@ export interface ComboboxItemOptions<T extends As = "div"> extends CompositeItem
73
73
  */
74
74
  value?: string;
75
75
  /**
76
- * Whether to hide the combobox when this item is clicked.
76
+ * Whether to hide the combobox when this item is clicked. By default, the
77
+ * combobox will be hidden when the user clicks on an item with a
78
+ * [`value`](https://ariakit.org/reference/combobox-item#value) prop, unless
79
+ * the combobox is
80
+ * [multi-selectable](https://ariakit.org/examples/combobox-multiple).
77
81
  *
78
82
  * Live examples:
79
83
  * - [Combobox with links](https://ariakit.org/examples/combobox-links)
80
- * @default true
81
84
  */
82
85
  hideOnClick?: BooleanOrCallback<MouseEvent<HTMLElement>>;
83
86
  /**
84
- * Whether to set the combobox value with this item's value when this item is
85
- * clicked.
87
+ * Whether to set the
88
+ * [`selectedValue`](https://ariakit.org/reference/combobox-provider#selectedvalue)
89
+ * state using this item's
90
+ * [`value`](https://ariakit.org/reference/combobox-item#value) when the item
91
+ * is clicked.
86
92
  * @default true
87
93
  */
94
+ selectValueOnClick?: BooleanOrCallback<MouseEvent<HTMLElement>>;
95
+ /**
96
+ * Whether to set the combobox
97
+ * [`value`](https://ariakit.org/reference/combobox-provider#value) state
98
+ * using this item's
99
+ * [`value`](https://ariakit.org/reference/combobox-item#value) when the item
100
+ * is clicked. The default is `true`, unless the combobox is
101
+ * [multi-selectable](https://ariakit.org/examples/combobox-multiple).
102
+ *
103
+ * Live examples:
104
+ * - [Menu with Combobox](https://ariakit.org/examples/menu-combobox)
105
+ */
88
106
  setValueOnClick?: BooleanOrCallback<MouseEvent<HTMLElement>>;
89
107
  /**
90
108
  * @default false
@@ -3,9 +3,10 @@ import {
3
3
  useCompositeHover
4
4
  } from "../__chunks/G6ONQ5EH.js";
5
5
  import {
6
+ ComboboxItemCheckedContext,
6
7
  ComboboxItemValueContext,
7
8
  useComboboxScopedContext
8
- } from "../__chunks/MTC2KUZZ.js";
9
+ } from "../__chunks/W76OTZCC.js";
9
10
  import {
10
11
  useCompositeItem
11
12
  } from "../__chunks/5PEPOQU7.js";
@@ -44,13 +45,24 @@ import { isDownloading, isOpeningInNewTab } from "@ariakit/core/utils/events";
44
45
  import { hasFocus } from "@ariakit/core/utils/focus";
45
46
  import { invariant } from "@ariakit/core/utils/misc";
46
47
  import { jsx } from "react/jsx-runtime";
48
+ function isSelected(storeValue, itemValue) {
49
+ if (itemValue == null)
50
+ return;
51
+ if (storeValue == null)
52
+ return false;
53
+ if (Array.isArray(storeValue)) {
54
+ return storeValue.includes(itemValue);
55
+ }
56
+ return storeValue === itemValue;
57
+ }
47
58
  var useComboboxItem = createHook(
48
59
  (_a) => {
49
60
  var _b = _a, {
50
61
  store,
51
62
  value,
52
- hideOnClick = value != null,
53
- setValueOnClick = true,
63
+ hideOnClick,
64
+ selectValueOnClick = true,
65
+ setValueOnClick,
54
66
  focusOnHover = false,
55
67
  moveOnKeyPress = true,
56
68
  getItem: getItemProp
@@ -58,6 +70,7 @@ var useComboboxItem = createHook(
58
70
  "store",
59
71
  "value",
60
72
  "hideOnClick",
73
+ "selectValueOnClick",
61
74
  "setValueOnClick",
62
75
  "focusOnHover",
63
76
  "moveOnKeyPress",
@@ -79,8 +92,14 @@ var useComboboxItem = createHook(
79
92
  },
80
93
  [value, getItemProp]
81
94
  );
95
+ const multiSelectable = store.useState(
96
+ (state) => Array.isArray(state.selectedValue)
97
+ );
98
+ setValueOnClick = setValueOnClick != null ? setValueOnClick : !multiSelectable;
99
+ hideOnClick = hideOnClick != null ? hideOnClick : value != null && !multiSelectable;
82
100
  const onClickProp = props.onClick;
83
101
  const setValueOnClickProp = useBooleanEvent(setValueOnClick);
102
+ const selectValueOnClickProp = useBooleanEvent(selectValueOnClick);
84
103
  const hideOnClickProp = useBooleanEvent(hideOnClick);
85
104
  const onClick = useEvent((event) => {
86
105
  onClickProp == null ? void 0 : onClickProp(event);
@@ -90,8 +109,20 @@ var useComboboxItem = createHook(
90
109
  return;
91
110
  if (isOpeningInNewTab(event))
92
111
  return;
93
- if (value != null && setValueOnClickProp(event)) {
94
- store == null ? void 0 : store.setValue(value);
112
+ if (value != null) {
113
+ if (selectValueOnClickProp(event)) {
114
+ store == null ? void 0 : store.setSelectedValue((prevValue) => {
115
+ if (!Array.isArray(prevValue))
116
+ return value;
117
+ if (prevValue.includes(value)) {
118
+ return prevValue.filter((v) => v !== value);
119
+ }
120
+ return [...prevValue, value];
121
+ });
122
+ }
123
+ if (setValueOnClickProp(event)) {
124
+ store == null ? void 0 : store.setValue(value);
125
+ }
95
126
  }
96
127
  if (hideOnClickProp(event)) {
97
128
  store == null ? void 0 : store.move(null);
@@ -116,10 +147,16 @@ var useComboboxItem = createHook(
116
147
  }
117
148
  }
118
149
  });
150
+ const selected = store.useState(
151
+ (state) => isSelected(state.selectedValue, value)
152
+ );
153
+ if (multiSelectable && selected != null) {
154
+ props["aria-selected"] = selected;
155
+ }
119
156
  props = useWrapElement(
120
157
  props,
121
- (element) => /* @__PURE__ */ jsx(ComboboxItemValueContext.Provider, { value, children: element }),
122
- [value]
158
+ (element) => /* @__PURE__ */ jsx(ComboboxItemValueContext.Provider, { value, children: /* @__PURE__ */ jsx(ComboboxItemCheckedContext.Provider, { value: selected != null ? selected : false, children: element }) }),
159
+ [value, selected]
123
160
  );
124
161
  const contentElement = store.useState("contentElement");
125
162
  props = __spreadProps(__spreadValues({
@@ -0,0 +1,42 @@
1
+ import type { As, Options, Props } from "../utils/types.js";
2
+ import type { ComboboxStore } from "./combobox-store.js";
3
+ /**
4
+ * Returns props to create a `ComboboxLabel` component.
5
+ * @see https://ariakit.org/components/combobox
6
+ * @example
7
+ * ```jsx
8
+ * const store = useComboboxStore();
9
+ * const props = useComboboxLabel({ store });
10
+ * <Role {...props}>Favorite fruit</Role>
11
+ * <Combobox store={store} />
12
+ * ```
13
+ */
14
+ export declare const useComboboxLabel: import("../utils/types.js").Hook<ComboboxLabelOptions<"label">>;
15
+ /**
16
+ * Renders a label for the [`Combobox`](https://ariakit.org/reference/combobox)
17
+ * component.
18
+ * @see https://ariakit.org/components/combobox
19
+ * @example
20
+ * ```jsx {2}
21
+ * <ComboboxProvider>
22
+ * <ComboboxLabel>Favorite fruit</ComboboxLabel>
23
+ * <Combobox />
24
+ * <ComboboxPopover>
25
+ * <ComboboxItem value="Apple" />
26
+ * <ComboboxItem value="Orange" />
27
+ * </ComboboxPopover>
28
+ * </ComboboxProvider>
29
+ * ```
30
+ */
31
+ export declare const ComboboxLabel: import("../utils/types.js").Component<ComboboxLabelOptions<"label">>;
32
+ export interface ComboboxLabelOptions<T extends As = "label"> extends Options<T> {
33
+ /**
34
+ * Object returned by the
35
+ * [`useComboboxStore`](https://ariakit.org/reference/use-combobox-store)
36
+ * hook. If not provided, the closest
37
+ * [`ComboboxProvider`](https://ariakit.org/reference/combobox-provider)
38
+ * component's context will be used.
39
+ */
40
+ store?: ComboboxStore;
41
+ }
42
+ export type ComboboxLabelProps<T extends As = "label"> = Props<ComboboxLabelOptions<T>>;
@@ -0,0 +1,55 @@
1
+ "use client";
2
+ import {
3
+ useComboboxProviderContext
4
+ } from "../__chunks/W76OTZCC.js";
5
+ import "../__chunks/IB7YUKH5.js";
6
+ import "../__chunks/4UUKJZ4V.js";
7
+ import "../__chunks/7H5KSHHF.js";
8
+ import "../__chunks/G6BJYYBK.js";
9
+ import "../__chunks/OAYFXAQ2.js";
10
+ import {
11
+ createElement,
12
+ createHook,
13
+ createMemoComponent
14
+ } from "../__chunks/3ORBWXWF.js";
15
+ import "../__chunks/6O5OEQGF.js";
16
+ import "../__chunks/XM66DUTO.js";
17
+ import {
18
+ __objRest,
19
+ __spreadValues
20
+ } from "../__chunks/4R3V3JGP.js";
21
+
22
+ // src/combobox/combobox-label.ts
23
+ import { invariant } from "@ariakit/core/utils/misc";
24
+ var useComboboxLabel = createHook(
25
+ (_a) => {
26
+ var _b = _a, { store } = _b, props = __objRest(_b, ["store"]);
27
+ const context = useComboboxProviderContext();
28
+ store = store || context;
29
+ invariant(
30
+ store,
31
+ process.env.NODE_ENV !== "production" && "ComboboxLabel must receive a `store` prop or be wrapped in a ComboboxProvider component."
32
+ );
33
+ const comboboxId = store.useState((state) => {
34
+ var _a2;
35
+ return (_a2 = state.baseElement) == null ? void 0 : _a2.id;
36
+ });
37
+ props = __spreadValues({
38
+ htmlFor: comboboxId
39
+ }, props);
40
+ return props;
41
+ }
42
+ );
43
+ var ComboboxLabel = createMemoComponent(
44
+ (props) => {
45
+ const htmlProps = useComboboxLabel(props);
46
+ return createElement("label", htmlProps);
47
+ }
48
+ );
49
+ if (process.env.NODE_ENV !== "production") {
50
+ ComboboxLabel.displayName = "ComboboxLabel";
51
+ }
52
+ export {
53
+ ComboboxLabel,
54
+ useComboboxLabel
55
+ };
@@ -2,8 +2,8 @@
2
2
  import {
3
3
  ComboboxList,
4
4
  useComboboxList
5
- } from "../__chunks/KFUKDUTY.js";
6
- import "../__chunks/MTC2KUZZ.js";
5
+ } from "../__chunks/4AMOOZBQ.js";
6
+ import "../__chunks/W76OTZCC.js";
7
7
  import "../__chunks/IB7YUKH5.js";
8
8
  import "../__chunks/4UUKJZ4V.js";
9
9
  import "../__chunks/A7CE3X6M.js";
@@ -1,10 +1,10 @@
1
1
  "use client";
2
2
  import {
3
3
  useComboboxList
4
- } from "../__chunks/KFUKDUTY.js";
4
+ } from "../__chunks/4AMOOZBQ.js";
5
5
  import {
6
6
  useComboboxProviderContext
7
- } from "../__chunks/MTC2KUZZ.js";
7
+ } from "../__chunks/W76OTZCC.js";
8
8
  import "../__chunks/IB7YUKH5.js";
9
9
  import "../__chunks/4UUKJZ4V.js";
10
10
  import {
@@ -1,5 +1,7 @@
1
- import type { ReactNode } from "react";
2
- import type { ComboboxStoreProps } from "./combobox-store.js";
1
+ import type { ReactElement, ReactNode } from "react";
2
+ import type { PickRequired } from "@ariakit/core/utils/types";
3
+ import type { ComboboxStoreProps, ComboboxStoreSelectedValue } from "./combobox-store.js";
4
+ type Value = ComboboxStoreSelectedValue;
3
5
  /**
4
6
  * Provides a combobox store to Combobox components.
5
7
  * @see https://ariakit.org/components/combobox
@@ -15,7 +17,9 @@ import type { ComboboxStoreProps } from "./combobox-store.js";
15
17
  * </ComboboxProvider>
16
18
  * ```
17
19
  */
18
- export declare function ComboboxProvider(props?: ComboboxProviderProps): import("react/jsx-runtime").JSX.Element;
19
- export interface ComboboxProviderProps extends ComboboxStoreProps {
20
+ export declare function ComboboxProvider<T extends Value = Value>(props: PickRequired<ComboboxProviderProps<T>, "selectedValue" | "defaultSelectedValue">): ReactElement;
21
+ export declare function ComboboxProvider(props?: ComboboxProviderProps): ReactElement;
22
+ export interface ComboboxProviderProps<T extends Value = Value> extends ComboboxStoreProps<T> {
20
23
  children?: ReactNode;
21
24
  }
25
+ export {};
@@ -1,10 +1,10 @@
1
1
  "use client";
2
2
  import {
3
3
  useComboboxStore
4
- } from "../__chunks/24AKC2LC.js";
4
+ } from "../__chunks/ZETMAOTK.js";
5
5
  import {
6
6
  ComboboxContextProvider
7
- } from "../__chunks/MTC2KUZZ.js";
7
+ } from "../__chunks/W76OTZCC.js";
8
8
  import "../__chunks/ELWRSPQ7.js";
9
9
  import "../__chunks/5A2VZUUV.js";
10
10
  import "../__chunks/IB7YUKH5.js";
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import {
3
3
  useComboboxScopedContext
4
- } from "../__chunks/MTC2KUZZ.js";
4
+ } from "../__chunks/W76OTZCC.js";
5
5
  import {
6
6
  useCompositeRow
7
7
  } from "../__chunks/BNUFNEVY.js";
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import {
3
3
  useComboboxScopedContext
4
- } from "../__chunks/MTC2KUZZ.js";
4
+ } from "../__chunks/W76OTZCC.js";
5
5
  import {
6
6
  useCompositeSeparator
7
7
  } from "../__chunks/ENRQQ6LK.js";
@@ -1,7 +1,9 @@
1
1
  import * as Core from "@ariakit/core/combobox/combobox-store";
2
+ import type { PickRequired } from "@ariakit/core/utils/types";
2
3
  import type { CompositeStoreFunctions, CompositeStoreOptions, CompositeStoreState } from "../composite/composite-store.js";
3
4
  import type { PopoverStoreFunctions, PopoverStoreOptions, PopoverStoreState } from "../popover/popover-store.js";
4
5
  import type { Store } from "../utils/store.js";
6
+ type Value = Core.ComboboxStoreSelectedValue;
5
7
  export declare function useComboboxStoreProps<T extends Core.ComboboxStore>(store: T, update: () => void, props: ComboboxStoreProps): T;
6
8
  /**
7
9
  * Creates a combobox store.
@@ -17,15 +19,19 @@ export declare function useComboboxStoreProps<T extends Core.ComboboxStore>(stor
17
19
  * </ComboboxPopover>
18
20
  * ```
19
21
  */
22
+ export declare function useComboboxStore<T extends Value = Value>(props: PickRequired<ComboboxStoreProps<T>, "selectedValue" | "defaultSelectedValue">): ComboboxStore<T>;
20
23
  export declare function useComboboxStore(props?: ComboboxStoreProps): ComboboxStore;
21
24
  export type ComboboxStoreItem = Core.ComboboxStoreItem;
22
- export interface ComboboxStoreState extends Core.ComboboxStoreState, CompositeStoreState<ComboboxStoreItem>, PopoverStoreState {
25
+ export type ComboboxStoreSelectedValue = Core.ComboboxStoreSelectedValue;
26
+ export interface ComboboxStoreState<T extends Value = Value> extends Core.ComboboxStoreState<T>, CompositeStoreState<ComboboxStoreItem>, PopoverStoreState {
23
27
  }
24
- export interface ComboboxStoreFunctions extends Core.ComboboxStoreFunctions, CompositeStoreFunctions<ComboboxStoreItem>, PopoverStoreFunctions {
28
+ export interface ComboboxStoreFunctions<T extends Value = Value> extends Core.ComboboxStoreFunctions<T>, CompositeStoreFunctions<ComboboxStoreItem>, PopoverStoreFunctions {
25
29
  }
26
- export interface ComboboxStoreOptions extends Core.ComboboxStoreOptions, CompositeStoreOptions<ComboboxStoreItem>, PopoverStoreOptions {
30
+ export interface ComboboxStoreOptions<T extends Value = Value> extends Core.ComboboxStoreOptions<T>, CompositeStoreOptions<ComboboxStoreItem>, PopoverStoreOptions {
27
31
  /**
28
- * A callback that gets called when the `value` state changes.
32
+ * A callback that gets called when the
33
+ * [`value`](https://ariakit.org/reference/combobox-provider#value) state
34
+ * changes.
29
35
  *
30
36
  * Live examples:
31
37
  * - [Combobox with integrated
@@ -36,9 +42,21 @@ export interface ComboboxStoreOptions extends Core.ComboboxStoreOptions, Composi
36
42
  * Combobox](https://ariakit.org/examples/combobox-multiple)
37
43
  * - [Menu with Combobox](https://ariakit.org/examples/menu-combobox)
38
44
  * - [Select with Combobox](https://ariakit.org/examples/select-combobox)
39
- * @param value The new value.
40
45
  */
41
- setValue?: (value: ComboboxStoreState["value"]) => void;
46
+ setValue?: (value: ComboboxStoreState<T>["value"]) => void;
47
+ /**
48
+ * A callback that gets called when the
49
+ * [`selectedValue`](https://ariakit.org/reference/combobox-provider#selectedvalue)
50
+ * state changes.
51
+ *
52
+ * Live examples:
53
+ * - [Multi-selectable
54
+ * Combobox](https://ariakit.org/examples/combobox-multiple)
55
+ */
56
+ setSelectedValue?: (value: ComboboxStoreState<T>["selectedValue"]) => void;
57
+ }
58
+ export interface ComboboxStoreProps<T extends Value = Value> extends ComboboxStoreOptions<T>, Core.ComboboxStoreProps<T> {
59
+ }
60
+ export interface ComboboxStore<T extends Value = Value> extends ComboboxStoreFunctions<T>, Store<Core.ComboboxStore<T>> {
42
61
  }
43
- export type ComboboxStoreProps = ComboboxStoreOptions & Core.ComboboxStoreProps;
44
- export type ComboboxStore = ComboboxStoreFunctions & Store<Core.ComboboxStore>;
62
+ export {};
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  useComboboxStore,
4
4
  useComboboxStoreProps
5
- } from "../__chunks/24AKC2LC.js";
5
+ } from "../__chunks/ZETMAOTK.js";
6
6
  import "../__chunks/ELWRSPQ7.js";
7
7
  import "../__chunks/5A2VZUUV.js";
8
8
  import "../__chunks/UNZQE6T7.js";
@@ -4,7 +4,7 @@ import {
4
4
  } from "../__chunks/JCH6MLL2.js";
5
5
  import {
6
6
  useComboboxProviderContext
7
- } from "../__chunks/MTC2KUZZ.js";
7
+ } from "../__chunks/W76OTZCC.js";
8
8
  import {
9
9
  useComposite
10
10
  } from "../__chunks/FHDXHZLB.js";
@@ -231,15 +231,16 @@ var useCombobox = createHook(
231
231
  return;
232
232
  canAutoSelectRef.current = false;
233
233
  }, [open]);
234
+ const resetValueOnSelect = store.useState("resetValueOnSelect");
234
235
  useUpdateEffect(() => {
235
- var _a2;
236
+ var _a2, _b2;
236
237
  if (!store)
237
238
  return;
238
- if (!autoSelect)
239
+ if (!autoSelect && !resetValueOnSelect)
239
240
  return;
240
241
  if (!canAutoSelectRef.current)
241
242
  return;
242
- const { baseElement, contentElement: contentElement2 } = store.getState();
243
+ const { baseElement, contentElement: contentElement2, activeId } = store.getState();
243
244
  if (baseElement && !hasFocus(baseElement))
244
245
  return;
245
246
  if (contentElement2 == null ? void 0 : contentElement2.hasAttribute("data-placing")) {
@@ -247,14 +248,23 @@ var useCombobox = createHook(
247
248
  observer.observe(contentElement2, { attributeFilter: ["data-placing"] });
248
249
  return () => observer.disconnect();
249
250
  }
250
- store.move((_a2 = store.first()) != null ? _a2 : null);
251
+ if (autoSelect) {
252
+ store.move((_a2 = store.first()) != null ? _a2 : null);
253
+ } else {
254
+ const element = (_b2 = store.item(activeId)) == null ? void 0 : _b2.element;
255
+ if (element && "scrollIntoView" in element) {
256
+ element.scrollIntoView({ block: "nearest", inline: "nearest" });
257
+ }
258
+ }
251
259
  return;
252
- }, [store, valueUpdated, storeValue, autoSelect, items]);
253
- useSafeLayoutEffect(() => {
254
- if (autoSelect)
255
- return;
256
- store == null ? void 0 : store.setActiveId(null);
257
- }, [valueUpdated, autoSelect, store]);
260
+ }, [
261
+ store,
262
+ valueUpdated,
263
+ storeValue,
264
+ autoSelect,
265
+ resetValueOnSelect,
266
+ items
267
+ ]);
258
268
  useEffect(() => {
259
269
  if (!inline)
260
270
  return;
@@ -46,6 +46,8 @@ export interface CompositeHoverOptions<T extends As = "div"> extends Options<T>
46
46
  * Determines if the composite item should be focused on hover.
47
47
  *
48
48
  * Live examples:
49
+ * - [Multi-selectable
50
+ * Combobox](https://ariakit.org/examples/combobox-multiple)
49
51
  * - [Combobox with integrated
50
52
  * filter](https://ariakit.org/examples/combobox-filtering-integrated)
51
53
  * - [Textarea with inline
@@ -60,6 +62,7 @@ export interface CompositeHoverOptions<T extends As = "div"> extends Options<T>
60
62
  * is `true`.
61
63
  *
62
64
  * Live examples:
65
+ * - [Navigation Menubar](https://ariakit.org/examples/menubar-navigation)
63
66
  * - [Combobox with integrated
64
67
  * filter](https://ariakit.org/examples/combobox-filtering-integrated)
65
68
  */
@@ -84,6 +84,9 @@ export interface CompositeItemOptions<T extends As = "button"> extends CommandOp
84
84
  * **Note**: This prop has no effect when the
85
85
  * [`virtualFocus`](https://ariakit.org/reference/composite-provider#virtualfocus)
86
86
  * option is enabled.
87
+ *
88
+ * Live examples:
89
+ * - [Navigation Menubar](https://ariakit.org/examples/menubar-navigation)
87
90
  */
88
91
  tabbable?: boolean;
89
92
  }
@@ -61,6 +61,7 @@ export interface DisclosureContentOptions<T extends As = "div"> extends Options<
61
61
  * the DOM when it's hidden.
62
62
  *
63
63
  * Live examples:
64
+ * - [Navigation Menubar](https://ariakit.org/examples/menubar-navigation)
64
65
  * - [Combobox with integrated
65
66
  * filter](https://ariakit.org/examples/combobox-filtering-integrated)
66
67
  * - [Textarea with inline
@@ -42,6 +42,9 @@ export interface DisclosureOptions<T extends As = "button"> extends ButtonOption
42
42
  * [`toggle`](https://ariakit.org/reference/use-disclosure-store#toggle) will
43
43
  * be called on click. This is useful if you want to handle the toggle logic
44
44
  * yourself.
45
+ *
46
+ * Live examples:
47
+ * - [Navigation Menubar](https://ariakit.org/examples/menubar-navigation)
45
48
  * @default true
46
49
  */
47
50
  toggleOnClick?: BooleanOrCallback<MouseEvent<HTMLElement>>;
@@ -106,6 +106,7 @@ export interface FocusableOptions<T extends As = "div"> extends Options<T> {
106
106
  * programmatic equivalent of the `data-focus-visible` attribute.
107
107
  *
108
108
  * Live examples:
109
+ * - [Navigation Menubar](https://ariakit.org/examples/menubar-navigation)
109
110
  * - [Custom Checkbox](https://ariakit.org/examples/checkbox-custom)
110
111
  */
111
112
  onFocusVisible?: BivariantCallback<(event: SyntheticEvent<HTMLElement>) => void>;
@@ -8,10 +8,10 @@ import {
8
8
  import {
9
9
  useCheckbox
10
10
  } from "../__chunks/D42GAV4S.js";
11
+ import "../__chunks/VPR2WHQV.js";
11
12
  import {
12
13
  useCheckboxStore
13
14
  } from "../__chunks/BI7ZXWGY.js";
14
- import "../__chunks/VPR2WHQV.js";
15
15
  import "../__chunks/6XBVQI3K.js";
16
16
  import "../__chunks/NWCBQ4CV.js";
17
17
  import "../__chunks/UH3I23HL.js";
@@ -39,6 +39,9 @@ export interface HovercardAnchorOptions<T extends As = "a"> extends FocusableOpt
39
39
  store?: HovercardStore;
40
40
  /**
41
41
  * Whether to show the hovercard on mouse move.
42
+ *
43
+ * Live examples:
44
+ * - [Navigation Menubar](https://ariakit.org/examples/menubar-navigation)
42
45
  * @default true
43
46
  */
44
47
  showOnHover?: BooleanOrCallback<ReactMouseEvent<HTMLElement>>;
@@ -2,10 +2,10 @@
2
2
  import {
3
3
  useCheckbox
4
4
  } from "../__chunks/D42GAV4S.js";
5
+ import "../__chunks/VPR2WHQV.js";
5
6
  import {
6
7
  useCheckboxStore
7
8
  } from "../__chunks/BI7ZXWGY.js";
8
- import "../__chunks/VPR2WHQV.js";
9
9
  import {
10
10
  useMenuItem
11
11
  } from "../__chunks/JRUYDVPB.js";
@@ -1,12 +1,12 @@
1
1
  "use client";
2
2
  import {
3
3
  useMenuStore
4
- } from "../__chunks/PHTJ3BCW.js";
4
+ } from "../__chunks/7HYEBVZE.js";
5
5
  import {
6
6
  MenuContextProvider
7
7
  } from "../__chunks/YGMEBI3A.js";
8
8
  import "../__chunks/KA4GX64Z.js";
9
- import "../__chunks/MTC2KUZZ.js";
9
+ import "../__chunks/W76OTZCC.js";
10
10
  import "../__chunks/ELWRSPQ7.js";
11
11
  import "../__chunks/5A2VZUUV.js";
12
12
  import "../__chunks/IB7YUKH5.js";