@bitrise/bitkit 13.234.0 → 13.236.0
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
|
@@ -178,7 +178,9 @@ function useDropdown<T>({
|
|
|
178
178
|
|
|
179
179
|
const [formValue, setFormValue] = useControllableState<T>({
|
|
180
180
|
defaultValue: isMultiSelect ? defaultValue || ([] as T) : defaultValue,
|
|
181
|
-
onChange: (newValue) =>
|
|
181
|
+
onChange: (newValue) => {
|
|
182
|
+
onChange?.({ target: { name, value: newValue } });
|
|
183
|
+
},
|
|
182
184
|
value,
|
|
183
185
|
});
|
|
184
186
|
const [formLabel, setFormLabel] = useState<ReactNode>();
|
|
@@ -204,13 +206,27 @@ function useDropdown<T>({
|
|
|
204
206
|
onSearch: () => setActiveIndex(null),
|
|
205
207
|
});
|
|
206
208
|
|
|
209
|
+
// this can just be a ref as it will always be updated when formValue is, which will cause a re-render
|
|
210
|
+
const labelMapRef = useRef<Map<T, ReactNode>>();
|
|
211
|
+
if (!labelMapRef.current) labelMapRef.current = new Map();
|
|
212
|
+
|
|
213
|
+
// clear map when value is changed from the outside
|
|
214
|
+
useEffect(() => {
|
|
215
|
+
if (labelMapRef.current && Array.isArray(value)) {
|
|
216
|
+
const removed = labelMapRef.current.keys().filter((key) => !value.includes(key));
|
|
217
|
+
removed.forEach((remove) => labelMapRef.current?.delete(remove));
|
|
218
|
+
}
|
|
219
|
+
}, [value]);
|
|
220
|
+
|
|
207
221
|
const onOptionSelected = useCallback(
|
|
208
222
|
(args: DropdownEventArgs<T>) => {
|
|
209
223
|
setFormValue((previous) => {
|
|
210
224
|
if (Array.isArray(previous)) {
|
|
211
225
|
if (previous.includes(args.value)) {
|
|
226
|
+
labelMapRef.current?.delete(args.value);
|
|
212
227
|
return previous.filter((aPrevious) => aPrevious !== args.value) as T;
|
|
213
228
|
}
|
|
229
|
+
labelMapRef.current?.set(args.value, args.label);
|
|
214
230
|
|
|
215
231
|
return [...previous, args.value] as T;
|
|
216
232
|
}
|
|
@@ -275,8 +291,6 @@ function useDropdown<T>({
|
|
|
275
291
|
return <>{formValueItem}</>;
|
|
276
292
|
}
|
|
277
293
|
|
|
278
|
-
const currentOption = findOption(refdChildren, formValueItem);
|
|
279
|
-
|
|
280
294
|
return (
|
|
281
295
|
<Tag
|
|
282
296
|
colorScheme="neutral"
|
|
@@ -295,7 +309,7 @@ function useDropdown<T>({
|
|
|
295
309
|
}}
|
|
296
310
|
size="sm"
|
|
297
311
|
>
|
|
298
|
-
{
|
|
312
|
+
{labelMapRef.current?.get(formValueItem) || formValueItem}
|
|
299
313
|
</Tag>
|
|
300
314
|
);
|
|
301
315
|
})}
|