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

It can't be closed when even isOpen = true #120

Open
IslamicProgrammer opened this issue Apr 16, 2023 · 7 comments
Open

It can't be closed when even isOpen = true #120

IslamicProgrammer opened this issue Apr 16, 2023 · 7 comments

Comments

@IslamicProgrammer
Copy link

<Sheet isOpen={open} onClose={() => {}}>
<Sheet.Container>
<Sheet.Header />
<Sheet.Content>{body}</Sheet.Content>
</Sheet.Container>
<Sheet.Backdrop />

  In my case open is true but i can close it
@adshrc
Copy link

adshrc commented Apr 20, 2023

you need to use a State where you track the open status. if you set the open to false, it will close the modal.
Btw, </Sheet> is missing at the end

@Temzasse
Copy link
Owner

Currently the only way to force the sheet to remain open is to re-open it when the user closes it:

const [isOpen, setOpen] = useState(false);

return (
  <Sheet isOpen={isOpen} onClose={() => setOpen(true)} />
);

I'll try to find a better way to force the sheet to remain open 🕵🏻

@IslamicProgrammer IslamicProgrammer changed the title It can be closed when even isOpen = true It can't be closed when even isOpen = true May 18, 2023
@ReidCampbell
Copy link

I am also interested in an option to persist the bottom sheet. Id like an option for dragging to stop once it hits the last snap point

@AbdullahKhan780
Copy link

Currently the only way to force the sheet to remain open is to re-open it when the user closes it:

const [isOpen, setOpen] = useState(false);

return (
  <Sheet isOpen={isOpen} onClose={() => setOpen(true)} />
);

I'll try to find a better way to force the sheet to remain open 🕵🏻

This way the animation gets broken! I have attached my code screenshot and a video of how it's behaving. I hope it will be fixed soon!

Screenshot 2023-07-31 at 12 21 19 PM
WhatsApp.Video.2023-07-31.at.12.18.47.PM.mp4

@ReidCampbell
Copy link

Yeah setting it to <Sheet isOpen={isOpen} onClose={() => setOpen(true)} /> didn't work for me. I ended up doing

useEffect(() => {
  if (isOpen) return;
  setTimeout(open, 200);
}, [isOpen, open]);

<Sheet isOpen={isOpen} onClose={close} />

Id like the ability for the sheet not to be able to be dragged past the lowest snapPoint and the ability to disable the closing when the drag force is high i.e. Dragging down fast at the highest snapPoint shouldn't cause it to close.

@amnanjum01
Copy link

I have found a way around. So basically, when the isOpen state changes to false, I have added a useEffect hook with isOpen in my dependency array. Once the isOpen changes from true to false, inside the useEffect I will check if the state is false and if it is false I will set it to true. (In my answer, isResultOpen is isOpen)

`const [isResultOpen, setIsResultOpen] = useState(false);

useEffect(()=>{
if(isResultOpen == false){
setIsResultOpen(true)
}
},[isResultOpen])

`

You might be wondering if it is false by default then it is true by default because on the initial render it is false and then this will be detected and it will be turned into true right away so no time to actually open it. Well, I found a work around that would conditionally render the component as per my use case.

@NicolasJott
Copy link

Yeah setting it to <Sheet isOpen={isOpen} onClose={() => setOpen(true)} /> didn't work for me. I ended up doing

useEffect(() => {
  if (isOpen) return;
  setTimeout(open, 200);
}, [isOpen, open]);

<Sheet isOpen={isOpen} onClose={close} />

Id like the ability for the sheet not to be able to be dragged past the lowest snapPoint and the ability to disable the closing when the drag force is high i.e. Dragging down fast at the highest snapPoint shouldn't cause it to close.

This was my solution which seems to be working for me.

 <Sheet isOpen={sheetOpen} onClose={() => setSheetOpen(false)} onCloseEnd={() => setSheetOpen(true)} />

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

No branches or pull requests

7 participants