Compare commits

...
Author SHA1 Message Date
Sonarly Claude Code 4f78fd914b fix: prevent MultiItemFieldInput click-outside from deleting items when input is not displayed
https://sonarly.com/issue/18203?type=bug

The click-outside handler in `MultiItemFieldInput` unconditionally runs item-update logic that interprets empty input as "delete item at index 0", causing file attachments (and other multi-item field values) to silently disappear.

Fix: The click-outside handler in `MultiItemFieldInput` unconditionally called `validateInputAndComputeUpdatedItems()`, which interprets empty `inputValue` + `itemToEditIndex=0` (both defaults) as "delete item at index 0". This caused the first item to be silently removed every time the user opened the dropdown and clicked away without editing.

The fix wraps the validate-and-update logic in an `if (isInputDisplayed)` guard. When the text input is not shown (the user is just viewing the item list), the click-outside handler now skips the mutation logic entirely and just calls `onClickOutside(items, event)` with the original items, which correctly persists the unchanged value and closes the cell.

This fixes both reported scenarios:
1. **Single file disappears on re-edit**: Opening the dropdown and clicking outside no longer triggers item deletion
2. **Deleting one of two files removes both**: After deleting one file via the delete button, clicking outside no longer triggers a second spurious deletion

The fix is minimal (one conditional guard) and preserves all existing behavior for the case when the user IS actively editing (typing in the input field).
2026-03-25 06:33:35 +00:00
@@ -91,13 +91,18 @@ export const MultiItemFieldInput = <T,>({
) {
return;
}
const { isValid, updatedItems } = validateInputAndComputeUpdatedItems();
if (!isValid) {
return;
if (isInputDisplayed) {
const { isValid, updatedItems } =
validateInputAndComputeUpdatedItems();
if (!isValid) {
return;
}
onChange(updatedItems);
}
onChange(updatedItems);
onClickOutside(items, event);
},
listenerId: instanceId,