@heroui/autocomplete 2.3.21-beta.3 → 2.3.21

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.
@@ -45,6 +45,7 @@ var import_shared_utils = require("@heroui/shared-utils");
45
45
  var import_utils = require("@react-aria/utils");
46
46
  var import_combobox2 = require("@react-aria/combobox");
47
47
  var import_form = require("@heroui/form");
48
+ var import_aria_utils = require("@heroui/aria-utils");
48
49
  function useAutocomplete(originalProps) {
49
50
  var _a, _b, _c, _d, _e;
50
51
  const globalContext = (0, import_system.useProviderContext)();
@@ -214,12 +215,30 @@ function useAutocomplete(originalProps) {
214
215
  }
215
216
  }, [inputRef.current]);
216
217
  (0, import_react.useEffect)(() => {
217
- let key = state.collection.getFirstKey();
218
- while (key && state.disabledKeys.has(key)) {
219
- key = state.collection.getKeyAfter(key);
218
+ let keyToFocus;
219
+ if (state.selectedKey !== null && state.collection.getItem(state.selectedKey) && !state.disabledKeys.has(state.selectedKey)) {
220
+ keyToFocus = state.selectedKey;
221
+ } else {
222
+ let firstAvailableKey = state.collection.getFirstKey();
223
+ while (firstAvailableKey && state.disabledKeys.has(firstAvailableKey)) {
224
+ firstAvailableKey = state.collection.getKeyAfter(firstAvailableKey);
225
+ }
226
+ keyToFocus = firstAvailableKey;
227
+ }
228
+ state.selectionManager.setFocusedKey(keyToFocus);
229
+ }, [state.collection, state.disabledKeys, state.selectedKey]);
230
+ (0, import_react.useEffect)(() => {
231
+ if (state.isOpen && popoverRef.current && listBoxRef.current) {
232
+ let selectedItem = listBoxRef.current.querySelector("[aria-selected=true] [data-label=true]");
233
+ let scrollShadow = scrollShadowRef.current;
234
+ if (selectedItem && scrollShadow && selectedItem.parentElement) {
235
+ let scrollShadowRect = scrollShadow == null ? void 0 : scrollShadow.getBoundingClientRect();
236
+ let scrollShadowHeight = scrollShadowRect.height;
237
+ scrollShadow.scrollTop = selectedItem.parentElement.offsetTop - scrollShadowHeight / 2 + selectedItem.parentElement.clientHeight / 2;
238
+ state.selectionManager.setFocusedKey(state.selectedKey);
239
+ }
220
240
  }
221
- state.selectionManager.setFocusedKey(key);
222
- }, [state.collection, state.disabledKeys]);
241
+ }, [state.isOpen, disableAnimation]);
223
242
  (0, import_react.useEffect)(() => {
224
243
  if (isOpen) {
225
244
  if (popoverRef.current && inputWrapperRef.current) {
@@ -334,6 +353,7 @@ function useAutocomplete(originalProps) {
334
353
  )
335
354
  })
336
355
  },
356
+ shouldCloseOnInteractOutside: (popoverProps2 == null ? void 0 : popoverProps2.shouldCloseOnInteractOutside) ? popoverProps2.shouldCloseOnInteractOutside : (element) => (0, import_aria_utils.ariaShouldCloseOnInteractOutside)(element, inputWrapperRef, state),
337
357
  // when the popover is open, the focus should be on input instead of dialog
338
358
  // therefore, we skip dialog focus here
339
359
  disableDialogFocus: true
@@ -1,8 +1,8 @@
1
1
  "use client";
2
2
  import {
3
3
  autocomplete_default
4
- } from "./chunk-TVVBPDQE.mjs";
5
- import "./chunk-7QAGQGGG.mjs";
4
+ } from "./chunk-R4R544ZH.mjs";
5
+ import "./chunk-ORFKRCF3.mjs";
6
6
  export {
7
7
  autocomplete_default as default
8
8
  };
@@ -12,6 +12,7 @@ import { clsx, dataAttr, objectToDeps } from "@heroui/shared-utils";
12
12
  import { chain, mergeProps } from "@react-aria/utils";
