@heroui/autocomplete 2.3.21-beta.2 → 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.
@@ -215,12 +215,30 @@ function useAutocomplete(originalProps) {
215
215
  }
216
216
  }, [inputRef.current]);
217
217
  (0, import_react.useEffect)(() => {
218
- let key = state.collection.getFirstKey();
219
- while (key && state.disabledKeys.has(key)) {
220
- 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
+ }
221
240
  }
222
- state.selectionManager.setFocusedKey(key);
223
- }, [state.collection, state.disabledKeys]);
241
+ }, [state.isOpen, disableAnimation]);
224
242
  (0, import_react.useEffect)(() => {
225
243
  if (isOpen) {
226
244
  if (popoverRef.current && inputWrapperRef.current) {
@@ -1,8 +1,8 @@
1
1
  "use client";
2
2
  import {
3
3
  autocomplete_default
4
- } from "./chunk-DNIGSRME.mjs";
5
- import "./chunk-OHYOYGT2.mjs";
4
+ } from "./chunk-R4R544ZH.mjs";
5
+ import "./chunk-ORFKRCF3.mjs";
6
6
  export {
7
7
  autocomplete_default as default
8
8
  };
@@ -182,12 +182,30 @@ function useAutocomplete(originalProps) {
182
182
  }
183
183
  }, [inputRef.current]);
184
184
  useEffect(() => {
185
- let key = state.collection.getFirstKey();
186
- while (key && state.disabledKeys.has(key)) {
187
- 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
+ }
188
207
  }
189
- state.selectionManager.setFocusedKey(key);
190
- }, [state.collection, state.disabledKeys]);
208
+ }, [state.isOpen, disableAnimation]);
191
209
  useEffect(() => {
192
210
  if (isOpen) {
193
211
  if (popoverRef.current && inputWrapperRef.current) {
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import {
3
3
  useAutocomplete
4
- } from "./chunk-OHYOYGT2.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
@@ -221,12 +221,30 @@ function useAutocomplete(originalProps) {
221
221
  }
222
222
  }, [inputRef.current]);
223
223
  (0, import_react.useEffect)(() => {
224
- let key = state.collection.getFirstKey();
225
- while (key && state.disabledKeys.has(key)) {
226
- 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
+ }
227
246
  }
228
- state.selectionManager.setFocusedKey(key);
229
- }, [state.collection, state.disabledKeys]);
247
+ }, [state.isOpen, disableAnimation]);
230
248
  (0, import_react.useEffect)(() => {
231
249
  if (isOpen) {
232
250
  if (popoverRef.current && inputWrapperRef.current) {
package/dist/index.mjs CHANGED
@@ -1,10 +1,10 @@
1
1
  "use client";
2
2
  import {
3
3
  autocomplete_default
4
- } from "./chunk-DNIGSRME.mjs";
4
+ } from "./chunk-R4R544ZH.mjs";
5
5
  import {
6
6
  useAutocomplete
7
- } from "./chunk-OHYOYGT2.mjs";
7
+ } from "./chunk-ORFKRCF3.mjs";
8
8
 
9
9
  // src/index.ts
10
10
  import { ListboxItem, ListboxSection } from "@heroui/listbox";
@@ -205,12 +205,30 @@ function useAutocomplete(originalProps) {
205
205
  }
206
206
  }, [inputRef.current]);
207
207
  (0, import_react.useEffect)(() => {
208
- let key = state.collection.getFirstKey();
209
- while (key && state.disabledKeys.has(key)) {
210
- 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
+ }
211
230
  }
212
- state.selectionManager.setFocusedKey(key);
213
- }, [state.collection, state.disabledKeys]);
231
+ }, [state.isOpen, disableAnimation]);
214
232
  (0, import_react.useEffect)(() => {
215
233
  if (isOpen) {
216
234
  if (popoverRef.current && inputWrapperRef.current) {
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import {
3
3
  useAutocomplete
4
- } from "./chunk-OHYOYGT2.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.2",
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,35 +25,35 @@
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"
33
33
  },
34
34
  "dependencies": {
35
- "@react-aria/combobox": "3.12.2",
36
- "@react-aria/focus": "3.20.2",
37
- "@react-aria/i18n": "3.12.8",
38
- "@react-aria/interactions": "3.25.0",
39
- "@react-aria/utils": "3.28.2",
40
- "@react-aria/visually-hidden": "3.8.22",
41
- "@react-stately/combobox": "3.10.4",
42
- "@react-types/combobox": "3.13.4",
43
- "@react-types/shared": "3.29.0",
44
- "@heroui/form": "2.1.19-beta.2",
45
- "@heroui/aria-utils": "2.2.17-beta.2",
46
- "@heroui/button": "2.2.20-beta.2",
47
- "@heroui/input": "2.4.20-beta.2",
48
- "@heroui/listbox": "2.3.19-beta.2",
49
- "@heroui/popover": "2.3.20-beta.2",
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.2",
55
- "@heroui/use-aria-button": "2.2.14-beta.0",
56
- "@heroui/use-safe-layout-effect": "2.1.8-beta.0"
35
+ "@react-aria/combobox": "3.12.3",
36
+ "@react-aria/focus": "3.20.3",
37
+ "@react-aria/i18n": "3.12.9",
38
+ "@react-aria/interactions": "3.25.1",
39
+ "@react-aria/utils": "3.29.0",
40
+ "@react-aria/visually-hidden": "3.8.23",
41
+ "@react-stately/combobox": "3.10.5",
42
+ "@react-types/combobox": "3.13.5",
43
+ "@react-types/shared": "3.29.1",
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",