@availity/mui-controlled-form 1.2.0 → 1.2.2

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,24 @@
2
2
 
3
3
  This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4
4
 
5
+ ## [1.2.2](https://github.com/Availity/element/compare/@availity/mui-controlled-form@1.2.1...@availity/mui-controlled-form@1.2.2) (2025-04-08)
6
+
7
+ ### Dependency Updates
8
+
9
+ * `mui-datepicker` updated to version `1.2.1`
10
+ * `theme-provider` updated to version `1.2.1`
11
+ ## [1.2.1](https://github.com/Availity/element/compare/@availity/mui-controlled-form@1.2.0...@availity/mui-controlled-form@1.2.1) (2025-04-04)
12
+
13
+ ### Dependency Updates
14
+
15
+ * `mui-autocomplete` updated to version `1.2.0`
16
+ * `mui-datepicker` updated to version `1.2.0`
17
+ * `mui-textfield` updated to version `1.2.0`
18
+
19
+ ### Bug Fixes
20
+
21
+ * **mui-controlled-form:** allow defaultOptions on multiple AsyncAutocomplete ([4dcb5bc](https://github.com/Availity/element/commit/4dcb5bc4d1a02a54b5a2d0540e15d77a07aa7c02))
22
+
5
23
  ## [1.2.0](https://github.com/Availity/element/compare/@availity/mui-controlled-form@1.1.3...@availity/mui-controlled-form@1.2.0) (2025-03-31)
6
24
 
7
25
  ### Dependency Updates
package/dist/index.js CHANGED
@@ -145,10 +145,10 @@ var ControlledAsyncAutocomplete = (_a) => {
145
145
  loadOptions: (offset, limit, inputValue) => __async(void 0, null, function* () {
146
146
  const { options, hasMore, offset: returnedOffsetValue } = yield rest.loadOptions(offset, limit, inputValue);
147
147
  if (defaultToFirstOption && offset === 0) {
148
- setValue(name, options[0]);
148
+ setValue(name, rest.multiple ? [options[0]] : options[0]);
149
149
  }
150
150
  if (defaultToOnlyOption && offset === 0 && options.length === 1) {
151
- setValue(name, options[0]);
151
+ setValue(name, rest.multiple ? [options[0]] : options[0]);
152
152
  }
153
153
  return { options, hasMore, offset: returnedOffsetValue };
154
154
  })
package/dist/index.mjs CHANGED
@@ -109,10 +109,10 @@ var ControlledAsyncAutocomplete = (_a) => {
109
109
  loadOptions: (offset, limit, inputValue) => __async(void 0, null, function* () {
110
110
  const { options, hasMore, offset: returnedOffsetValue } = yield rest.loadOptions(offset, limit, inputValue);
111
111
  if (defaultToFirstOption && offset === 0) {
112
- setValue(name, options[0]);
112
+ setValue(name, rest.multiple ? [options[0]] : options[0]);
113
113
  }
114
114
  if (defaultToOnlyOption && offset === 0 && options.length === 1) {
115
- setValue(name, options[0]);
115
+ setValue(name, rest.multiple ? [options[0]] : options[0]);
116
116
  }
117
117
  return { options, hasMore, offset: returnedOffsetValue };
118
118
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@availity/mui-controlled-form",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "description": "Availity MUI/react-hook-form controlled form components - part of the @availity/element design system",
5
5
  "keywords": [
6
6
  "react",
@@ -40,11 +40,11 @@
40
40
  "publish:canary": "yarn npm publish --access public --tag canary"
41
41
  },
42
42
  "dependencies": {
43
- "@availity/mui-autocomplete": "^1.0.9",
43
+ "@availity/mui-autocomplete": "^1.0.10",
44
44
  "@availity/mui-checkbox": "^1.0.1",
45
- "@availity/mui-datepicker": "^1.0.6",
45
+ "@availity/mui-datepicker": "^1.0.8",
46
46
  "@availity/mui-form-utils": "^1.1.0",
47
- "@availity/mui-textfield": "^1.1.1",
47
+ "@availity/mui-textfield": "^1.1.2",
48
48
  "react-hook-form": "^7.54.2"
49
49
  },
50
50
  "devDependencies": {
@@ -76,12 +76,14 @@ export const _ControlledAsyncAutoComplete: StoryObj<typeof ControlledAsyncAutoco
76
76
  limit: 10,
77
77
  queryKey: 'example',
78
78
  rules: { required: 'This is required.' },
79
+ defaultToFirstOption: true,
80
+ disableClearable: true,
79
81
  },
80
82
  };
81
83
 
82
- export const _ControlledAsyncAutoCompleteDefaultOption: StoryObj<typeof ControlledAsyncAutocomplete> = {
84
+ export const _ControlledAsyncAutoCompleteMultiple: StoryObj<typeof ControlledAsyncAutocomplete> = {
83
85
  render: (args) => {
84
- const methods = useForm();
86
+ const methods = useForm({ defaultValues: { controlledAsyncAutocomplete: [] } });
85
87
 
86
88
  return (
87
89
  <QueryClientProvider client={client}>
@@ -112,11 +114,56 @@ export const _ControlledAsyncAutoCompleteDefaultOption: StoryObj<typeof Controll
112
114
  name: 'controlledAsyncAutocomplete',
113
115
  FieldProps: { label: 'Async Select', helperText: 'Helper Text', fullWidth: false, required: true },
114
116
  getOptionLabel: (val: Option) => val.label,
117
+ isOptionEqualToValue: (option, value) => option.label === value.label,
115
118
  loadOptions,
116
- limit: 10,
119
+ limit: 5,
117
120
  queryKey: 'example',
118
121
  rules: { required: 'This is required.' },
119
122
  defaultToFirstOption: true,
120
123
  disableClearable: true,
124
+ multiple: true,
125
+ filterSelectedOptions: true,
126
+ },
127
+ };
128
+
129
+ export const _ControlledAsyncAutoCompleteDefaultToOnlyOption: StoryObj<typeof ControlledAsyncAutocomplete> = {
130
+ render: (args) => {
131
+ const methods = useForm();
132
+
133
+ return (
134
+ <QueryClientProvider client={client}>
135
+ <FormProvider {...methods}>
136
+ <form onSubmit={methods.handleSubmit((data) => data)}>
137
+ <ControlledAsyncAutocomplete {...args} />
138
+ <Grid container direction="row" justifyContent="space-between" marginTop={1}>
139
+ <Button
140
+ disabled={!methods?.formState?.isSubmitSuccessful}
141
+ children="Reset"
142
+ color="secondary"
143
+ onClick={() => methods.reset()}
144
+ />
145
+ <Button type="submit" disabled={methods?.formState?.isSubmitSuccessful} children="Submit" />
146
+ </Grid>
147
+ {methods?.formState?.isSubmitSuccessful ? (
148
+ <Paper sx={{ padding: '1.5rem', marginTop: '1.5rem' }}>
149
+ <Typography variant="h2">Submitted Values</Typography>
150
+ <pre data-testid="result">{JSON.stringify(methods.getValues(), null, 2)}</pre>
151
+ </Paper>
152
+ ) : null}
153
+ </form>
154
+ </FormProvider>
155
+ </QueryClientProvider>
156
+ );
157
+ },
158
+ args: {
159
+ name: 'controlledAsyncAutocomplete',
160
+ FieldProps: { label: 'Async Select', helperText: 'Helper Text', fullWidth: false, required: true },
161
+ getOptionLabel: (val: Option) => val.label,
162
+ loadOptions,
163
+ limit: 1,
164
+ queryKey: 'example2',
165
+ rules: { required: 'This is required.' },
166
+ defaultToOnlyOption: true,
167
+ disableClearable: true,
121
168
  },
122
169
  };
@@ -71,11 +71,11 @@ export const ControlledAsyncAutocomplete = <
71
71
  const { options, hasMore, offset: returnedOffsetValue } = await rest.loadOptions(offset, limit, inputValue);
72
72
 
73
73
  if (defaultToFirstOption && offset === 0) {
74
- setValue(name, options[0]);
74
+ setValue(name, rest.multiple ? [options[0]] : options[0]);
75
75
  }
76
76
 
77
77
  if (defaultToOnlyOption && offset === 0 && options.length === 1) {
78
- setValue(name, options[0]);
78
+ setValue(name, rest.multiple ? [options[0]] : options[0]);
79
79
  }
80
80
 
81
81
  return { options, hasMore, offset: returnedOffsetValue };