@ariakit/core 0.3.6 → 0.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @ariakit/core
2
2
 
3
+ ## 0.3.7
4
+
5
+ ### Multi-selectable Combobox
6
+
7
+ We've added support for the [Combobox](https://ariakit.org/components/combobox) with multiple selection capabilities using a new [`selectedValue`](https://ariakit.org/reference/combobox-provider#selectedvalue) prop, along with [`defaultSelectedValue`](https://ariakit.org/reference/combobox-provider#defaultselectedvalue) and [`setSelectedValue`](https://ariakit.org/reference/combobox-provider#setselectedvalue).
8
+
9
+ This works similarly to the [`value`](https://ariakit.org/reference/select-provider#value) prop on [Select](https://ariakit.org/components/select) components. If it receives an array, the combobox will allow multiple selections. By default, it's a string that represents the selected value in a single-select combobox.
10
+
11
+ Check out the [Multi-selectable Combobox](https://ariakit.org/examples/combobox-multiple) example to see it in action.
12
+
13
+ ### Other updates
14
+
15
+ - Added [`resetValueOnSelect`](https://ariakit.org/reference/combobox-provider#resetvalueonselect) state to [Combobox](https://ariakit.org/components/combobox) components.
16
+
3
17
  ## 0.3.6
4
18
 
5
19
  - Fixed `setSelectionRange` error when used with [unsupported](https://html.spec.whatwg.org/multipage/input.html#concept-input-apply) input types.
@@ -1,9 +1,9 @@
1
1
  import type { Store, StoreOptions, StoreProps } from "../utils/store.js";
2
2
  import type { BivariantCallback } from "../utils/types.js";
3
- type Item = {
3
+ interface Item {
4
4
  id: string;
5
5
  element?: HTMLElement | null;
6
- };
6
+ }
7
7
  /**
8
8
  * Creates a collection store.
9
9
  */
@@ -60,6 +60,8 @@ export interface CollectionStoreOptions<T extends Item = Item> extends StoreOpti
60
60
  */
61
61
  defaultItems?: CollectionStoreState<T>["items"];
62
62
  }
63
- export type CollectionStoreProps<T extends Item = Item> = CollectionStoreOptions<T> & StoreProps<CollectionStoreState<T>>;
64
- export type CollectionStore<T extends Item = Item> = CollectionStoreFunctions<T> & Store<CollectionStoreState<T>>;
63
+ export interface CollectionStoreProps<T extends Item = Item> extends CollectionStoreOptions<T>, StoreProps<CollectionStoreState<T>> {
64
+ }
65
+ export interface CollectionStore<T extends Item = Item> extends CollectionStoreFunctions<T>, Store<CollectionStoreState<T>> {
66
+ }
65
67
  export {};
@@ -1,9 +1,9 @@
1
1
  import type { Store, StoreOptions, StoreProps } from "../utils/store.js";
2
2
  import type { BivariantCallback } from "../utils/types.js";
3
- type Item = {
3
+ interface Item {
4
4
  id: string;
5
5
  element?: HTMLElement | null;
6
- };
6
+ }
7
7
  /**
8
8
  * Creates a collection store.
9
9
  */
@@ -60,6 +60,8 @@ export interface CollectionStoreOptions<T extends Item = Item> extends StoreOpti
60
60
  */
61
61
  defaultItems?: CollectionStoreState<T>["items"];
62
62
  }
63
- export type CollectionStoreProps<T extends Item = Item> = CollectionStoreOptions<T> & StoreProps<CollectionStoreState<T>>;
64
- export type CollectionStore<T extends Item = Item> = CollectionStoreFunctions<T> & Store<CollectionStoreState<T>>;
63
+ export interface CollectionStoreProps<T extends Item = Item> extends CollectionStoreOptions<T>, StoreProps<CollectionStoreState<T>> {
64
+ }
65
+ export interface CollectionStore<T extends Item = Item> extends CollectionStoreFunctions<T>, Store<CollectionStoreState<T>> {
66
+ }
65
67
  export {};
@@ -68,18 +68,31 @@ function createComboboxStore(props = {}) {
68
68
  "bottom-start"
69
69
  )
70
70
  }));
71
- const initialValue = _3UT5FE6Kcjs.defaultValue.call(void 0,
71
+ const value = _3UT5FE6Kcjs.defaultValue.call(void 0,
72
72
  props.value,
73
73
  syncState == null ? void 0 : syncState.value,
74
74
  props.defaultValue,
75
75
  ""
76
76
  );
77
+ const selectedValue = _3UT5FE6Kcjs.defaultValue.call(void 0,
78
+ props.selectedValue,
79
+ syncState == null ? void 0 : syncState.selectedValue,
80
+ props.defaultSelectedValue,
81
+ ""
82
+ );
83
+ const multiSelectable = Array.isArray(selectedValue);
77
84
  const initialState = _AV6KTKLEcjs.__spreadProps.call(void 0, _AV6KTKLEcjs.__spreadValues.call(void 0, _AV6KTKLEcjs.__spreadValues.call(void 0, {}, composite.getState()), popover.getState()), {
78
- value: initialValue,
85
+ value,
86
+ selectedValue,
87
+ resetValueOnSelect: _3UT5FE6Kcjs.defaultValue.call(void 0,
88
+ props.resetValueOnSelect,
89
+ syncState == null ? void 0 : syncState.resetValueOnSelect,
90
+ multiSelectable
91
+ ),
79
92
  resetValueOnHide: _3UT5FE6Kcjs.defaultValue.call(void 0,
80
93
  props.resetValueOnHide,
81
94
  syncState == null ? void 0 : syncState.resetValueOnHide,
82
- false
95
+ multiSelectable
83
96
  ),
84
97
  activeValue: syncState == null ? void 0 : syncState.activeValue
85
98
  });
@@ -91,7 +104,15 @@ function createComboboxStore(props = {}) {
91
104
  return;
92
105
  if (state.mounted)
93
106
  return;
94
- combobox.setState("value", initialValue);
107
+ combobox.setState("value", value);
108
+ })
109
+ );
110
+ _46BH65MCcjs.setup.call(void 0,
111
+ combobox,
112
+ () => _46BH65MCcjs.sync.call(void 0, combobox, ["resetValueOnSelect", "selectedValue"], (state) => {
113
+ if (!state.resetValueOnSelect)
114
+ return;
115
+ combobox.setState("value", value);
95
116
  })
96
117
  );
97
118
  _46BH65MCcjs.setup.call(void 0,
@@ -122,7 +143,8 @@ function createComboboxStore(props = {}) {
122
143
  })
123
144
  );
124
145
  return _AV6KTKLEcjs.__spreadProps.call(void 0, _AV6KTKLEcjs.__spreadValues.call(void 0, _AV6KTKLEcjs.__spreadValues.call(void 0, _AV6KTKLEcjs.__spreadValues.call(void 0, {}, popover), composite), combobox), {
125
- setValue: (value) => combobox.setState("value", value)
146
+ setValue: (value2) => combobox.setState("value", value2),
147
+ setSelectedValue: (selectedValue2) => combobox.setState("selectedValue", selectedValue2)
126
148
  });
127
149
  }
128
150
 
@@ -1,22 +1,26 @@
1
1
  import type { CompositeStoreFunctions, CompositeStoreItem, CompositeStoreOptions, CompositeStoreState } from "../composite/composite-store.js";
2
2
  import type { PopoverStoreFunctions, PopoverStoreOptions, PopoverStoreState } from "../popover/popover-store.js";
3
3
  import type { Store, StoreOptions, StoreProps } from "../utils/store.js";
