carbon-design-system / carbon

A design system built by IBM
https://www.carbondesignsystem.com
Apache License 2.0
7.87k stars 1.82k forks source link

[Bug]: ComboBox: onChange is called twice when clearing the input field #18137

Open pedesen opened 1 day ago

pedesen commented 1 day ago

Package

@carbon/react

Browser

Firefox, Chrome

Package version

1.70.0

React version

18.2.0

Description

There is another issue when ComboBox is used as a fully controlled input (meaning with selectedItem and onChange props provided):

When clicking on the "clear selected item" button, the onChange is called twice: first time with null and second time with the item that was cleared before. This leads to unexpected behavior.

This currently prevents us to upgrade @carbon/react, because I was not able to find a workaround for this.

Reproduction/example

https://stackblitz.com/edit/github-w7mkre-dtgf2u?file=src%2FApp.jsx

Steps to reproduce

  1. Clear combobox
  2. Select Item 1
  3. Clear combobox again
  4. Observe console logs

Problem: After step 3 onChange is called twice: first time with null and second time with the item that was cleared before. This leads to unexpected behavior.

Suggested Severity

Severity 2 = User cannot complete task, and/or no workaround within the user experience of a given component.

Application/PAL

No response

Code of Conduct