@availity/mui-autocomplete 2.2.5 → 2.2.6

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
@@ -2,6 +2,13 @@
2
2
 
3
3
  This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4
4
 
5
+ ## [2.2.6](https://github.com/Availity/element/compare/@availity/mui-autocomplete@2.2.5...@availity/mui-autocomplete@2.2.6) (2026-03-16)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * **mui-autocomplete:** expand scroll check area for asyncautocomplete ([4cc7229](https://github.com/Availity/element/commit/4cc7229871f77afce0a21e5cd8741f3c92c2b721))
11
+
5
12
  ## [2.2.5](https://github.com/Availity/element/compare/@availity/mui-autocomplete@2.2.4...@availity/mui-autocomplete@2.2.5) (2026-03-03)
6
13
 
7
14
  ### Dependency Updates
package/dist/index.js CHANGED
@@ -227,7 +227,7 @@ var AsyncAutocomplete = (_a) => {
227
227
  const handleAddingOptions = (event) => __async(null, null, function* () {
228
228
  const listboxNode = event.currentTarget;
229
229
  const difference = listboxNode.scrollHeight - (listboxNode.scrollTop + listboxNode.clientHeight);
230
- if (difference <= 5 && !isLoading && !isFetching && hasNextPage) {
230
+ if (difference <= 10 && !isLoading && !isFetching && hasNextPage) {
231
231
  fetchNextPage();
232
232
  }
233
233
  });
package/dist/index.mjs CHANGED
@@ -185,7 +185,7 @@ var AsyncAutocomplete = (_a) => {
185
185
  const handleAddingOptions = (event) => __async(null, null, function* () {
186
186
  const listboxNode = event.currentTarget;
187
187
  const difference = listboxNode.scrollHeight - (listboxNode.scrollTop + listboxNode.clientHeight);
188
- if (difference <= 5 && !isLoading && !isFetching && hasNextPage) {
188
+ if (difference <= 10 && !isLoading && !isFetching && hasNextPage) {
189
189
  fetchNextPage();
190
190
  }
191
191
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@availity/mui-autocomplete",
3
- "version": "2.2.5",
3
+ "version": "2.2.6",
4
4
  "description": "Availity MUI Autocomplete Component - part of the @availity/element design system",
5
5
  "keywords": [
6
6
  "react",
@@ -5,6 +5,7 @@ import { server } from '@availity/mock/src/lib/server';
5
5
  import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
6
6
 
7
7
  import { AsyncAutocomplete } from './AsyncAutocomplete';
8
+ import { mock } from 'node:test';
8
9
 
9
10
  const api = new AvApi({ name: 'example' } as ApiConfig);
10
11
 
@@ -182,63 +183,85 @@ describe('AsyncAutocomplete', () => {
182
183
  });
183
184
  });
184
185
 
185
- // test('should call loadOptions when scroll to the bottom', async () => {
186
- // const client = new QueryClient();
187
-
188
- // render(
189
- // <QueryClientProvider client={client}>
190
- // <AsyncAutocomplete queryKey="test2" loadOptions={loadOptions} limit={10} FieldProps={{ label: 'Test' }} ListboxProps={{style: {maxHeight: '100px'}}} />
191
- // </QueryClientProvider>
192
- // );
193
-
194
- // const input = screen.getByRole('combobox');
195
- // fireEvent.click(input);
196
- // fireEvent.keyDown(input, { key: 'ArrowDown' });
197
-
198
- // await waitFor(() => {
199
- // expect(screen.getByText('Option 0')).toBeDefined();
200
- // expect(() => screen.getByText('Option 10')).toThrow();
201
- // });
202
-
203
- // await act(async () => {
204
- // const options = await screen.findByRole('listbox');
205
- // fireEvent.scroll(options, { target: { scrollTop: options.scrollHeight } });
206
- // });
207
-
208
- // await waitFor(() => {
209
- // expect(screen.getByText('Option 10')).toBeDefined();
210
- // expect(() => screen.getByText('Option 20')).toThrow();
211
- // });
212
- // });
213
-
214
- // test('should call loadOptions when mouse enters the listbox if not enough options for scroll', async () => {
215
- // const client = new QueryClient();
216
-
217
- // render(
218
- // <QueryClientProvider client={client}>
219
- // <AsyncAutocomplete queryKey="test2" loadOptions={loadOptions} limit={5} FieldProps={{ label: 'Test' }} ListboxProps={{style: {maxHeight: '150px'}}} />
220
- // </QueryClientProvider>
221
- // );
222
-
223
- // const input = screen.getByRole('combobox');
224
- // fireEvent.click(input);
225
- // fireEvent.keyDown(input, { key: 'ArrowDown' });
226
-
227
- // await waitFor(() => {
228
- // expect(screen.getByText('Option 0')).toBeDefined();
229
- // expect(() => screen.getByText('Option 5')).toThrow();
230
- // });
231
-
232
- // await act(async () => {
233
- // const options = await screen.findByRole('listbox');
234
- // fireEvent.mouseEnter(options);
235
- // });
236
-
237
- // await waitFor(() => {
238
- // expect(screen.getByText('Option 5')).toBeDefined();
239
- // expect(() => screen.getByText('Option 10')).toThrow();
240
- // });
241
- // });
186
+ test('should call loadOptions when scroll to the bottom', async () => {
187
+ const mockLoadOptions = jest.fn(loadOptions);
188
+ const client = new QueryClient();
189
+
190
+ render(
191
+ <QueryClientProvider client={client}>
192
+ <AsyncAutocomplete queryKey="test-loadoptions-scroll" loadOptions={mockLoadOptions} limit={10} FieldProps={{ label: 'Test' }} />
193
+ </QueryClientProvider>
194
+ );
195
+
196
+ const input = screen.getByRole('combobox');
197
+ fireEvent.click(input);
198
+ fireEvent.keyDown(input, { key: 'ArrowUp' });
199
+
200
+ const listbox = await screen.findByRole('listbox');
201
+ Object.defineProperty(listbox, 'scrollHeight', { value: 500, writable: true });
202
+ Object.defineProperty(listbox, 'clientHeight', { value: 100, writable: true });
203
+ Object.defineProperty(listbox, 'scrollTop', { value: 0, writable: true });
204
+
205
+ // wait for no-scroll loading fallback to finish before testing scroll behavior
206
+ await waitFor(() => expect(() => screen.getByAltText('Loading')).toThrow());
207
+ const initialCallCount = mockLoadOptions.mock.calls.length;
208
+
209
+ fireEvent.scroll(listbox, { target: { scrollTop: 200 } });
210
+
211
+ // should not loadOptions since not scrolled to bottom
212
+ await waitFor(() => {
213
+ expect(mockLoadOptions).toHaveBeenCalledTimes(initialCallCount);
214
+ });
215
+
216
+ fireEvent.scroll(listbox, { target: { scrollTop: 400 } });
217
+
218
+ await waitFor(() => {
219
+ expect(mockLoadOptions).toHaveBeenCalledTimes(initialCallCount + 1);
220
+ });
221
+ });
222
+
223
+ test('should call loadOptions if more options available and not enough options for scroll', async () => {
224
+ const mockLoadOptions = jest.fn(loadOptions);
225
+ const client = new QueryClient();
226
+
227
+ render(
228
+ <QueryClientProvider client={client}>
229
+ <AsyncAutocomplete
230
+ queryKey="test-loadOptions-noscroll"
231
+ loadOptions={mockLoadOptions}
232
+ limit={5}
233
+ FieldProps={{ label: 'Test' }}
234
+ />
235
+ </QueryClientProvider>
236
+ );
237
+
238
+ const input = screen.getByRole('combobox');
239
+ fireEvent.click(input);
240
+ fireEvent.keyDown(input, { key: 'ArrowDown' });
241
+
242
+ await waitFor(() => {
243
+ expect(mockLoadOptions).toHaveBeenCalled();
244
+ });
245
+
246
+ // should load more options until enough options for scroll or no more options to load
247
+ const listbox = await screen.findByRole('listbox');
248
+ Object.defineProperty(listbox, 'scrollHeight', { value: 500, writable: true });
249
+ Object.defineProperty(listbox, 'clientHeight', { value: 100, writable: true });
250
+ Object.defineProperty(listbox, 'scrollTop', { value: 0, writable: true });
251
+
252
+ await waitFor(() => expect(() => screen.getByAltText('Loading')).toThrow());
253
+
254
+ // count number of calls before satisfying scrollable condition
255
+ const maxCallCount = mockLoadOptions.mock.calls.length;
256
+
257
+ fireEvent.pointerEnter(listbox);
258
+
259
+ // should not fallback to load more options as scrollable condition is satisfied
260
+ await waitFor(() => {
261
+ expect(mockLoadOptions).toHaveBeenCalledTimes(maxCallCount);
262
+ });
263
+ });
264
+
242
265
 
243
266
  test('should search with input value', async () => {
244
267
  const mockLoadOptions = jest.fn(async () => ({ options: [{ label: 'Option 1' }], hasMore: false, offset: 50 }));
@@ -112,7 +112,7 @@ export const AsyncAutocomplete = <
112
112
  const difference = listboxNode.scrollHeight - (listboxNode.scrollTop + listboxNode.clientHeight);
113
113
 
114
114
  // Only fetch if we are near the bottom, not already fetching, and there are more results
115
- if (difference <= 5 && !isLoading && !isFetching && hasNextPage) {
115
+ if (difference <= 10 && !isLoading && !isFetching && hasNextPage) {
116
116
  fetchNextPage();
117
117
  }
118
118
  }
@@ -142,7 +142,7 @@ export const AsyncAutocomplete = <
142
142
  ...ListboxProps,
143
143
  ref: setListboxRef,
144
144
  onScroll: handleAddingOptions,
145
- onPointerEnter: handleAddingOptions,
145
+ onPointerEnter: handleAddingOptions
146
146
  }}
147
147
  />
148
148
  );