Skip to content

[Tearsheet]: onClose does not receive updated state values #8681

@kcpru

Description

@kcpru

Package

Carbon for IBM Products

Description

When using the Tearsheet with an onClose callback that returns a boolean, the callback seems to capture a stale state value. If onClose returns a value derived from a useState variable, the Tearsheet continues to use the initial state value instead of the most recent one. The state only updates correctly after closing and reopening the Tearsheet.

Component(s) impacted

Tearsheet

Browser

No response

@carbon/ibm-products (previously @carbon/ibm-cloud-cognitive) version

2.78.0

Suggested Severity

None

Product/offering

Glossary

CodeSandbox or Stackblitz example

https://stackblitz.com/edit/github-fadd4uc7-rnv9g4o4?file=src%2FExample%2FExample.jsx

Steps to reproduce the issue (if applicable)

  1. Open the Stackblitz example
  2. Press ESC - the tearsheet closes as expected
  3. Reopen the Terasheet
  4. Click the button that toggles Prevent closing to true
  5. Press ESC again - the Tearsheet closes (but it sholdn't)
  6. Reopen the Tearsheet
  7. Press ESC - only now the Tearsheet doesn't close

Observe the console logs - while pressing ESC, preventClosing value remains stale (initial value)

Release date (if applicable)

No response

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Needs triage 🧐

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions