@availity/mui-autocomplete 1.0.0-alpha.0 → 1.0.1

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,29 @@
2
2
 
3
3
  This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4
4
 
5
+ ## [1.0.1](https://github.com/Availity/element/compare/@availity/mui-autocomplete@1.0.0...@availity/mui-autocomplete@1.0.1) (2025-02-26)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * **mui-autocomplete:** refetch on clear ([fdea737](https://github.com/Availity/element/commit/fdea737f76b330a21e36ffd36996da9e83f2d629))
11
+
12
+ ## [1.0.0](https://github.com/Availity/element/compare/@availity/mui-autocomplete@1.0.0-alpha.0...@availity/mui-autocomplete@1.0.0) (2025-02-25)
13
+
14
+ ### Dependency Updates
15
+
16
+ * `mui-form-utils` updated to version `0.10.1`
17
+ * `mui-textfield` updated to version `0.10.1`
18
+ * `@availity/mock` updated to version `0.10.1`
19
+
20
+ ### ⚠ BREAKING CHANGES
21
+
22
+ * upgrade to @mui/material v6
23
+
24
+ ### Miscellaneous Chores
25
+
26
+ * element v1 release ([a6e3567](https://github.com/Availity/element/commit/a6e35671185b9f13d25c7a39c4488ecb8774633e))
27
+
5
28
  ## [1.0.0-alpha.0](https://github.com/Availity/element/compare/@availity/mui-autocomplete@0.10.1...@availity/mui-autocomplete@1.0.0-alpha.0) (2025-02-24)
6
29
 
7
30
 
package/dist/index.d.mts CHANGED
@@ -31,12 +31,12 @@ interface AsyncAutocompleteProps<Option, Multiple extends boolean | undefined, D
31
31
  hasMore: boolean;
32
32
  offset: number;
33
33
  }>;
34
- /** Object of parameters used for the cacheKey. Options are re-reftched when a value in the object changes */
34
+ /** Object of parameters used for the cacheKey. Options are re-refetched when a value in the object changes */
35
35
  watchParams?: Record<string, unknown>;
36
36
  /** Time to wait before searching with the input value typed into the component */
37
37
  debounceTimeout?: number;
38
38
  }
39
- declare const AsyncAutocomplete: <Option, Multiple extends boolean | undefined = false, DisableClearable extends boolean | undefined = false, FreeSolo extends boolean | undefined = false, ChipComponent extends React.ElementType = "div">({ loadOptions, limit, queryKey, ListboxProps, queryOptions, watchParams, debounceTimeout, FieldProps, ...rest }: AsyncAutocompleteProps<Option, Multiple, DisableClearable, FreeSolo, ChipComponent>) => react_jsx_runtime.JSX.Element;
39
+ declare const AsyncAutocomplete: <Option, Multiple extends boolean | undefined = false, DisableClearable extends boolean | undefined = false, FreeSolo extends boolean | undefined = false, ChipComponent extends React.ElementType = "div">({ loadOptions, limit, queryKey, ListboxProps, queryOptions, watchParams, debounceTimeout, FieldProps, onInputChange, ...rest }: AsyncAutocompleteProps<Option, Multiple, DisableClearable, FreeSolo, ChipComponent>) => react_jsx_runtime.JSX.Element;
40
40
 
41
41
  type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
42
42
 
package/dist/index.d.ts CHANGED
@@ -31,12 +31,12 @@ interface AsyncAutocompleteProps<Option, Multiple extends boolean | undefined, D
31
31
  hasMore: boolean;
32
32
  offset: number;
33
33
  }>;
34
- /** Object of parameters used for the cacheKey. Options are re-reftched when a value in the object changes */
34
+ /** Object of parameters used for the cacheKey. Options are re-refetched when a value in the object changes */
35
35
  watchParams?: Record<string, unknown>;
36
36
  /** Time to wait before searching with the input value typed into the component */
37
37
  debounceTimeout?: number;
38
38
  }
