You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[EuiCheckableCard] onChange handler invoked twice upon checkbox click #8782
Describe the bug
When the EuiCheckableCard component is set with the checkableType="checkbox" property, the handler passed to onChange is invoked twice when the click occurs directly on the checkbox itself, while it triggers correctly only once when clicking around the checkbox or on the label.
✅ onChange triggered once
❌ onChange triggered twice
Environment and versions
EUI version: 103
React version: 18
To Reproduce
Run this component in isolation
exportdefault()=>{const[checkbox,setCheckbox]=useState(false);constcheckboxCardId=useGeneratedHtmlId({prefix: 'checkboxCard'});return(<EuiCheckableCardid={checkboxCardId}label="I am a checkbox"checkableType="checkbox"value="checkbox1"checked={checkbox}onChange={()=>setCheckbox(prev=>!prev)}/>);};
N.B. Differently from the demo in the docs, the boolean update is made with a functional update to demonstrate how this could easily break depending on what the event handler does.
Expected behavior
The event handler passed to onChange should always be invoked once, indipendently from where the click occurs in the card.
@weronikaolejniczak the suggested workaround is valid just because React would reference the old value twice when the handler is triggered, but the onChange is not just to toggle or integrate with a watched value.
For instance, this workaround is won't work when integrating with other state management libraries.
Activity
weronikaolejniczak commentedon Jun 11, 2025
The key difference is here:
onChange={() => setCheckbox((prevValue) => !prevValue)}This should work correctly. Reproduction sandboxFor a workaround, reference the state directly:
!isChecked. Not ideal but according to the docs example works.tonyghiani commentedon Jun 11, 2025
@weronikaolejniczak the suggested workaround is valid just because React would reference the old value twice when the handler is triggered, but the
onChangeis not just to toggle or integrate with a watched value.For instance, this workaround is won't work when integrating with other state management libraries.
mgadewoll commentedon Jun 12, 2025
ℹ It's triggered twice because of this part here.
When the input is clicked, it's clicked as itself and via the additional programmatic click. We'll need to check the target to exclude it.