13
13
  import { useComboBox } from "@react-aria/combobox";
14
14
  import { FormContext, useSlottedContext } from "@heroui/form";
15
+ import { ariaShouldCloseOnInteractOutside } from "@heroui/aria-utils";
15
16
  function useAutocomplete(originalProps) {
16
17
  var _a, _b, _c, _d, _e;
17
18
  const globalContext = useProviderContext();
@@ -181,12 +182,30 @@ function useAutocomplete(originalProps) {
181
182
  }
182
183
  }, [inputRef.current]);
183
184
  useEffect(() => {
184
- let key = state.collection.getFirstKey();
185
- while (key && state.disabledKeys.has(key)) {
186
- key = state.collection.getKeyAfter(key);
185
+ let keyToFocus;
186
+ if (state.selectedKey !== null && state.collection.getItem(state.selectedKey) && !state.disabledKeys.has(state.selectedKey)) {
187
+ keyToFocus = state.selectedKey;
188
+ } else {
189
+ let firstAvailableKey = state.collection.getFirstKey();
190
+ while (firstAvailableKey && state.disabledKeys.has(firstAvailableKey)) {
191
+ firstAvailableKey = state.collection.getKeyAfter(firstAvailableKey);
192
+ }
193
+ keyToFocus = firstAvailableKey;
194
+ }
195
+ state.selectionManager.setFocusedKey(keyToFocus);
196
+ }, [state.collection, state.disabledKeys, state.selectedKey]);
197
+ useEffect(() => {
198
+ if (state.isOpen && popoverRef.current && listBoxRef.current) {
199
+ let selectedItem = listBoxRef.current.querySelector("[aria-selected=true] [data-label=true]");
200
+ let scrollShadow = scrollShadowRef.current;
201
+ if (selectedItem && scrollShadow && selectedItem.parentElement) {
202
+ let scrollShadowRect = scrollShadow == null ? void 0 : scrollShadow.getBoundingClientRect();
203
+ let scrollShadowHeight = scrollShadowRect.height;
204
+ scrollShadow.scrollTop = selectedItem.parentElement.offsetTop - scrollShadowHeight / 2 + selectedItem.parentElement.clientHeight / 2;
205
+ state.selectionManager.setFocusedKey(state.selectedKey);
206
+ }
187
207
  }
188
- state.selectionManager.setFocusedKey(key);
189
- }, [state.collection, state.disabledKeys]);
208
+ }, [state.isOpen, disableAnimation]);
190
209
  useEffect(() => {
191
210
  if (isOpen) {
192
211
  if (popoverRef.current && inputWrapperRef.current) {
@@ -301,6 +320,7 @@ function useAutocomplete(originalProps) {
301
320
  )
302
321
  })
303
322
  },
323
+ shouldCloseOnInteractOutside: (popoverProps2 == null ? void 0 : popoverProps2.shouldCloseOnInteractOutside) ? popoverProps2.shouldCloseOnInteractOutside : (element) => ariaShouldCloseOnInteractOutside(element, inputWrapperRef, state),
304
324
  // when the popover is open, the focus should be on input instead of dialog
305
325
  // therefore, we skip dialog focus here
306
326
  disableDialogFocus: true
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import {
3
3
  useAutocomplete
4
- } from "./chunk-7QAGQGGG.mjs";
4
+ } from "./chunk-ORFKRCF3.mjs";
5
5
 
6
6
  // src/autocomplete.tsx
7
7
  import { forwardRef } from "@heroui/system";
package/dist/index.js CHANGED
@@ -51,6 +51,7 @@ var import_shared_utils = require("@heroui/shared-utils");
51
51
  var import_utils = require("@react-aria/utils");
52
52
  var import_combobox2 = require("@react-aria/combobox");
53
53
  var import_form = require("@heroui/form");