39
- declare const AsyncAutocomplete: <Option, Multiple extends boolean | undefined = false, DisableClearable extends boolean | undefined = false, FreeSolo extends boolean | undefined = false, ChipComponent extends React.ElementType = "div">({ loadOptions, limit, queryKey, ListboxProps, queryOptions, watchParams, debounceTimeout, FieldProps, ...rest }: AsyncAutocompleteProps<Option, Multiple, DisableClearable, FreeSolo, ChipComponent>) => react_jsx_runtime.JSX.Element;
39
+ declare const AsyncAutocomplete: <Option, Multiple extends boolean | undefined = false, DisableClearable extends boolean | undefined = false, FreeSolo extends boolean | undefined = false, ChipComponent extends React.ElementType = "div">({ loadOptions, limit, queryKey, ListboxProps, queryOptions, watchParams, debounceTimeout, FieldProps, onInputChange, ...rest }: AsyncAutocompleteProps<Option, Multiple, DisableClearable, FreeSolo, ChipComponent>) => react_jsx_runtime.JSX.Element;
40
40
 
41
41
  type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
42
42
 
package/dist/index.js CHANGED
@@ -167,7 +167,8 @@ var AsyncAutocomplete = (_a) => {
167
167
  queryOptions,
168
168
  watchParams,
169
169
  debounceTimeout = 350,
170
- FieldProps
170
+ FieldProps,
171
+ onInputChange
171
172
  } = _b, rest = __objRest(_b, [
172
173
  "loadOptions",
173
174
  "limit",
@@ -176,10 +177,11 @@ var AsyncAutocomplete = (_a) => {
176
177
  "queryOptions",
177
178
  "watchParams",
178
179
  "debounceTimeout",
179
- "FieldProps"
180
+ "FieldProps",
181
+ "onInputChange"
180
182
  ]);
181
183
  const [inputValue, setInputValue] = (0, import_react3.useState)("");
182
- const handleInputChange = (event) => {
184
+ const handleInputPropsOnChange = (event) => {
183
185
  var _a2;
184
186
  setInputValue(event.target.value);
185
187
  if ((_a2 = FieldProps == null ? void 0 : FieldProps.InputProps) == null ? void 0 : _a2.onChange) FieldProps.InputProps.onChange(event);
@@ -194,12 +196,19 @@ var AsyncAutocomplete = (_a) => {
194
196
  getNextPageParam: (lastPage) => lastPage.hasMore ? lastPage.offset + limit : false
195
197
  }, queryOptions));
196
198
  const options = (data == null ? void 0 : data.pages) ? data.pages.map((page) => page.options).flat() : [];
199
+ const handleOnInputChange = (event, value, reason) => {
200
+ if (reason === "clear") {
201
+ setInputValue(event.target.value);
202
+ }
203
+ if (onInputChange) onInputChange(event, value, reason);
204
+ };
197
205
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
198
206
  Autocomplete,
199
207
  __spreadProps(__spreadValues({}, rest), {
208
+ onInputChange: handleOnInputChange,
200
209
  FieldProps: __spreadProps(__spreadValues({}, FieldProps), {
201
210
  InputProps: __spreadProps(__spreadValues({}, FieldProps == null ? void 0 : FieldProps.InputProps), {
202
- onChange: handleInputChange
211
+ onChange: handleInputPropsOnChange
203
212
  })
204
213
  }),
205
214
  loading: isFetching,
package/dist/index.mjs CHANGED
@@ -131,7 +131,8 @@ var AsyncAutocomplete = (_a) => {
131
131
  queryOptions,
132
132
  watchParams,
133
133
  debounceTimeout = 350,
134
- FieldProps
134
+ FieldProps,
135
+ onInputChange
135
136
  } = _b, rest = __objRest(_b, [
136
137
  "loadOptions",
137
138
  "limit",
@@ -140,10 +141,11 @@ var AsyncAutocomplete = (_a) => {
140
141
  "queryOptions",
141
142
  "watchParams",
142
143
  "debounceTimeout",
143
- "FieldProps"
144
+ "FieldProps",
145
+ "onInputChange"
144
146
  ]);
145
147
  const [inputValue, setInputValue] = useState2("");
146
- const handleInputChange = (event) => {
148
+ const handleInputPropsOnChange = (event) => {
147
149
  var _a2;
148
150
  setInputValue(event.target.value);
149
151
  if ((_a2 = FieldProps == null ? void 0 : FieldProps.InputProps) == null ? void 0 : _a2.onChange) FieldProps.InputProps.onChange(event);
@@ -158,12 +160,19 @@ var AsyncAutocomplete = (_a) => {
158
160
  getNextPageParam: (lastPage) => lastPage.hasMore ? lastPage.offset + limit : false
159
161
  }, queryOptions));
160
162
  const options = (data == null ? void 0 : data.pages) ? data.pages.map((page) => page.options).flat() : [];
163
+ const handleOnInputChange = (event, value, reason) => {
164
+ if (reason === "clear") {
165
+ setInputValue(event.target.value);
166
+ }
167
+ if (onInputChange) onInputChange(event, value, reason);
168
+ };
161
169
  return /* @__PURE__ */ jsx2(
162
170
  Autocomplete,
163
171
  __spreadProps(__spreadValues({}, rest), {
172
+ onInputChange: handleOnInputChange,
164
173
  FieldProps: __spreadProps(__spreadValues({}, FieldProps), {
165
174
  InputProps: __spreadProps(__spreadValues({}, FieldProps == null ? void 0 : FieldProps.InputProps), {
166
- onChange: handleInputChange
175
+ onChange: handleInputPropsOnChange
167
176
  })
168
177
  }),
169
178
  loading: isFetching,
package/introduction.mdx CHANGED
@@ -1,7 +1,10 @@
1
1
  import { Markdown } from '@storybook/blocks';
2
2
  import { Meta } from '@storybook/addon-docs';
3
3
  import ReadMe from './README.md?raw';
4
+ import CHANGELOG from './CHANGELOG.md?raw';
4
5
 
5
6
  <Meta title="Form Components/Autocomplete/Introduction" />
6
7
 
7
8
  <Markdown>{ReadMe}</Markdown>
9
+
10
+ <Markdown>{CHANGELOG}</Markdown>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@availity/mui-autocomplete",
3
- "version": "1.0.0-alpha.0",
3
+ "version": "1.0.1",
4
4
  "description": "Availity MUI Autocomplete Component - part of the @availity/element design system",
5
5
  "keywords": [
6
6
  "react",
@@ -45,8 +45,8 @@
45
45
  },
46
46
  "devDependencies": {
47
47
  "@availity/api-axios": "^10.0.0",
48
- "@availity/mui-form-utils": "^1.0.0-alpha.0",
49
- "@availity/mui-textfield": "^1.0.0-alpha.0",
48
+ "@availity/mui-form-utils": "^1.0.0",
49
+ "@availity/mui-textfield": "^1.0.0",
50
50
  "@mui/material": "^6.4.5",
51
51
  "@tanstack/react-query": "^4.36.1",
52
52
  "react": "18.2.0",
@@ -56,8 +56,8 @@
56
56
  },
57
57
  "peerDependencies": {
58
58
  "@availity/api-axios": "^8.0.7",
59
- "@availity/mui-form-utils": "^1.0.0-alpha.0",
60
- "@availity/mui-textfield": "^1.0.0-alpha.0",
59
+ "@availity/mui-form-utils": "^1.0.0",
60
+ "@availity/mui-textfield": "^1.0.0",
61
61
  "@mui/material": "^6.4.5",
62
62
  "@tanstack/react-query": "^4.36.1",
63
63
  "react": ">=16.3.0"
@@ -1,6 +1,7 @@
1
1
  import { useState } from 'react';
2
2
  import type { ChipTypeMap } from '@mui/material/Chip';
3
3
  import { useInfiniteQuery, UseInfiniteQueryOptions } from '@tanstack/react-query';
4
+ import { AutocompleteInputChangeReason } from '@mui/material/Autocomplete';
4
5
 
5
6
  import { Autocomplete, AutocompleteProps } from './Autocomplete';
6
7
  import { useDebounce } from './util';
@@ -28,7 +29,7 @@ export interface AsyncAutocompleteProps<
28
29
  limit?: number;
29
30
  /** Config options for the useInfiniteQuery hook */
30
31
  queryOptions?: UseInfiniteQueryOptions<{ options: Option[]; hasMore: boolean; offset: number }>;
31
- /** Object of parameters used for the cacheKey. Options are re-reftched when a value in the object changes */
32
+ /** Object of parameters used for the cacheKey. Options are re-refetched when a value in the object changes */
32
33
  watchParams?: Record<string, unknown>;
33
34
  /** Time to wait before searching with the input value typed into the component */
34
35
  debounceTimeout?: number;
@@ -49,11 +50,12 @@ export const AsyncAutocomplete = <
49
50
  watchParams,
50
51
  debounceTimeout = 350,
51
52
  FieldProps,
53
+ onInputChange,
52
54
  ...rest
53
55
  }: AsyncAutocompleteProps<Option, Multiple, DisableClearable, FreeSolo, ChipComponent>) => {
54
56
  const [inputValue, setInputValue] = useState('');
55
57
 
56
- const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
58
+ const handleInputPropsOnChange = (event: React.ChangeEvent<HTMLInputElement>) => {
57
59
  setInputValue(event.target.value);
58
60
  // Call passed in onChange if present
59
61
  if (FieldProps?.InputProps?.onChange) FieldProps.InputProps.onChange(event);
@@ -71,14 +73,27 @@ export const AsyncAutocomplete = <
71
73
 
72
74
  const options = data?.pages ? data.pages.map((page) => page.options).flat() : [];
73
75
 
76
+ const handleOnInputChange = (
77
+ event: React.ChangeEvent<HTMLInputElement>,
78
+ value: string,
79
+ reason: AutocompleteInputChangeReason
80
+ ) => {
81
+ if (reason === 'clear') {
82
+ setInputValue(event.target.value);
83
+ }
84
+
85
+ if (onInputChange) onInputChange(event, value, reason);
86
+ };
87
+
74
88
  return (
75
89
  <Autocomplete
76
90
  {...rest}
91
+ onInputChange={handleOnInputChange}
77
92
  FieldProps={{
78
93
  ...FieldProps,
79
94
  InputProps: {
80
95
  ...FieldProps?.InputProps,
81
- onChange: handleInputChange,
96
+ onChange: handleInputPropsOnChange,
82
97
  },
83
98
  }}
84
99
  loading={isFetching}
@@ -52,4 +52,39 @@ describe('ProviderAutocomplete', () => {
52
52
  expect(screen.getByText('No options')).toBeDefined();
53
53
  });
54
54
  });
55
+
56
+ test('should refetch with no inputValue on clear', async () => {
57
+ const client = new QueryClient();
58
+
59
+ render(
60
+ <QueryClientProvider client={client}>
61
+ <ProviderAutocomplete customerId="123" FieldProps={{ label: 'Test' }} />
62
+ </QueryClientProvider>
63
+ );
64
+
65
+ const input = screen.getByRole('combobox');
66
+ fireEvent.click(input);
67
+ fireEvent.keyDown(input, { key: 'ArrowDown' });
68
+
69
+ await waitFor(() => {
70
+ expect(screen.getByText('Provider 0')).toBeDefined();
71
+ });
72
+
73
+ fireEvent.change(input, { target: { value: '21' } });
74
+
75
+ await waitFor(() => {
76
+ expect(screen.getByText('Provider 21')).toBeDefined();
77
+ expect(() => screen.getByText('Provider 0')).toThrow();
78
+ fireEvent.click(screen.getByText('Provider 21'));
79
+ });
80
+
81
+ expect(screen.getByTitle('Clear')).toBeDefined();
82
+ fireEvent.click(screen.getByTitle('Clear'));
83
+ fireEvent.click(input);
84
+ fireEvent.keyDown(input, { key: 'ArrowDown' });
85
+
86
+ await waitFor(() => {
87
+ expect(screen.getByText('Provider 0')).toBeDefined();
88
+ });
89
+ }, 10000000000);
55
90
  });