@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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bitrise/bitkit",
3
3
  "description": "Bitrise React component library",
4
- "version": "13.234.0",
4
+ "version": "13.236.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+ssh://git@github.com/bitrise-io/bitkit.git"
@@ -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) => onChange?.({ target: { name, value: 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
- {currentOption?.label || formValueItem}
312
+ {labelMapRef.current?.get(formValueItem) || formValueItem}
299
313
  </Tag>
300
314
  );
301
315
  })}
@@ -139,7 +139,7 @@ const RealStage = ({
139
139
  )}
140
140
  </Box>
141
141
  <Box sx={style.labelContainer}>
142
- {action && !isDisabled ? (
142
+ {action && !isDisabled && !isSkipped ? (
143
143
  <Link
144
144
  as={action.href ? 'a' : 'button'}
145
145
  colorScheme="purple"