@sonardigital/carbon-ui 1.1.41 → 1.1.44

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sonardigital/carbon-ui",
3
- "version": "1.1.41",
3
+ "version": "1.1.44",
4
4
  "description": "",
5
5
  "main": "src/index.ts",
6
6
  "files": [
@@ -36,7 +36,7 @@ export function FormMultiselect({
36
36
  {...field}
37
37
  {...rest}
38
38
  options={options}
39
- value={value as { label: string; value: string | number }[]}
39
+ value={value as (string | number)[]}
40
40
  onChange={onChange}
41
41
  />
42
42
  {fieldState.error && <FormError label={fieldState.error?.message ?? ''} />}
@@ -15,7 +15,7 @@ interface SelectAutocompleteProps
15
15
  AutocompleteProps<{ label: string; value: string | number }, false, false, false>,
16
16
  'renderInput' | 'onChange' | 'value'
17
17
  > {
18
- value: { label: string; value: string | number }[];
18
+ value: (string | number)[];
19
19
  onChange: (value: (string | number | null)[]) => void;
20
20
  placeholder?: string;
21
21
  options: { label: string; value: string | number }[];
@@ -28,9 +28,15 @@ export function MultiselectAutocomplete(props: SelectAutocompleteProps): React.R
28
28
 
29
29
  const theme = useTheme();
30
30
 
31
+ const getSelectedOptions = (): { label: string; value: string | number }[] => {
32
+ if (!options) return [];
33
+ if (!value) return [];
34
+ return options.filter((option) => value?.includes(option.value)) || null;
35
+ };
36
+
31
37
  return (
32
38
  <Autocomplete
33
- value={value}
39
+ value={getSelectedOptions()}
34
40
  multiple
35
41
  options={options || []}
36
42
  getOptionLabel={(option: { label: string; value: string | number }) => option.label}
@@ -41,6 +47,9 @@ export function MultiselectAutocomplete(props: SelectAutocompleteProps): React.R
41
47
  }
42
48
  popupIcon={null}
43
49
  defaultValue={[]}
50
+ onChange={(_, newValue) => {
51
+ onChange(newValue.map((item) => item.value));
52
+ }}
44
53
  renderValue={(selected) => {
45
54
  return (
46
55
  <>