Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: SelectableTile onChange method is presented with stale 'selected' value #18478

Open
2 tasks done
cbrooker27 opened this issue Jan 29, 2025 · 0 comments · May be fixed by #18765
Open
2 tasks done

[Bug]: SelectableTile onChange method is presented with stale 'selected' value #18478

cbrooker27 opened this issue Jan 29, 2025 · 0 comments · May be fixed by #18765
Assignees

Comments

@cbrooker27
Copy link

Package

@carbon/react

Browser

Chrome

Package version

1.74.0

React version

v18.3.1

Description

When the SelectedTile component is in the 'unselected' state and we trigger a change (via click or keyboard), the onChange method is presented with a selected value that is stale. In this case, it is presented with false. The UI redraws correctly and properly updates all the data as far as I can tell.

The defect stems from calling onChange after calling setIsSelected and assuming that setIsSelected will impact the value of isSelected during this call. It will not, it will only drive a re-render.
https://react.dev/learn/state-as-a-snapshot#state-over-time

A suggested fix would be to use the same value that is passed to setIsSelected to also be passed to onChange

Reproduction/example

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

Steps to reproduce

Access the example provided and click the selectable tile in the preview area. Observe the incorrect value presented to the method.

Suggested Severity

Severity 3 = User can complete task, and/or has a workaround within the user experience of a given component.

Application/PAL

No response

Code of Conduct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 🚦 In Review
Development

Successfully merging a pull request may close this issue.

3 participants