react-modal-sheet icon indicating copy to clipboard operation
react-modal-sheet copied to clipboard

It can't be closed when even isOpen = true

Open IslamicProgrammer opened this issue 1 year ago • 6 comments

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

  In my case open is true but i can close it

IslamicProgrammer avatar Apr 16 '23 16:04 IslamicProgrammer

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

adshrc avatar Apr 20 '23 10:04 adshrc

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 🕵🏻

Temzasse avatar May 17 '23 08:05 Temzasse

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

ReidCampbell avatar Jul 25 '23 11:07 ReidCampbell

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

https://github.com/Temzasse/react-modal-sheet/assets/68871807/50dacbe9-089b-40eb-a6a6-7ba402630371

AbdullahKhan780 avatar Jul 31 '23 07:07 AbdullahKhan780

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.

ReidCampbell avatar Aug 02 '23 12:08 ReidCampbell

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.

amnanjum01 avatar May 16 '24 18:05 amnanjum01