4

Chakra Ui provides disclosure

  const { isOpen, onOpen, onClose } = useDisclosure();  

and in the documentation this button will close the drawer

<Button variant="outline" mr={3} onClick={onClose}>
   Cancel
</Button>

they haven't provided something like close() function to close it programmatically, or am i missing something

Jash Jariwala
  • 95
  • 1
  • 7

3 Answers3

3

onClose is function provided from chakra-ui which will close the drawer or any portal created opened by chakra-ui. onClose behaves like close() function only.

Ferin Patel
  • 3,424
  • 2
  • 17
  • 49
1

When you want to open the drawer use onOpen function inside onClick or what you want, when you want to close the drawer use onClose inside inside onClick or what you want. Don't worry, these have code behind which take care of handling drawer.

George Hutanu
  • 139
  • 1
  • 5
0

pass onClose in onClick={} and don't forget to add () after onClose to prevent errors

<Button onClick={()=>onClose()}>X

othmane-be
  • 82
  • 1
  • 7