54
+ var import_aria_utils = require("@heroui/aria-utils");
54
55
  function useAutocomplete(originalProps) {
55
56
  var _a, _b, _c, _d, _e;
56
57
  const globalContext = (0, import_system.useProviderContext)();
@@ -220,12 +221,30 @@ function useAutocomplete(originalProps) {
220
221
  }
221
222
  }, [inputRef.current]);
222
223
  (0, import_react.useEffect)(() => {
223
- let key = state.collection.getFirstKey();
224
- while (key && state.disabledKeys.has(key)) {
225
- key = state.collection.getKeyAfter(key);
224
+ let keyToFocus;
225
+ if (state.selectedKey !== null && state.collection.getItem(state.selectedKey) && !state.disabledKeys.has(state.selectedKey)) {
226
+ keyToFocus = state.selectedKey;
227
+ } else {
228
+ let firstAvailableKey = state.collection.getFirstKey();
229
+ while (firstAvailableKey && state.disabledKeys.has(firstAvailableKey)) {
230
+ firstAvailableKey = state.collection.getKeyAfter(firstAvailableKey);
231
+ }
232
+ keyToFocus = firstAvailableKey;
233
+ }
234
+ state.selectionManager.setFocusedKey(keyToFocus);
235
+ }, [state.collection, state.disabledKeys, state.selectedKey]);
236
+ (0, import_react.useEffect)(() => {
237
+ if (state.isOpen && popoverRef.current && listBoxRef.current) {
238
+ let selectedItem = listBoxRef.current.querySelector("[aria-selected=true] [data-label=true]");
239
+ let scrollShadow = scrollShadowRef.current;
240
+ if (selectedItem && scrollShadow && selectedItem.parentElement) {
241
+ let scrollShadowRect = scrollShadow == null ? void 0 : scrollShadow.getBoundingClientRect();
242
+ let scrollShadowHeight = scrollShadowRect.height;
243
+ scrollShadow.scrollTop = selectedItem.parentElement.offsetTop - scrollShadowHeight / 2 + selectedItem.parentElement.clientHeight / 2;
244
+ state.selectionManager.setFocusedKey(state.selectedKey);
245
+ }
226
246
  }
227
- state.selectionManager.setFocusedKey(key);
228
- }, [state.collection, state.disabledKeys]);
247
+ }, [state.isOpen, disableAnimation]);
229
248
  (0, import_react.useEffect)(() => {
230
249
  if (isOpen) {
231
250
  if (popoverRef.current && inputWrapperRef.current) {
@@ -340,6 +359,7 @@ function useAutocomplete(originalProps) {
340
359
  )
341
360
  })
342
361
  },
362
+ shouldCloseOnInteractOutside: (popoverProps2 == null ? void 0 : popoverProps2.shouldCloseOnInteractOutside) ? popoverProps2.shouldCloseOnInteractOutside : (element) => (0, import_aria_utils.ariaShouldCloseOnInteractOutside)(element, inputWrapperRef, state),
343
363
  // when the popover is open, the focus should be on input instead of dialog
344
364
  // therefore, we skip dialog focus here
345
365
  disableDialogFocus: true
package/dist/index.mjs CHANGED
@@ -1,10 +1,10 @@
1
1
  "use client";
2
2
  import {
3
3
  autocomplete_default
4
- } from "./chunk-TVVBPDQE.mjs";
4
+ } from "./chunk-R4R544ZH.mjs";
5
5
  import {
6
6
  useAutocomplete
7
- } from "./chunk-7QAGQGGG.mjs";
7
+ } from "./chunk-ORFKRCF3.mjs";
8
8
 
9
9
  // src/index.ts
10
10
  import { ListboxItem, ListboxSection } from "@heroui/listbox";
@@ -132,77 +132,77 @@ declare function useAutocomplete<T extends object>(originalProps: UseAutocomplet
132
132
  slots: {
133
133
  base: (slotProps?: ({
134
134
  isClearable?: boolean | undefined;
135
- disableSelectorIconRotation?: boolean | undefined;
136
135
  disableAnimation?: boolean | undefined;
136
+ disableSelectorIconRotation?: boolean | undefined;
137
137
  } & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
138
138
  listboxWrapper: (slotProps?: ({
139
139
  isClearable?: boolean | undefined;
140
- disableSelectorIconRotation?: boolean | undefined;
141
140
  disableAnimation?: boolean | undefined;
141
+ disableSelectorIconRotation?: boolean | undefined;
142
142
  } & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
143
143
  listbox: (slotProps?: ({
144
144
  isClearable?: boolean | undefined;
145
- disableSelectorIconRotation?: boolean | undefined;
146
145
  disableAnimation?: boolean | undefined;
146
+ disableSelectorIconRotation?: boolean | undefined;
147
147
  } & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
148
148
  popoverContent: (slotProps?: ({
149
149
  isClearable?: boolean | undefined;
150
- disableSelectorIconRotation?: boolean | undefined;
151
150
  disableAnimation?: boolean | undefined;
151
+ disableSelectorIconRotation?: boolean | undefined;
152
152
  } & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
153
153
  endContentWrapper: (slotProps?: ({
154
154
  isClearable?: boolean | undefined;
155
- disableSelectorIconRotation?: boolean | undefined;
156
155
  disableAnimation?: boolean | undefined;
156
+ disableSelectorIconRotation?: boolean | undefined;
157
157
  } & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
158
158
  clearButton: (slotProps?: ({
159
159
  isClearable?: boolean | undefined;
160
- disableSelectorIconRotation?: boolean | undefined;
161
160
  disableAnimation?: boolean | undefined;
161
+ disableSelectorIconRotation?: boolean | undefined;
162
162
  } & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
163
163
  selectorButton: (slotProps?: ({
164
164
  isClearable?: boolean | undefined;
165
- disableSelectorIconRotation?: boolean | undefined;
166
165
  disableAnimation?: boolean | undefined;
166
+ disableSelectorIconRotation?: boolean | undefined;
167
167
  } & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
168
168
  } & {
169
169
  base: (slotProps?: ({
170
170
  isClearable?: boolean | undefined;
171
- disableSelectorIconRotation?: boolean | undefined;
172
171
  disableAnimation?: boolean | undefined;
172
+ disableSelectorIconRotation?: boolean | undefined;
173
173
  } & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
174
174
  listboxWrapper: (slotProps?: ({
175
175
  isClearable?: boolean | undefined;
176
- disableSelectorIconRotation?: boolean | undefined;
177
176
  disableAnimation?: boolean | undefined;
177
+ disableSelectorIconRotation?: boolean | undefined;
178
178
  } & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
179
179
  listbox: (slotProps?: ({
180
180
  isClearable?: boolean | undefined;
181
- disableSelectorIconRotation?: boolean | undefined;
182
181
  disableAnimation?: boolean | undefined;
182
+ disableSelectorIconRotation?: boolean | undefined;
183
183
  } & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
184
184
  popoverContent: (slotProps?: ({
185
185
  isClearable?: boolean | undefined;
186
- disableSelectorIconRotation?: boolean | undefined;
187
186
  disableAnimation?: boolean | undefined;
187
+ disableSelectorIconRotation?: boolean | undefined;
188
188
  } & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
189
189
  endContentWrapper: (slotProps?: ({
190
190
  isClearable?: boolean | undefined;
191
- disableSelectorIconRotation?: boolean | undefined;
192
191
  disableAnimation?: boolean | undefined;
192
+ disableSelectorIconRotation?: boolean | undefined;
193
193
  } & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
194
194
  clearButton: (slotProps?: ({
195
195
  isClearable?: boolean | undefined;
196
- disableSelectorIconRotation?: boolean | undefined;
197
196
  disableAnimation?: boolean | undefined;
197
+ disableSelectorIconRotation?: boolean | undefined;
198
198
  } & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
199
199
  selectorButton: (slotProps?: ({
200
200
  isClearable?: boolean | undefined;
201
- disableSelectorIconRotation?: boolean | undefined;
202
201
  disableAnimation?: boolean | undefined;
202
+ disableSelectorIconRotation?: boolean | undefined;
203
203
  } & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
204
204
  } & {};
205
- classNames: SlotsToClasses<"base" | "listboxWrapper" | "listbox" | "popoverContent" | "endContentWrapper" | "selectorButton" | "clearButton"> | undefined;
205
+ classNames: SlotsToClasses<"base" | "clearButton" | "listbox" | "listboxWrapper" | "popoverContent" | "endContentWrapper" | "selectorButton"> | undefined;
206
206
  isLoading: boolean | undefined;
207
207
  clearIcon: ReactNode;
208
208
  isOpen: boolean;
@@ -132,77 +132,77 @@ declare function useAutocomplete<T extends object>(originalProps: UseAutocomplet
132
132
  slots: {
133
133
  base: (slotProps?: ({
134
134
  isClearable?: boolean | undefined;
135
- disableSelectorIconRotation?: boolean | undefined;
136
135
  disableAnimation?: boolean | undefined;
136
+ disableSelectorIconRotation?: boolean | undefined;
137
137
  } & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
138
138
  listboxWrapper: (slotProps?: ({
139
139
  isClearable?: boolean | undefined;
140
- disableSelectorIconRotation?: boolean | undefined;
141
140
  disableAnimation?: boolean | undefined;
141
+ disableSelectorIconRotation?: boolean | undefined;
142
142
  } & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
143
143
  listbox: (slotProps?: ({
144
144
  isClearable?: boolean | undefined;
145
- disableSelectorIconRotation?: boolean | undefined;
146
145
  disableAnimation?: boolean | undefined;
146
+ disableSelectorIconRotation?: boolean | undefined;
147
147
  } & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
148
148
  popoverContent: (slotProps?: ({
149
149
  isClearable?: boolean | undefined;
150
- disableSelectorIconRotation?: boolean | undefined;
151
150
  disableAnimation?: boolean | undefined;
151
+ disableSelectorIconRotation?: boolean | undefined;
152
152
  } & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
153
153
  endContentWrapper: (slotProps?: ({
154
154
  isClearable?: boolean | undefined;
155
- disableSelectorIconRotation?: boolean | undefined;
156
155
  disableAnimation?: boolean | undefined;
156
+ disableSelectorIconRotation?: boolean | undefined;
157
157
  } & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
158
158
  clearButton: (slotProps?: ({
159
159
  isClearable?: boolean | undefined;
160
- disableSelectorIconRotation?: boolean | undefined;
161
160
  disableAnimation?: boolean | undefined;
161
+ disableSelectorIconRotation?: boolean | undefined;
162
162
  } & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
163
163
  selectorButton: (slotProps?: ({
164
164
  isClearable?: boolean | undefined;
165
- disableSelectorIconRotation?: boolean | undefined;
166
165
  disableAnimation?: boolean | undefined;
166
+ disableSelectorIconRotation?: boolean | undefined;
167
167
  } & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
168
168
  } & {
169
169
  base: (slotProps?: ({
170
170
  isClearable?: boolean | undefined;
171
- disableSelectorIconRotation?: boolean | undefined;
172
171
  disableAnimation?: boolean | undefined;
172
+ disableSelectorIconRotation?: boolean | undefined;
173
173
  } & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
174
174
  listboxWrapper: (slotProps?: ({
175
175
  isClearable?: boolean | undefined;
176
- disableSelectorIconRotation?: boolean | undefined;
177
176
  disableAnimation?: boolean | undefined;
177
+ disableSelectorIconRotation?: boolean | undefined;
178
178
  } & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
179
179
  listbox: (slotProps?: ({
180
180
  isClearable?: boolean | undefined;
181
- disableSelectorIconRotation?: boolean | undefined;
182
181
  disableAnimation?: boolean | undefined;
182
+ disableSelectorIconRotation?: boolean | undefined;
183
183
  } & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
184
184
  popoverContent: (slotProps?: ({
185
185
  isClearable?: boolean | undefined;
186
- disableSelectorIconRotation?: boolean | undefined;
187
186
  disableAnimation?: boolean | undefined;
187
+ disableSelectorIconRotation?: boolean | undefined;
188
188
  } & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
189
189
  endContentWrapper: (slotProps?: ({
190
190
  isClearable?: boolean | undefined;
191
- disableSelectorIconRotation?: boolean | undefined;
192
191
  disableAnimation?: boolean | undefined;
192
+ disableSelectorIconRotation?: boolean | undefined;
193
193
  } & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
194
194
  clearButton: (slotProps?: ({
195
195
  isClearable?: boolean | undefined;
196
- disableSelectorIconRotation?: boolean | undefined;
197
196
  disableAnimation?: boolean | undefined;
197
+ disableSelectorIconRotation?: boolean | undefined;
198
198
  } & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
199
199
  selectorButton: (slotProps?: ({
200
200
  isClearable?: boolean | undefined;
201
- disableSelectorIconRotation?: boolean | undefined;
202
201
  disableAnimation?: boolean | undefined;
202
+ disableSelectorIconRotation?: boolean | undefined;
203
203
  } & tailwind_variants.ClassProp<tailwind_variants.ClassValue>) | undefined) => string;
204
204
  } & {};
205
- classNames: SlotsToClasses<"base" | "listboxWrapper" | "listbox" | "popoverContent" | "endContentWrapper" | "selectorButton" | "clearButton"> | undefined;
205
+ classNames: SlotsToClasses<"base" | "clearButton" | "listbox" | "listboxWrapper" | "popoverContent" | "endContentWrapper" | "selectorButton"> | undefined;
206
206
  isLoading: boolean | undefined;
207
207
  clearIcon: ReactNode;
208
208
  isOpen: boolean;
@@ -35,6 +35,7 @@ var import_shared_utils = require("@heroui/shared-utils");
35
35
  var import_utils = require("@react-aria/utils");
36
36
  var import_combobox2 = require("@react-aria/combobox");
37
37
  var import_form = require("@heroui/form");
38
+ var import_aria_utils = require("@heroui/aria-utils");
38
39
  function useAutocomplete(originalProps) {
39
40
  var _a, _b, _c, _d, _e;
40
41
  const globalContext = (0, import_system.useProviderContext)();
@@ -204,12 +205,30 @@ function useAutocomplete(originalProps) {
204
205
  }
205
206
  }, [inputRef.current]);
206
207
  (0, import_react.useEffect)(() => {
207
- let key = state.collection.getFirstKey();
208
- while (key && state.disabledKeys.has(key)) {
209
- key = state.collection.getKeyAfter(key);
208
+ let keyToFocus;
209
+ if (state.selectedKey !== null && state.collection.getItem(state.selectedKey) && !state.disabledKeys.has(state.selectedKey)) {
210
+ keyToFocus = state.selectedKey;
211
+ } else {
212
+ let firstAvailableKey = state.collection.getFirstKey();
213
+ while (firstAvailableKey && state.disabledKeys.has(firstAvailableKey)) {
214
+ firstAvailableKey = state.collection.getKeyAfter(firstAvailableKey);
215
+ }
216
+ keyToFocus = firstAvailableKey;
217
+ }
218
+ state.selectionManager.setFocusedKey(keyToFocus);
219
+ }, [state.collection, state.disabledKeys, state.selectedKey]);
220
+ (0, import_react.useEffect)(() => {
221
+ if (state.isOpen && popoverRef.current && listBoxRef.current) {
222
+ let selectedItem = listBoxRef.current.querySelector("[aria-selected=true] [data-label=true]");
223
+ let scrollShadow = scrollShadowRef.current;
224
+ if (selectedItem && scrollShadow && selectedItem.parentElement) {
225
+ let scrollShadowRect = scrollShadow == null ? void 0 : scrollShadow.getBoundingClientRect();
226
+ let scrollShadowHeight = scrollShadowRect.height;
227
+ scrollShadow.scrollTop = selectedItem.parentElement.offsetTop - scrollShadowHeight / 2 + selectedItem.parentElement.clientHeight / 2;
228
+ state.selectionManager.setFocusedKey(state.selectedKey);
229
+ }
210
230
  }
211
- state.selectionManager.setFocusedKey(key);
212
- }, [state.collection, state.disabledKeys]);
231
+ }, [state.isOpen, disableAnimation]);
213
232
  (0, import_react.useEffect)(() => {
214
233
  if (isOpen) {
215
234
  if (popoverRef.current && inputWrapperRef.current) {
@@ -324,6 +343,7 @@ function useAutocomplete(originalProps) {
324
343
  )
325
344
  })
326
345
  },
346
+ shouldCloseOnInteractOutside: (popoverProps2 == null ? void 0 : popoverProps2.shouldCloseOnInteractOutside) ? popoverProps2.shouldCloseOnInteractOutside : (element) => (0, import_aria_utils.ariaShouldCloseOnInteractOutside)(element, inputWrapperRef, state),
327
347
  // when the popover is open, the focus should be on input instead of dialog
328
348
  // therefore, we skip dialog focus here
329
349
  disableDialogFocus: true
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import {
3
3
  useAutocomplete
4
- } from "./chunk-7QAGQGGG.mjs";
4
+ } from "./chunk-ORFKRCF3.mjs";
5
5
  export {
6
6
  useAutocomplete
7
7
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heroui/autocomplete",
3
- "version": "2.3.21-beta.3",
3
+ "version": "2.3.21",
4
4
  "description": "An autocomplete combines a text input with a listbox, allowing users to filter a list of options to items matching a query.",
5
5
  "keywords": [
6
6
  "autocomplete"
@@ -25,8 +25,8 @@
25
25
  "url": "https://github.com/heroui-inc/heroui/issues"
26
26
  },
27
27
  "peerDependencies": {
28
- "@heroui/system": ">=2.4.16-beta.0",
29
- "@heroui/theme": ">=2.4.16-beta.0",
28
+ "@heroui/system": ">=2.4.7",
29
+ "@heroui/theme": ">=2.4.6",
30
30
  "framer-motion": ">=11.5.6 || >=12.0.0-alpha.1",
31
31
  "react": ">=18 || >=19.0.0-rc.0",
32
32
  "react-dom": ">=18 || >=19.0.0-rc.0"
@@ -41,19 +41,19 @@
41
41
  "@react-stately/combobox": "3.10.5",
42
42
  "@react-types/combobox": "3.13.5",
43
43
  "@react-types/shared": "3.29.1",
44
- "@heroui/form": "2.1.19-beta.3",
45
- "@heroui/aria-utils": "2.2.17-beta.3",
46
- "@heroui/button": "2.2.20-beta.3",
47
- "@heroui/input": "2.4.20-beta.3",
48
- "@heroui/listbox": "2.3.19-beta.3",
49
- "@heroui/popover": "2.3.20-beta.3",
50
- "@heroui/react-utils": "2.1.11-beta.0",
51
- "@heroui/scroll-shadow": "2.3.14-beta.2",
52
- "@heroui/shared-icons": "2.1.8-beta.0",
53
- "@heroui/shared-utils": "2.1.10-beta.0",
54
- "@heroui/spinner": "2.2.17-beta.3",
55
- "@heroui/use-aria-button": "2.2.14-beta.1",
56
- "@heroui/use-safe-layout-effect": "2.1.8-beta.0"
44
+ "@heroui/aria-utils": "2.2.17",
45
+ "@heroui/button": "2.2.20",
46
+ "@heroui/input": "2.4.20",
47
+ "@heroui/listbox": "2.3.19",
48
+ "@heroui/popover": "2.3.20",
49
+ "@heroui/form": "2.1.19",
50
+ "@heroui/react-utils": "2.1.10",
51
+ "@heroui/scroll-shadow": "2.3.13",
52
+ "@heroui/shared-icons": "2.1.8",
53
+ "@heroui/shared-utils": "2.1.9",
54
+ "@heroui/spinner": "2.2.17",
55
+ "@heroui/use-aria-button": "2.2.14",
56
+ "@heroui/use-safe-layout-effect": "2.1.7"
57
57
  },
58
58
  "clean-package": "../../../clean-package.config.json",
59
59
  "module": "dist/index.mjs",