How does the drawer component work? #342
-
I've been trying to get the drawer component to work correctly for several hours with little progress. I'm hoping someone can explain the bits that I'm not getting. I'm working in React. My issue is as follows: I can't figure out how to close the drawer. I think I understand how it's suppose to work. Which is this:
I problem appears when I need to close the drawer. The way I understand it I should be able to do something like this: const myComponent = () => {
...BLAH
const handleDrawerToggle = () => {
setDrawerState(!drawerState)
}
return (
<>
<label htmlFor='menu' className='drawer-overlay' onClick={handleDrawerToggle}></label>
</>
);
} I don't think this approach is wrong so the major problem is that I am likely misunderstanding something about how this classes must be layered together because the overlay doesn't obscure the drawer-content container and is not clickable. Thanks in advance for any suggestions or help. If anyone has an example of the drawer working in a manner that function essentially identical to daisyUI docs that would be a huge help. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
@shawnlikescode drawer works with the hidden checkbox and labels are there to control the checkbox so there wont be any JS needed. however, labels don't really change the value of the checkbox when clicked. so If you want to control the open/close functionality with JS, you can use |
Beta Was this translation helpful? Give feedback.
@shawnlikescode drawer works with the hidden checkbox and labels are there to control the checkbox so there wont be any JS needed. however, labels don't really change the value of the checkbox when clicked. so If you want to control the open/close functionality with JS, you can use
onClick
for the buttons and alsodrawer-overlay
to handle the value of checkbox.Here's an example using React: https://codesandbox.io/s/daisyui-drawer-react-ne6mk