4
- import type { SetState } from "../utils/types.js";
5
- type Item = CompositeStoreItem & {
4
+ import type { PickRequired, SetState } from "../utils/types.js";
5
+ type Value = string | string[];
6
+ type MutableValue<T extends Value = Value> = T extends string ? string : T;
7
+ interface Item extends CompositeStoreItem {
6
8
  value?: string;
7
- };
9
+ }
8
10
  /**
9
11
  * Creates a combobox store.
10
12
  */
13
+ export declare function createComboboxStore<T extends Value = Value>(props: PickRequired<ComboboxStoreProps<T>, "selectedValue" | "defaultSelectedValue">): ComboboxStore<T>;
11
14
  export declare function createComboboxStore(props?: ComboboxStoreProps): ComboboxStore;
12
15
  export type ComboboxStoreItem = Item;
13
- export interface ComboboxStoreState extends CompositeStoreState<Item>, PopoverStoreState {
16
+ export type ComboboxStoreSelectedValue = Value;
17
+ export interface ComboboxStoreState<T extends Value = Value> extends CompositeStoreState<Item>, PopoverStoreState {
14
18
  /**
15
19
  * @default true
16
20
  */
17
21
  includesBaseElement: boolean;
18
22
  /**
19
- * The input value.
23
+ * The combobox input value.
20
24
  *
21
25
  * Live examples:
22
26
  * - [Combobox with integrated
@@ -34,47 +38,88 @@ export interface ComboboxStoreState extends CompositeStoreState<Item>, PopoverSt
34
38
  */
35
39
  activeValue: string | undefined;
36
40
  /**
37
- * Whether to reset the value when the combobox popover is hidden.
41
+ * The value(s) of the currently selected item(s). This can be a string or an
42
+ * array of strings. If it's an array, the combobox is considered
43
+ * [multi-selectable](https://ariakit.org/examples/combobox-multiple).
44
+ *
45
+ * Live examples:
46
+ * - [Multi-selectable
47
+ * Combobox](https://ariakit.org/examples/combobox-multiple)
48
+ */
49
+ selectedValue: MutableValue<T>;
50
+ /**
51
+ * Whether to reset the value when the combobox popover closes. This prop is
52
+ * automatically set to `true` by default if the combobox supports multiple
53
+ * selections. In other words, if the
54
+ * [`selectedValue`](https://ariakit.org/reference/combobox-provider#selectedvalue)
55
+ * or
56
+ * [`defaultSelectedValue`](https://ariakit.org/reference/combobox-provider#defaultselectedvalue)
57
+ * props are arrays.
38
58
  *
39
59
  * Live examples:
40
60
  * - [Multi-selectable
41
61
  * Combobox](https://ariakit.org/examples/combobox-multiple)
42
62
  * - [Menu with Combobox](https://ariakit.org/examples/menu-combobox)
43
63
  * - [Select with Combobox](https://ariakit.org/examples/select-combobox)
44
- * @default false
45
64
  */
46
65
  resetValueOnHide: boolean;
47
- }
48
- export interface ComboboxStoreFunctions extends CompositeStoreFunctions<Item>, PopoverStoreFunctions {
49
66
  /**
50
- * Sets the `value` state.
67
+ * Whether to reset the value when an item is selected. This prop is
68
+ * automatically set to `true` by default if the combobox supports multiple
69
+ * selections. In other words, if the
70
+ * [`selectedValue`](https://ariakit.org/reference/combobox-provider#selectedvalue)
71
+ * or
72
+ * [`defaultSelectedValue`](https://ariakit.org/reference/combobox-provider#defaultselectedvalue)
73
+ * props are arrays.
51
74
  *
52
75
  * Live examples:
53
76
  * - [Multi-selectable
54
77
  * Combobox](https://ariakit.org/examples/combobox-multiple)
78
+ */
79
+ resetValueOnSelect: boolean;
80
+ }
81
+ export interface ComboboxStoreFunctions<T extends Value = Value> extends CompositeStoreFunctions<Item>, PopoverStoreFunctions {
82
+ /**
83
+ * Sets the [`value`](https://ariakit.org/reference/combobox-provider#value)
84
+ * state.
85
+ *
86
+ * Live examples:
55
87
  * - [Textarea with inline
56
88
  * Combobox](https://ariakit.org/examples/combobox-textarea)
57
89
  * @example
58
90
  * store.setValue("Hello world");
59
91
  * store.setValue((value) => value + "!");
60
92
  */
61
- setValue: SetState<ComboboxStoreState["value"]>;
93
+ setValue: SetState<ComboboxStoreState<T>["value"]>;
94
+ /**
95
+ * Sets the
96
+ * [`selectedValue`](https://ariakit.org/reference/combobox-provider#selectedvalue)
97
+ * state.
98
+ */
99
+ setSelectedValue: SetState<ComboboxStoreState<T>["selectedValue"]>;
62
100
  }
63
- export interface ComboboxStoreOptions extends StoreOptions<ComboboxStoreState, "includesBaseElement" | "value" | "resetValueOnHide">, CompositeStoreOptions<Item>, PopoverStoreOptions {
101
+ export interface ComboboxStoreOptions<T extends Value = Value> extends StoreOptions<ComboboxStoreState<T>, "includesBaseElement" | "value" | "selectedValue" | "resetValueOnHide" | "resetValueOnSelect">, CompositeStoreOptions<Item>, PopoverStoreOptions {
64
102
  /**
65
103
  * @default null
66
104
  */
67
105
  defaultActiveId?: CompositeStoreOptions<Item>["activeId"];
68
106
  /**
69
- * The combobox initial value.
70
- *
71
- * Live examples:
72
- * - [Multi-selectable
73
- * Combobox](https://ariakit.org/examples/combobox-multiple)
107
+ * The initial value of the combobox input.
108
+ * @default ""
109
+ */
110
+ defaultValue?: ComboboxStoreState<T>["value"];
111
+ /**
112
+ * The initial value of the
113
+ * [`selectedValue`](https://ariakit.org/reference/combobox-provider#selectedvalue)
114
+ * state. This can be a string or an array of strings. If it's an array, the
115
+ * combobox is considered
116
+ * [multi-selectable](https://ariakit.org/examples/combobox-multiple).
74
117
  * @default ""
75
118
  */
76
- defaultValue?: ComboboxStoreState["value"];
119
+ defaultSelectedValue?: ComboboxStoreState<T>["selectedValue"];
120
+ }
121
+ export interface ComboboxStoreProps<T extends Value = Value> extends ComboboxStoreOptions<T>, StoreProps<ComboboxStoreState<T>> {
122
+ }
123
+ export interface ComboboxStore<T extends Value = Value> extends ComboboxStoreFunctions<T>, Store<ComboboxStoreState<T>> {
77
124
  }
78
- export type ComboboxStoreProps = ComboboxStoreOptions & StoreProps<ComboboxStoreState>;
79
- export type ComboboxStore = ComboboxStoreFunctions & Store<ComboboxStoreState>;
80
125
  export {};
@@ -1,22 +1,26 @@
1
1
  import type { CompositeStoreFunctions, CompositeStoreItem, CompositeStoreOptions, CompositeStoreState } from "../composite/composite-store.js";
2
2
  import type { PopoverStoreFunctions, PopoverStoreOptions, PopoverStoreState } from "../popover/popover-store.js";
3
3
  import type { Store, StoreOptions, StoreProps } from "../utils/store.js";
4
- import type { SetState } from "../utils/types.js";
5
- type Item = CompositeStoreItem & {
4
+ import type { PickRequired, SetState } from "../utils/types.js";
5
+ type Value = string | string[];
6
+ type MutableValue<T extends Value = Value> = T extends string ? string : T;
7
+ interface Item extends CompositeStoreItem {
6
8
  value?: string;
7
- };
9
+ }
8
10
  /**
9
11
  * Creates a combobox store.
10
12
  */
13
+ export declare function createComboboxStore<T extends Value = Value>(props: PickRequired<ComboboxStoreProps<T>, "selectedValue" | "defaultSelectedValue">): ComboboxStore<T>;
11
14
  export declare function createComboboxStore(props?: ComboboxStoreProps): ComboboxStore;
12
15
  export type ComboboxStoreItem = Item;
13
- export interface ComboboxStoreState extends CompositeStoreState<Item>, PopoverStoreState {
16
+ export type ComboboxStoreSelectedValue = Value;
17
+ export interface ComboboxStoreState<T extends Value = Value> extends CompositeStoreState<Item>, PopoverStoreState {
14
18
  /**
15
19
  * @default true
16
20
  */
17
21
  includesBaseElement: boolean;
18
22
  /**
19
- * The input value.
23
+ * The combobox input value.
20
24
  *
21
25
  * Live examples:
22
26
  * - [Combobox with integrated
@@ -34,47 +38,88 @@ export interface ComboboxStoreState extends CompositeStoreState<Item>, PopoverSt
34
38
  */
35
39
  activeValue: string | undefined;
36
40
  /**
37
- * Whether to reset the value when the combobox popover is hidden.
41
+ * The value(s) of the currently selected item(s). This can be a string or an
42
+ * array of strings. If it's an array, the combobox is considered
43
+ * [multi-selectable](https://ariakit.org/examples/combobox-multiple).
44
+ *
45
+ * Live examples:
46
+ * - [Multi-selectable
47
+ * Combobox](https://ariakit.org/examples/combobox-multiple)
48
+ */
49
+ selectedValue: MutableValue<T>;
50
+ /**
51
+ * Whether to reset the value when the combobox popover closes. This prop is
52
+ * automatically set to `true` by default if the combobox supports multiple
53
+ * selections. In other words, if the
54
+ * [`selectedValue`](https://ariakit.org/reference/combobox-provider#selectedvalue)
55
+ * or
56
+ * [`defaultSelectedValue`](https://ariakit.org/reference/combobox-provider#defaultselectedvalue)
57
+ * props are arrays.
38
58
  *
39
59
  * Live examples:
40
60
  * - [Multi-selectable
41
61
  * Combobox](https://ariakit.org/examples/combobox-multiple)
42
62
  * - [Menu with Combobox](https://ariakit.org/examples/menu-combobox)
43
63
  * - [Select with Combobox](https://ariakit.org/examples/select-combobox)
44
- * @default false
45
64
  */
46
65
  resetValueOnHide: boolean;
47
- }
48
- export interface ComboboxStoreFunctions extends CompositeStoreFunctions<Item>, PopoverStoreFunctions {
49
66
  /**
50
- * Sets the `value` state.
67
+ * Whether to reset the value when an item is selected. This prop is
68
+ * automatically set to `true` by default if the combobox supports multiple
69
+ * selections. In other words, if the
70
+ * [`selectedValue`](https://ariakit.org/reference/combobox-provider#selectedvalue)
71
+ * or
72
+ * [`defaultSelectedValue`](https://ariakit.org/reference/combobox-provider#defaultselectedvalue)
73
+ * props are arrays.
51
74
  *
52
75
  * Live examples:
53
76
  * - [Multi-selectable
54
77
  * Combobox](https://ariakit.org/examples/combobox-multiple)
78
+ */
79
+ resetValueOnSelect: boolean;
80
+ }
81
+ export interface ComboboxStoreFunctions<T extends Value = Value> extends CompositeStoreFunctions<Item>, PopoverStoreFunctions {
82
+ /**
83
+ * Sets the [`value`](https://ariakit.org/reference/combobox-provider#value)
84
+ * state.
85
+ *
86
+ * Live examples:
55
87
  * - [Textarea with inline
56
88
  * Combobox](https://ariakit.org/examples/combobox-textarea)
57
89
  * @example
58
90
  * store.setValue("Hello world");
59
91
  * store.setValue((value) => value + "!");
60
92
  */
61
- setValue: SetState<ComboboxStoreState["value"]>;
93
+ setValue: SetState<ComboboxStoreState<T>["value"]>;
94
+ /**
95
+ * Sets the
96
+ * [`selectedValue`](https://ariakit.org/reference/combobox-provider#selectedvalue)
97
+ * state.
98
+ */
99
+ setSelectedValue: SetState<ComboboxStoreState<T>["selectedValue"]>;
62
100
  }
63
- export interface ComboboxStoreOptions extends StoreOptions<ComboboxStoreState, "includesBaseElement" | "value" | "resetValueOnHide">, CompositeStoreOptions<Item>, PopoverStoreOptions {
101
+ export interface ComboboxStoreOptions<T extends Value = Value> extends StoreOptions<ComboboxStoreState<T>, "includesBaseElement" | "value" | "selectedValue" | "resetValueOnHide" | "resetValueOnSelect">, CompositeStoreOptions<Item>, PopoverStoreOptions {
64
102
  /**
65
103
  * @default null
66
104
  */
67
105
  defaultActiveId?: CompositeStoreOptions<Item>["activeId"];
68
106
  /**
69
- * The combobox initial value.
70
- *
71
- * Live examples:
72
- * - [Multi-selectable
73
- * Combobox](https://ariakit.org/examples/combobox-multiple)
107
+ * The initial value of the combobox input.
108
+ * @default ""
109
+ */
110
+ defaultValue?: ComboboxStoreState<T>["value"];
111
+ /**
112
+ * The initial value of the
113
+ * [`selectedValue`](https://ariakit.org/reference/combobox-provider#selectedvalue)
114
+ * state. This can be a string or an array of strings. If it's an array, the
115
+ * combobox is considered
116
+ * [multi-selectable](https://ariakit.org/examples/combobox-multiple).
74
117
  * @default ""
75
118
  */
76
- defaultValue?: ComboboxStoreState["value"];
119
+ defaultSelectedValue?: ComboboxStoreState<T>["selectedValue"];
120
+ }
121
+ export interface ComboboxStoreProps<T extends Value = Value> extends ComboboxStoreOptions<T>, StoreProps<ComboboxStoreState<T>> {
122
+ }
123
+ export interface ComboboxStore<T extends Value = Value> extends ComboboxStoreFunctions<T>, Store<ComboboxStoreState<T>> {
77
124
  }
78
- export type ComboboxStoreProps = ComboboxStoreOptions & StoreProps<ComboboxStoreState>;
79
- export type ComboboxStore = ComboboxStoreFunctions & Store<ComboboxStoreState>;
80
125
  export {};
@@ -2,11 +2,11 @@ import type { CollectionStoreFunctions, CollectionStoreItem, CollectionStoreOpti
2
2
  import type { Store, StoreOptions, StoreProps } from "../utils/store.js";
3
3
  import type { SetState } from "../utils/types.js";
4
4
  type Orientation = "horizontal" | "vertical" | "both";
5
- type Item = CollectionStoreItem & {
5
+ interface Item extends CollectionStoreItem {
6
6
  rowId?: string;
7
7
  disabled?: boolean;
8
8
  children?: string;
9
- };
9
+ }
10
10
  /**
11
11
  * Creates a composite store.
12
12
  */
@@ -25,10 +25,6 @@ export interface CompositeStoreState<T extends Item = Item> extends CollectionSt
25
25
  * tabindex](https://www.w3.org/WAI/ARIA/apg/practices/keyboard-interface/#kbd_roving_tabindex).
26
26
  * DOM focus will remain on the composite element while its items receive
27
27
  * virtual focus.
28
- *
29
- * Live examples:
30
- * - [Multi-selectable
31
- * Combobox](https://ariakit.org/examples/combobox-multiple)
32
28
  * @default false
33
29
  */
34
30
  virtualFocus: boolean;
@@ -201,6 +197,8 @@ export interface CompositeStoreOptions<T extends Item = Item> extends StoreOptio
201
197
  */
202
198
  defaultActiveId?: CompositeStoreState<T>["activeId"];
203
199
  }
204
- export type CompositeStoreProps<T extends Item = Item> = CompositeStoreOptions<T> & StoreProps<CompositeStoreState<T>>;
205
- export type CompositeStore<T extends Item = Item> = CompositeStoreFunctions<T> & Store<CompositeStoreState<T>>;
200
+ export interface CompositeStoreProps<T extends Item = Item> extends CompositeStoreOptions<T>, StoreProps<CompositeStoreState<T>> {
201
+ }
202
+ export interface CompositeStore<T extends Item = Item> extends CompositeStoreFunctions<T>, Store<CompositeStoreState<T>> {
203
+ }
206
204
  export {};
@@ -2,11 +2,11 @@ import type { CollectionStoreFunctions, CollectionStoreItem, CollectionStoreOpti
2
2
  import type { Store, StoreOptions, StoreProps } from "../utils/store.js";
3
3
  import type { SetState } from "../utils/types.js";
4
4
  type Orientation = "horizontal" | "vertical" | "both";
5
- type Item = CollectionStoreItem & {
5
+ interface Item extends CollectionStoreItem {
6
6
  rowId?: string;
7
7
  disabled?: boolean;
8
8
  children?: string;
9
- };
9
+ }
10
10
  /**
11
11
  * Creates a composite store.
12
12
  */
@@ -25,10 +25,6 @@ export interface CompositeStoreState<T extends Item = Item> extends CollectionSt
25
25
  * tabindex](https://www.w3.org/WAI/ARIA/apg/practices/keyboard-interface/#kbd_roving_tabindex).
26
26
  * DOM focus will remain on the composite element while its items receive
27
27
  * virtual focus.
28
- *
29
- * Live examples:
30
- * - [Multi-selectable
31
- * Combobox](https://ariakit.org/examples/combobox-multiple)
32
28
  * @default false
33
29
  */
34
30
  virtualFocus: boolean;
@@ -201,6 +197,8 @@ export interface CompositeStoreOptions<T extends Item = Item> extends StoreOptio
201
197
  */
202
198
  defaultActiveId?: CompositeStoreState<T>["activeId"];
203
199
  }
204
- export type CompositeStoreProps<T extends Item = Item> = CompositeStoreOptions<T> & StoreProps<CompositeStoreState<T>>;
205
- export type CompositeStore<T extends Item = Item> = CompositeStoreFunctions<T> & Store<CompositeStoreState<T>>;
200
+ export interface CompositeStoreProps<T extends Item = Item> extends CompositeStoreOptions<T>, StoreProps<CompositeStoreState<T>> {
201
+ }
202
+ export interface CompositeStore<T extends Item = Item> extends CompositeStoreFunctions<T>, Store<CompositeStoreState<T>> {
203
+ }
206
204
  export {};
@@ -36,6 +36,7 @@ export interface DisclosureStoreState {
36
36
  * milliseconds to pass before becoming `false`.
37
37
  *
38
38
  * Live examples:
39
+ * - [Navigation Menubar](https://ariakit.org/examples/menubar-navigation)
39
40
  * - [Animated Combobox](https://ariakit.org/examples/combobox-animated)
40
41
  * - [Animated Dialog](https://ariakit.org/examples/dialog-animated)
41
42
  * - [Animated Select](https://ariakit.org/examples/select-animated)
@@ -73,6 +74,7 @@ export interface DisclosureStoreFunctions {
73
74
  * Sets the `open` state to `true`.
74
75
  *
75
76
  * Live examples:
77
+ * - [Navigation Menubar](https://ariakit.org/examples/menubar-navigation)
76
78
  * - [Textarea with inline
77
79
  * Combobox](https://ariakit.org/examples/combobox-textarea)
78
80
  */
@@ -36,6 +36,7 @@ export interface DisclosureStoreState {
36
36
  * milliseconds to pass before becoming `false`.
37
37
  *
38
38
  * Live examples:
39
+ * - [Navigation Menubar](https://ariakit.org/examples/menubar-navigation)
39
40
  * - [Animated Combobox](https://ariakit.org/examples/combobox-animated)
40
41
  * - [Animated Dialog](https://ariakit.org/examples/dialog-animated)
41
42
  * - [Animated Select](https://ariakit.org/examples/select-animated)
@@ -73,6 +74,7 @@ export interface DisclosureStoreFunctions {
73
74
  * Sets the `open` state to `true`.
74
75
  *
75
76
  * Live examples:
77
+ * - [Navigation Menubar](https://ariakit.org/examples/menubar-navigation)
76
78
  * - [Textarea with inline
77
79
  * Combobox](https://ariakit.org/examples/combobox-textarea)
78
80
  */
@@ -20,11 +20,17 @@ export interface HovercardStoreState extends PopoverStoreState {
20
20
  /**
21
21
  * The amount of time in milliseconds to wait before **showing** the popover.
22
22
  * It defaults to the value passed to `timeout`.
23
+ *
24
+ * Live examples:
25
+ * - [Navigation Menubar](https://ariakit.org/examples/menubar-navigation)
23
26
  */
24
27
  showTimeout?: number;
25
28
  /**
26
29
  * The amount of time in milliseconds to wait before **hiding** the popover.
27
30
  * It defaults to the value passed to `timeout`.
31
+ *
32
+ * Live examples:
33
+ * - [Navigation Menubar](https://ariakit.org/examples/menubar-navigation)
28
34
  */
29
35
  hideTimeout?: number;
30
36
  /**
@@ -20,11 +20,17 @@ export interface HovercardStoreState extends PopoverStoreState {
20
20
  /**
21
21
  * The amount of time in milliseconds to wait before **showing** the popover.
22
22
  * It defaults to the value passed to `timeout`.
23
+ *
24
+ * Live examples:
25
+ * - [Navigation Menubar](https://ariakit.org/examples/menubar-navigation)
23
26
  */
24
27
  showTimeout?: number;
25
28
  /**
26
29
  * The amount of time in milliseconds to wait before **hiding** the popover.
27
30
  * It defaults to the value passed to `timeout`.
31
+ *
32
+ * Live examples:
33
+ * - [Navigation Menubar](https://ariakit.org/examples/menubar-navigation)
28
34
  */
29
35
  hideTimeout?: number;
30
36
  /**
@@ -28,6 +28,9 @@ export interface PopoverStoreState extends DialogStoreState {
28
28
  currentPlacement: Placement;
29
29
  /**
30
30
  * The placement of the popover.
31
+ *
32
+ * Live examples:
33
+ * - [Navigation Menubar](https://ariakit.org/examples/menubar-navigation)
31
34
  * @default "bottom"
32
35
  */
33
36
  placement: Placement;
@@ -28,6 +28,9 @@ export interface PopoverStoreState extends DialogStoreState {
28
28
  currentPlacement: Placement;
29
29
  /**
30
30
  * The placement of the popover.
31
+ *
32
+ * Live examples:
33
+ * - [Navigation Menubar](https://ariakit.org/examples/menubar-navigation)
31
34
  * @default "bottom"
32
35
  */
33
36
  placement: Placement;
@@ -5,9 +5,9 @@ import type { Store, StoreOptions, StoreProps } from "../utils/store.js";
5
5
  import type { PickRequired, SetState } from "../utils/types.js";
6
6
  type Value = string | string[];
7
7
  type MutableValue<T extends Value = Value> = T extends string ? string : T;
8
- type Item = CompositeStoreItem & {
8
+ interface Item extends CompositeStoreItem {
9
9
  value?: string;
10
- };
10
+ }
11
11
  export declare function createSelectStore<T extends Value = Value>(props: PickRequired<SelectStoreProps<T>, "value" | "defaultValue">): SelectStore<T>;
12
12
  export declare function createSelectStore(props?: SelectStoreProps): SelectStore;
13
13
  export type SelectStoreItem = Item;
@@ -27,18 +27,32 @@ export interface SelectStoreState<T extends Value = Value> extends CompositeStor
27
27
  * The select value.
28
28
  *
29
29
  * Live examples:
30
- * - [Multi-selectable
31
- * Combobox](https://ariakit.org/examples/combobox-multiple)
30
+ * - [Form with Select](https://ariakit.org/examples/form-select)
31
+ * - [Select Grid](https://ariakit.org/examples/select-grid)
32
+ * - [Select with custom
33
+ * items](https://ariakit.org/examples/select-item-custom)
34
+ * - [Multi-Select](https://ariakit.org/examples/select-multiple)
35
+ * - [Toolbar with Select](https://ariakit.org/examples/toolbar-select)
32
36
  */
33
37
  value: MutableValue<T>;
34
38
  /**
35
- * Whether the select value should be set when the active item changes by
36
- * moving (which usually happens when moving to an item using the keyboard).
39
+ * Whether the select
40
+ * [`value`](https://ariakit.org/reference/select-provider#value) should be
41
+ * set when the active item changes by moving (which usually happens when
42
+ * moving to an item using the keyboard).
43
+ *
44
+ * Live examples:
45
+ * - [Select Grid](https://ariakit.org/examples/select-grid)
46
+ * - [Select with custom
47
+ * items](https://ariakit.org/examples/select-item-custom)
37
48
  * @default false
38
49
  */
39
50
  setValueOnMove: boolean;
40
51
  /**
41
52
  * The select button element.
53
+ *
54
+ * Live examples:
55
+ * - [Form with Select](https://ariakit.org/examples/form-select)
42
56
  */
43
57
  selectElement: HTMLElement | null;
44
58
  /**
@@ -49,10 +63,6 @@ export interface SelectStoreState<T extends Value = Value> extends CompositeStor
49
63
  export interface SelectStoreFunctions<T extends Value = Value> extends Pick<SelectStoreOptions<T>, "combobox">, CompositeStoreFunctions<Item>, PopoverStoreFunctions {
50
64
  /**
51
65
  * Sets the `value` state.
52
- *
53
- * Live examples:
54
- * - [Multi-selectable
55
- * Combobox](https://ariakit.org/examples/combobox-multiple)
56
66
  * @example
57
67
  * store.setValue("Apple");
58
68
  * store.setValue(["Apple", "Banana"]);
@@ -73,21 +83,21 @@ export interface SelectStoreOptions<T extends Value = Value> extends StoreOption
73
83
  * A reference to a combobox store. This is used when combining the combobox
74
84
  * with a select (e.g., select with a search input). The stores will share the
75
85
  * same state.
76
- *
77
- * Live examples:
78
- * - [Multi-selectable
79
- * Combobox](https://ariakit.org/examples/combobox-multiple)
80
86
  */
81
87
  combobox?: ComboboxStore | null;
82
88
  /**
83
89
  * The default value. If not set, the first non-disabled item will be used.
84
90
  *
85
91
  * Live examples:
86
- * - [Multi-selectable
87
- * Combobox](https://ariakit.org/examples/combobox-multiple)
92
+ * - [Form with Select](https://ariakit.org/examples/form-select)
93
+ * - [Animated Select](https://ariakit.org/examples/select-animated)
94
+ * - [Select with Combobox](https://ariakit.org/examples/select-combobox)
95
+ * - [SelectGroup](https://ariakit.org/examples/select-group)
88
96
  */
89
97
  defaultValue?: SelectStoreState<T>["value"];
90
98
  }
91
- export type SelectStoreProps<T extends Value = Value> = SelectStoreOptions<T> & StoreProps<SelectStoreState<T>>;
92
- export type SelectStore<T extends Value = Value> = SelectStoreFunctions<T> & Store<SelectStoreState<T>>;
99
+ export interface SelectStoreProps<T extends Value = Value> extends SelectStoreOptions<T>, StoreProps<SelectStoreState<T>> {
100
+ }
101
+ export interface SelectStore<T extends Value = Value> extends SelectStoreFunctions<T>, Store<SelectStoreState<T>> {
102
+ }
93
103
  export {};
@@ -5,9 +5,9 @@ import type { Store, StoreOptions, StoreProps } from "../utils/store.js";
5
5
  import type { PickRequired, SetState } from "../utils/types.js";
6
6
  type Value = string | string[];
7
7
  type MutableValue<T extends Value = Value> = T extends string ? string : T;
8
- type Item = CompositeStoreItem & {
8
+ interface Item extends CompositeStoreItem {
9
9
  value?: string;
10
- };
10
+ }
11
11
  export declare function createSelectStore<T extends Value = Value>(props: PickRequired<SelectStoreProps<T>, "value" | "defaultValue">): SelectStore<T>;
12
12
  export declare function createSelectStore(props?: SelectStoreProps): SelectStore;
13
13
  export type SelectStoreItem = Item;
@@ -27,18 +27,32 @@ export interface SelectStoreState<T extends Value = Value> extends CompositeStor
27
27
  * The select value.
28
28
  *
29
29
  * Live examples:
30
- * - [Multi-selectable
31
- * Combobox](https://ariakit.org/examples/combobox-multiple)
30
+ * - [Form with Select](https://ariakit.org/examples/form-select)
31
+ * - [Select Grid](https://ariakit.org/examples/select-grid)
32
+ * - [Select with custom
33
+ * items](https://ariakit.org/examples/select-item-custom)
34
+ * - [Multi-Select](https://ariakit.org/examples/select-multiple)
35
+ * - [Toolbar with Select](https://ariakit.org/examples/toolbar-select)
32
36
  */
33
37
  value: MutableValue<T>;
34
38
  /**
35
- * Whether the select value should be set when the active item changes by
36
- * moving (which usually happens when moving to an item using the keyboard).
39
+ * Whether the select
40
+ * [`value`](https://ariakit.org/reference/select-provider#value) should be
41
+ * set when the active item changes by moving (which usually happens when
42
+ * moving to an item using the keyboard).
43
+ *
44
+ * Live examples:
45
+ * - [Select Grid](https://ariakit.org/examples/select-grid)
46
+ * - [Select with custom
47
+ * items](https://ariakit.org/examples/select-item-custom)
37
48
  * @default false
38
49
  */
39
50
  setValueOnMove: boolean;
40
51
  /**
41
52
  * The select button element.
53
+ *
54
+ * Live examples:
55
+ * - [Form with Select](https://ariakit.org/examples/form-select)
42
56
  */
43
57
  selectElement: HTMLElement | null;
44
58
  /**
@@ -49,10 +63,6 @@ export interface SelectStoreState<T extends Value = Value> extends CompositeStor
49
63
  export interface SelectStoreFunctions<T extends Value = Value> extends Pick<SelectStoreOptions<T>, "combobox">, CompositeStoreFunctions<Item>, PopoverStoreFunctions {
50
64
  /**
51
65
  * Sets the `value` state.
52
- *
53
- * Live examples:
54
- * - [Multi-selectable
55
- * Combobox](https://ariakit.org/examples/combobox-multiple)
56
66
  * @example
57
67
  * store.setValue("Apple");
58
68
  * store.setValue(["Apple", "Banana"]);
@@ -73,21 +83,21 @@ export interface SelectStoreOptions<T extends Value = Value> extends StoreOption
73
83
  * A reference to a combobox store. This is used when combining the combobox
74
84
  * with a select (e.g., select with a search input). The stores will share the
75
85
  * same state.
76
- *
77
- * Live examples:
78
- * - [Multi-selectable
79
- * Combobox](https://ariakit.org/examples/combobox-multiple)
80
86
  */
81
87
  combobox?: ComboboxStore | null;
82
88
  /**
83
89
  * The default value. If not set, the first non-disabled item will be used.
84
90
  *
85
91
  * Live examples:
86
- * - [Multi-selectable
87
- * Combobox](https://ariakit.org/examples/combobox-multiple)
92
+ * - [Form with Select](https://ariakit.org/examples/form-select)
93
+ * - [Animated Select](https://ariakit.org/examples/select-animated)
94
+ * - [Select with Combobox](https://ariakit.org/examples/select-combobox)
95
+ * - [SelectGroup](https://ariakit.org/examples/select-group)
88
96
  */
89
97
  defaultValue?: SelectStoreState<T>["value"];
90
98
  }
91
- export type SelectStoreProps<T extends Value = Value> = SelectStoreOptions<T> & StoreProps<SelectStoreState<T>>;
92
- export type SelectStore<T extends Value = Value> = SelectStoreFunctions<T> & Store<SelectStoreState<T>>;
99
+ export interface SelectStoreProps<T extends Value = Value> extends SelectStoreOptions<T>, StoreProps<SelectStoreState<T>> {
100
+ }
101
+ export interface SelectStore<T extends Value = Value> extends SelectStoreFunctions<T>, Store<SelectStoreState<T>> {
102
+ }
93
103
  export {};
@@ -46,6 +46,9 @@ export type StoreOptions<S extends State, K extends keyof S> = Partial<Pick<S, K
46
46
  export type StoreProps<S extends State = State> = {
47
47
  /**
48
48
  * Another store object that will be kept in sync with the original store.
49
+ *
50
+ * Live examples:
51
+ * - [Navigation Menubar](https://ariakit.org/examples/menubar-navigation)
49
52
  */
50
53
  store?: Store<Partial<S>>;
51
54
  };
@@ -46,6 +46,9 @@ export type StoreOptions<S extends State, K extends keyof S> = Partial<Pick<S, K
46
46
  export type StoreProps<S extends State = State> = {
47
47
  /**
48
48
  * Another store object that will be kept in sync with the original store.
49
+ *
50
+ * Live examples:
51
+ * - [Navigation Menubar](https://ariakit.org/examples/menubar-navigation)
49
52
  */
50
53
  store?: Store<Partial<S>>;
51
54
  };
@@ -1,9 +1,9 @@
1
1
  import type { Store, StoreOptions, StoreProps } from "../utils/store.js";
2
2
  import type { BivariantCallback } from "../utils/types.js";
3
- type Item = {
3
+ interface Item {
4
4
  id: string;
5
5
  element?: HTMLElement | null;
6
- };
6
+ }
7
7
  /**
8
8
  * Creates a collection store.
9
9
  */
@@ -60,6 +60,8 @@ export interface CollectionStoreOptions<T extends Item = Item> extends StoreOpti
60
60
  */
61
61
  defaultItems?: CollectionStoreState<T>["items"];
62
62
  }
63
- export type CollectionStoreProps<T extends Item = Item> = CollectionStoreOptions<T> & StoreProps<CollectionStoreState<T>>;
64
- export type CollectionStore<T extends Item = Item> = CollectionStoreFunctions<T> & Store<CollectionStoreState<T>>;
63
+ export interface CollectionStoreProps<T extends Item = Item> extends CollectionStoreOptions<T>, StoreProps<CollectionStoreState<T>> {
64
+ }
65
+ export interface CollectionStore<T extends Item = Item> extends CollectionStoreFunctions<T>, Store<CollectionStoreState<T>> {
66
+ }
65
67
  export {};
@@ -1,22 +1,26 @@
1
1
  import type { CompositeStoreFunctions, CompositeStoreItem, CompositeStoreOptions, CompositeStoreState } from "../composite/composite-store.js";
2
2
  import type { PopoverStoreFunctions, PopoverStoreOptions, PopoverStoreState } from "../popover/popover-store.js";
3
3
  import type { Store, StoreOptions, StoreProps } from "../utils/store.js";
4
- import type { SetState } from "../utils/types.js";
5
- type Item = CompositeStoreItem & {
4
+ import type { PickRequired, SetState } from "../utils/types.js";
5
+ type Value = string | string[];
6
+ type MutableValue<T extends Value = Value> = T extends string ? string : T;
7
+ interface Item extends CompositeStoreItem {
6
8
  value?: string;
7
- };
9
+ }
8
10
  /**
9
11
  * Creates a combobox store.
10
12
  */
13
+ export declare function createComboboxStore<T extends Value = Value>(props: PickRequired<ComboboxStoreProps<T>, "selectedValue" | "defaultSelectedValue">): ComboboxStore<T>;
11
14
  export declare function createComboboxStore(props?: ComboboxStoreProps): ComboboxStore;
12
15
  export type ComboboxStoreItem = Item;
13
- export interface ComboboxStoreState extends CompositeStoreState<Item>, PopoverStoreState {
16
+ export type ComboboxStoreSelectedValue = Value;
17
+ export interface ComboboxStoreState<T extends Value = Value> extends CompositeStoreState<Item>, PopoverStoreState {
14
18
  /**
15
19
  * @default true
16
20
  */
17
21
  includesBaseElement: boolean;
18
22
  /**
19
- * The input value.
23
+ * The combobox input value.
20
24
  *
21
25
  * Live examples:
22
26
  * - [Combobox with integrated
@@ -34,47 +38,88 @@ export interface ComboboxStoreState extends CompositeStoreState<Item>, PopoverSt
34
38
  */
35
39
  activeValue: string | undefined;
36
40
  /**
37
- * Whether to reset the value when the combobox popover is hidden.
41
+ * The value(s) of the currently selected item(s). This can be a string or an
42
+ * array of strings. If it's an array, the combobox is considered
43
+ * [multi-selectable](https://ariakit.org/examples/combobox-multiple).
44
+ *
45
+ * Live examples:
46
+ * - [Multi-selectable
47
+ * Combobox](https://ariakit.org/examples/combobox-multiple)
48
+ */
49
+ selectedValue: MutableValue<T>;
50
+ /**
51
+ * Whether to reset the value when the combobox popover closes. This prop is
52
+ * automatically set to `true` by default if the combobox supports multiple
53
+ * selections. In other words, if the
54
+ * [`selectedValue`](https://ariakit.org/reference/combobox-provider#selectedvalue)
55
+ * or
56
+ * [`defaultSelectedValue`](https://ariakit.org/reference/combobox-provider#defaultselectedvalue)
57
+ * props are arrays.
38
58
  *
39
59
  * Live examples:
40
60
  * - [Multi-selectable
41
61
  * Combobox](https://ariakit.org/examples/combobox-multiple)
42
62
  * - [Menu with Combobox](https://ariakit.org/examples/menu-combobox)
43
63
  * - [Select with Combobox](https://ariakit.org/examples/select-combobox)
44
- * @default false
45
64
  */
46
65
  resetValueOnHide: boolean;
47
- }
48
- export interface ComboboxStoreFunctions extends CompositeStoreFunctions<Item>, PopoverStoreFunctions {
49
66
  /**
50
- * Sets the `value` state.
67
+ * Whether to reset the value when an item is selected. This prop is
68
+ * automatically set to `true` by default if the combobox supports multiple
69
+ * selections. In other words, if the
70
+ * [`selectedValue`](https://ariakit.org/reference/combobox-provider#selectedvalue)
71
+ * or
72
+ * [`defaultSelectedValue`](https://ariakit.org/reference/combobox-provider#defaultselectedvalue)
73
+ * props are arrays.
51
74
  *
52
75
  * Live examples:
53
76
  * - [Multi-selectable
54
77
  * Combobox](https://ariakit.org/examples/combobox-multiple)
78
+ */
79
+ resetValueOnSelect: boolean;
80
+ }
81
+ export interface ComboboxStoreFunctions<T extends Value = Value> extends CompositeStoreFunctions<Item>, PopoverStoreFunctions {
82
+ /**
83
+ * Sets the [`value`](https://ariakit.org/reference/combobox-provider#value)
84
+ * state.
85
+ *
86
+ * Live examples:
55
87
  * - [Textarea with inline
56
88
  * Combobox](https://ariakit.org/examples/combobox-textarea)
57
89
  * @example
58
90
  * store.setValue("Hello world");
59
91
  * store.setValue((value) => value + "!");
60
92
  */
61
- setValue: SetState<ComboboxStoreState["value"]>;
93
+ setValue: SetState<ComboboxStoreState<T>["value"]>;
94
+ /**
95
+ * Sets the
96
+ * [`selectedValue`](https://ariakit.org/reference/combobox-provider#selectedvalue)
97
+ * state.
98
+ */
99
+ setSelectedValue: SetState<ComboboxStoreState<T>["selectedValue"]>;
62
100
  }
63
- export interface ComboboxStoreOptions extends StoreOptions<ComboboxStoreState, "includesBaseElement" | "value" | "resetValueOnHide">, CompositeStoreOptions<Item>, PopoverStoreOptions {
101
+ export interface ComboboxStoreOptions<T extends Value = Value> extends StoreOptions<ComboboxStoreState<T>, "includesBaseElement" | "value" | "selectedValue" | "resetValueOnHide" | "resetValueOnSelect">, CompositeStoreOptions<Item>, PopoverStoreOptions {
64
102
  /**
65
103
  * @default null
66
104
  */
67
105
  defaultActiveId?: CompositeStoreOptions<Item>["activeId"];
68
106
  /**
69
- * The combobox initial value.
70
- *
71
- * Live examples:
72
- * - [Multi-selectable
73
- * Combobox](https://ariakit.org/examples/combobox-multiple)
107
+ * The initial value of the combobox input.
108
+ * @default ""
109
+ */
110
+ defaultValue?: ComboboxStoreState<T>["value"];
111
+ /**
112
+ * The initial value of the
113
+ * [`selectedValue`](https://ariakit.org/reference/combobox-provider#selectedvalue)
114
+ * state. This can be a string or an array of strings. If it's an array, the
115
+ * combobox is considered
116
+ * [multi-selectable](https://ariakit.org/examples/combobox-multiple).
74
117
  * @default ""
75
118
  */
76
- defaultValue?: ComboboxStoreState["value"];
119
+ defaultSelectedValue?: ComboboxStoreState<T>["selectedValue"];
120
+ }
121
+ export interface ComboboxStoreProps<T extends Value = Value> extends ComboboxStoreOptions<T>, StoreProps<ComboboxStoreState<T>> {
122
+ }
123
+ export interface ComboboxStore<T extends Value = Value> extends ComboboxStoreFunctions<T>, Store<ComboboxStoreState<T>> {
77
124
  }
78
- export type ComboboxStoreProps = ComboboxStoreOptions & StoreProps<ComboboxStoreState>;
79
- export type ComboboxStore = ComboboxStoreFunctions & Store<ComboboxStoreState>;
80
125
  export {};
@@ -68,18 +68,31 @@ function createComboboxStore(props = {}) {
68
68
  "bottom-start"
69
69
  )
70
70
  }));
71
- const initialValue = defaultValue(
71
+ const value = defaultValue(
72
72
  props.value,
73
73
  syncState == null ? void 0 : syncState.value,
74
74
  props.defaultValue,
75
75
  ""
76
76
  );
77
+ const selectedValue = defaultValue(
78
+ props.selectedValue,
79
+ syncState == null ? void 0 : syncState.selectedValue,
80
+ props.defaultSelectedValue,
81
+ ""
82
+ );
83
+ const multiSelectable = Array.isArray(selectedValue);
77
84
  const initialState = __spreadProps(__spreadValues(__spreadValues({}, composite.getState()), popover.getState()), {
78
- value: initialValue,
85
+ value,
86
+ selectedValue,
87
+ resetValueOnSelect: defaultValue(
88
+ props.resetValueOnSelect,
89
+ syncState == null ? void 0 : syncState.resetValueOnSelect,
90
+ multiSelectable
91
+ ),
79
92
  resetValueOnHide: defaultValue(
80
93
  props.resetValueOnHide,
81
94
  syncState == null ? void 0 : syncState.resetValueOnHide,
82
- false
95
+ multiSelectable
83
96
  ),
84
97
  activeValue: syncState == null ? void 0 : syncState.activeValue
85
98
  });
@@ -91,7 +104,15 @@ function createComboboxStore(props = {}) {
91
104
  return;
92
105
  if (state.mounted)
93
106
  return;
94
- combobox.setState("value", initialValue);
107
+ combobox.setState("value", value);
108
+ })
109
+ );
110
+ setup(
111
+ combobox,
112
+ () => sync(combobox, ["resetValueOnSelect", "selectedValue"], (state) => {
113
+ if (!state.resetValueOnSelect)
114
+ return;
115
+ combobox.setState("value", value);
95
116
  })
96
117
  );
97
118
  setup(
@@ -122,7 +143,8 @@ function createComboboxStore(props = {}) {
122
143
  })
123
144
  );
124
145
  return __spreadProps(__spreadValues(__spreadValues(__spreadValues({}, popover), composite), combobox), {
125
- setValue: (value) => combobox.setState("value", value)
146
+ setValue: (value2) => combobox.setState("value", value2),
147
+ setSelectedValue: (selectedValue2) => combobox.setState("selectedValue", selectedValue2)
126
148
  });
127
149
  }
128
150
  export {
@@ -2,11 +2,11 @@ import type { CollectionStoreFunctions, CollectionStoreItem, CollectionStoreOpti
2
2
  import type { Store, StoreOptions, StoreProps } from "../utils/store.js";
3
3
  import type { SetState } from "../utils/types.js";
4
4
  type Orientation = "horizontal" | "vertical" | "both";
5
- type Item = CollectionStoreItem & {
5
+ interface Item extends CollectionStoreItem {
6
6
  rowId?: string;
7
7
  disabled?: boolean;
8
8
  children?: string;
9
- };
9
+ }
10
10
  /**
11
11
  * Creates a composite store.
12
12
  */
@@ -25,10 +25,6 @@ export interface CompositeStoreState<T extends Item = Item> extends CollectionSt
25
25
  * tabindex](https://www.w3.org/WAI/ARIA/apg/practices/keyboard-interface/#kbd_roving_tabindex).
26
26
  * DOM focus will remain on the composite element while its items receive
27
27
  * virtual focus.
28
- *
29
- * Live examples:
30
- * - [Multi-selectable
31
- * Combobox](https://ariakit.org/examples/combobox-multiple)
32
28
  * @default false
33
29
  */
34
30
  virtualFocus: boolean;
@@ -201,6 +197,8 @@ export interface CompositeStoreOptions<T extends Item = Item> extends StoreOptio
201
197
  */
202
198
  defaultActiveId?: CompositeStoreState<T>["activeId"];
203
199
  }
204
- export type CompositeStoreProps<T extends Item = Item> = CompositeStoreOptions<T> & StoreProps<CompositeStoreState<T>>;
205
- export type CompositeStore<T extends Item = Item> = CompositeStoreFunctions<T> & Store<CompositeStoreState<T>>;
200
+ export interface CompositeStoreProps<T extends Item = Item> extends CompositeStoreOptions<T>, StoreProps<CompositeStoreState<T>> {
201
+ }
202
+ export interface CompositeStore<T extends Item = Item> extends CompositeStoreFunctions<T>, Store<CompositeStoreState<T>> {
203
+ }
206
204
  export {};
@@ -36,6 +36,7 @@ export interface DisclosureStoreState {
36
36
  * milliseconds to pass before becoming `false`.
37
37
  *
38
38
  * Live examples:
39
+ * - [Navigation Menubar](https://ariakit.org/examples/menubar-navigation)
39
40
  * - [Animated Combobox](https://ariakit.org/examples/combobox-animated)
40
41
  * - [Animated Dialog](https://ariakit.org/examples/dialog-animated)
41
42
  * - [Animated Select](https://ariakit.org/examples/select-animated)
@@ -73,6 +74,7 @@ export interface DisclosureStoreFunctions {
73
74
  * Sets the `open` state to `true`.
74
75
  *
75
76
  * Live examples:
77
+ * - [Navigation Menubar](https://ariakit.org/examples/menubar-navigation)
76
78
  * - [Textarea with inline
77
79
  * Combobox](https://ariakit.org/examples/combobox-textarea)
78
80
  */
@@ -20,11 +20,17 @@ export interface HovercardStoreState extends PopoverStoreState {
20
20
  /**
21
21
  * The amount of time in milliseconds to wait before **showing** the popover.
22
22
  * It defaults to the value passed to `timeout`.
23
+ *
24
+ * Live examples:
25
+ * - [Navigation Menubar](https://ariakit.org/examples/menubar-navigation)
23
26
  */
24
27
  showTimeout?: number;
25
28
  /**
26
29
  * The amount of time in milliseconds to wait before **hiding** the popover.
27
30
  * It defaults to the value passed to `timeout`.
31
+ *
32
+ * Live examples:
33
+ * - [Navigation Menubar](https://ariakit.org/examples/menubar-navigation)
28
34
  */
29
35
  hideTimeout?: number;
30
36
  /**
@@ -28,6 +28,9 @@ export interface PopoverStoreState extends DialogStoreState {
28
28
  currentPlacement: Placement;
29
29
  /**
30
30
  * The placement of the popover.
31
+ *
32
+ * Live examples:
33
+ * - [Navigation Menubar](https://ariakit.org/examples/menubar-navigation)
31
34
  * @default "bottom"
32
35
  */
33
36
  placement: Placement;
@@ -5,9 +5,9 @@ import type { Store, StoreOptions, StoreProps } from "../utils/store.js";
5
5
  import type { PickRequired, SetState } from "../utils/types.js";
6
6
  type Value = string | string[];
7
7
  type MutableValue<T extends Value = Value> = T extends string ? string : T;
8
- type Item = CompositeStoreItem & {
8
+ interface Item extends CompositeStoreItem {
9
9
  value?: string;
10
- };
10
+ }
11
11
  export declare function createSelectStore<T extends Value = Value>(props: PickRequired<SelectStoreProps<T>, "value" | "defaultValue">): SelectStore<T>;
12
12
  export declare function createSelectStore(props?: SelectStoreProps): SelectStore;
13
13
  export type SelectStoreItem = Item;
@@ -27,18 +27,32 @@ export interface SelectStoreState<T extends Value = Value> extends CompositeStor
27
27
  * The select value.
28
28
  *
29
29
  * Live examples:
30
- * - [Multi-selectable
31
- * Combobox](https://ariakit.org/examples/combobox-multiple)
30
+ * - [Form with Select](https://ariakit.org/examples/form-select)
31
+ * - [Select Grid](https://ariakit.org/examples/select-grid)
32
+ * - [Select with custom
33
+ * items](https://ariakit.org/examples/select-item-custom)
34
+ * - [Multi-Select](https://ariakit.org/examples/select-multiple)
35
+ * - [Toolbar with Select](https://ariakit.org/examples/toolbar-select)
32
36
  */
33
37
  value: MutableValue<T>;
34
38
  /**
35
- * Whether the select value should be set when the active item changes by
36
- * moving (which usually happens when moving to an item using the keyboard).
39
+ * Whether the select
40
+ * [`value`](https://ariakit.org/reference/select-provider#value) should be
41
+ * set when the active item changes by moving (which usually happens when
42
+ * moving to an item using the keyboard).
43
+ *
44
+ * Live examples:
45
+ * - [Select Grid](https://ariakit.org/examples/select-grid)
46
+ * - [Select with custom
47
+ * items](https://ariakit.org/examples/select-item-custom)
37
48
  * @default false
38
49
  */
39
50
  setValueOnMove: boolean;
40
51
  /**
41
52
  * The select button element.
53
+ *
54
+ * Live examples:
55
+ * - [Form with Select](https://ariakit.org/examples/form-select)
42
56
  */
43
57
  selectElement: HTMLElement | null;
44
58
  /**
@@ -49,10 +63,6 @@ export interface SelectStoreState<T extends Value = Value> extends CompositeStor
49
63
  export interface SelectStoreFunctions<T extends Value = Value> extends Pick<SelectStoreOptions<T>, "combobox">, CompositeStoreFunctions<Item>, PopoverStoreFunctions {
50
64
  /**
51
65
  * Sets the `value` state.
52
- *
53
- * Live examples:
54
- * - [Multi-selectable
55
- * Combobox](https://ariakit.org/examples/combobox-multiple)
56
66
  * @example
57
67
  * store.setValue("Apple");
58
68
  * store.setValue(["Apple", "Banana"]);
@@ -73,21 +83,21 @@ export interface SelectStoreOptions<T extends Value = Value> extends StoreOption
73
83
  * A reference to a combobox store. This is used when combining the combobox
74
84
  * with a select (e.g., select with a search input). The stores will share the
75
85
  * same state.
76
- *
77
- * Live examples:
78
- * - [Multi-selectable
79
- * Combobox](https://ariakit.org/examples/combobox-multiple)
80
86
  */
81
87
  combobox?: ComboboxStore | null;
82
88
  /**
83
89
  * The default value. If not set, the first non-disabled item will be used.
84
90
  *
85
91
  * Live examples:
86
- * - [Multi-selectable
87
- * Combobox](https://ariakit.org/examples/combobox-multiple)
92
+ * - [Form with Select](https://ariakit.org/examples/form-select)
93
+ * - [Animated Select](https://ariakit.org/examples/select-animated)
94
+ * - [Select with Combobox](https://ariakit.org/examples/select-combobox)
95
+ * - [SelectGroup](https://ariakit.org/examples/select-group)
88
96
  */
89
97
  defaultValue?: SelectStoreState<T>["value"];
90
98
  }
91
- export type SelectStoreProps<T extends Value = Value> = SelectStoreOptions<T> & StoreProps<SelectStoreState<T>>;
92
- export type SelectStore<T extends Value = Value> = SelectStoreFunctions<T> & Store<SelectStoreState<T>>;
99
+ export interface SelectStoreProps<T extends Value = Value> extends SelectStoreOptions<T>, StoreProps<SelectStoreState<T>> {
100
+ }
101
+ export interface SelectStore<T extends Value = Value> extends SelectStoreFunctions<T>, Store<SelectStoreState<T>> {
102
+ }
93
103
  export {};
@@ -46,6 +46,9 @@ export type StoreOptions<S extends State, K extends keyof S> = Partial<Pick<S, K
46
46
  export type StoreProps<S extends State = State> = {
47
47
  /**
48
48
  * Another store object that will be kept in sync with the original store.
49
+ *
50
+ * Live examples:
51
+ * - [Navigation Menubar](https://ariakit.org/examples/menubar-navigation)
49
52
  */
50
53
  store?: Store<Partial<S>>;
51
54
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ariakit/core",
3
- "version": "0.3.6",
3
+ "version": "0.3.7",
4
4
  "description": "Ariakit core",
5
5
  "sideEffects": false,
6
6
  "license": "MIT",