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

Document onClose invoked on initial render when index is -1 #1540

Closed
x43n opened this issue Sep 20, 2023 · 2 comments
Closed

Document onClose invoked on initial render when index is -1 #1540

x43n opened this issue Sep 20, 2023 · 2 comments
Labels

Comments

@x43n
Copy link

x43n commented Sep 20, 2023

Feature Request

Add info to the index prop documentation detailing the behaviour commented here, specifically regarding "we fire the onClose callback"

Why it is needed

It is somewhat counter-intuitive to invoke the onClose callback when the desired initial state of the bottomsheet is closed (index -1). The onChange callback can be used for tracking a explicit close event, so it's ok, but good for this to be clearly in the docs to avoid confusing over why onClose is being called when the user has no closed anything.

@x43n x43n added the enhancement New feature or request label Sep 20, 2023
@github-actions
Copy link

@x43n: hello! 👋

This issue is being automatically closed because it does not follow the issue template.

@ponikar
Copy link

ponikar commented Nov 21, 2024

this is weird behaviour, somehow onClose gets invoked initially when trying to open the sheet. After debugging for a hour.
Came up with this hack. It might be helpful for you.

 const initial = useRef(true);
    const onClose = () => {
      // avoid trigger onClose initially
      if (initial.current && ref) {
        initial.current = false;
        ref.current.expand();
        return;
      }
      props?.onClose?.();
    };

ref has a reference of BottomSheet via useRef.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants