@groupeactual/ui-kit 1.0.5 → 1.0.7

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.
@@ -26,7 +26,7 @@ import Chip from '../../Chip/Chip';
26
26
  interface AutocompleteMultipleSelectProps<T>
27
27
  extends Omit<
28
28
  AutocompleteProps<T, true, true, false>,
29
- 'value' | 'onChange' | 'defaultValue' | 'options' | 'renderInput' | 'error'
29
+ 'onChange' | 'defaultValue' | 'options' | 'renderInput' | 'error'
30
30
  > {
31
31
  label?: string;
32
32
  helperText?: string;
@@ -65,7 +65,7 @@ const AutocompleteMultipleSelect = <T,>({
65
65
  const [inputValue, setInputValue] = useState('');
66
66
 
67
67
  const handleValueChange = (
68
- event: React.SyntheticEvent<Element, Event>,
68
+ _event: React.SyntheticEvent<Element, Event>,
69
69
  newValue: T[]
70
70
  ) => {
71
71
  setValue(newValue);
@@ -76,7 +76,7 @@ const AutocompleteMultipleSelect = <T,>({
76
76
  };
77
77
 
78
78
  const handleInputChange = (
79
- event: React.SyntheticEvent<Element, Event>,
79
+ _event: React.SyntheticEvent<Element, Event>,
80
80
  newInputValue: string
81
81
  ) => {
82
82
  setInputValue(newInputValue);
@@ -88,9 +88,14 @@ const AutocompleteMultipleSelect = <T,>({
88
88
  };
89
89
 
90
90
  const handleDeleteChip = (chipValue: T) => {
91
- const newValue = value?.filter((val) => val !== chipValue);
92
- if (onChange) onChange(newValue);
93
- setValue(newValue);
91
+ const newValue = props?.value ?
92
+ props?.value?.filter((val) => val !== chipValue) :
93
+ value?.filter((val) => val !== chipValue);
94
+
95
+ if (newValue) {
96
+ if (onChange) onChange(newValue);
97
+ setValue(newValue);
98
+ }
94
99
  };
95
100
 
96
101
  const preventEventPropagation = (event: React.MouseEvent) => {
@@ -100,10 +105,10 @@ const AutocompleteMultipleSelect = <T,>({
100
105
  const addFormControlClassName = useMemo(() => {
101
106
  const classNames: string[] = ['DsAutoComplete DsAutoCompleteMulti'];
102
107
  if (disabled) classNames.push('Mui-disabled');
103
- if (value?.length > 0) classNames.push('Mui-filled');
108
+ if ((props.value && props.value?.length > 0) || value?.length > 0) classNames.push('Mui-filled');
104
109
 
105
110
  return classNames.join(' ');
106
- }, [value, disabled]);
111
+ }, [value, disabled, props?.value]);
107
112
 
108
113
  const addInputLabelClassName = useMemo(() => {
109
114
  const classNames: string[] = [];
@@ -111,10 +116,10 @@ const AutocompleteMultipleSelect = <T,>({
111
116
  if (error) classNames.push('Mui-error');
112
117
  if (color === 'success') classNames.push('Mui-success');
113
118
  if (disabled) classNames.push('Mui-disabled');
114
- if (value?.length > 0) classNames.push('Mui-Input-filled');
119
+ if ((props.value && props.value?.length > 0) || value?.length > 0) classNames.push('Mui-Input-filled');
115
120
 
116
121
  return classNames.join(' ');
117
- }, [error, disabled]);
122
+ }, [error, disabled, props?.value, value]);
118
123
 
119
124
  return (
120
125
  <Box sx={{ width }}>
@@ -127,12 +132,12 @@ const AutocompleteMultipleSelect = <T,>({
127
132
  value={value}
128
133
  onChange={handleValueChange}
129
134
  onInputChange={handleInputChange}
135
+ inputValue={inputValue}
130
136
  {...props}
131
137
  placeholder={value.length || label === placeholder ? '' : placeholder}
132
138
  disableCloseOnSelect
133
139
  multiple
134
140
  disabled={disabled}
135
- inputValue={inputValue}
136
141
  options={options}
137
142
  clearIcon={
138
143
  <>
@@ -154,10 +159,10 @@ const AutocompleteMultipleSelect = <T,>({
154
159
  size={color === 'success' ? 'md' : 'sm'}
155
160
  />
156
161
  }
157
- renderTags={(value: T[]) => {
162
+ renderTags={(tag: T[]) => {
158
163
  return (
159
164
  <>
160
- {value.map((selectedOption: T, index: number) => (
165
+ {tag.map((selectedOption: T, _index: number) => (
161
166
  <Chip
162
167
  key={getKeyValue(selectedOption)}
163
168
  variant="filled"
@@ -23,7 +23,7 @@ import IconProvider from '../../Icon';
23
23
  interface Props<T>
24
24
  extends Omit<
25
25
  AutocompleteProps<T, false, false, false>,
26
- 'value' | 'onChange' | 'defaultValue' | 'options' | 'renderInput' | 'error'
26
+ 'onChange' | 'defaultValue' | 'options' | 'renderInput' | 'error'
27
27
  > {
28
28
  label: string;
29
29
  options: T[];
@@ -84,10 +84,10 @@ const AutoCompleteSingle = <T extends {}>({
84
84
  const getFormControlClassName = useMemo(() => {
85
85
  const classNames: string[] = ['DsAutoComplete DsAutoCompleteSingle'];
86
86
  if (disabled) classNames.push('Mui-disabled');
87
- if (value) classNames.push('Mui-filled');
87
+ if (props?.value || value) classNames.push('Mui-filled');
88
88
 
89
89
  return classNames.join(' ');
90
- }, [value, disabled]);
90
+ }, [value, props?.value, disabled]);
91
91
 
92
92
  const getInputLabelClassName = useMemo(() => {
93
93
  const classNames: string[] = [];