admin管理员组文章数量:1391974
Problem faced: In the documentation's code (=/demo.tsx), the drawer is triggered and opens when the "Open" button is clicked at the top. However, I want the drawer to be triggered and opened when the drawer is clicked instead. (onClick function)
What I've tried: I've tried attaching the onClick function to StyledBox and SwipeableDrawer ponents (=/demo.tsx) but the onClick function is not triggered and nothing happens. I've also tried enveloping div tags within the ponent tags to trigger the DOM directly like:
<SwipeableDrawer>
<div onClick={toggleDrawer(true)}></div>
</SwipeableDrawer>
What I need: If the documentation code (=/demo.tsx) can be modified so the drawer can be triggered when it is clicked on directly or a code snippet that works, that would be greatly appreciated.
Problem faced: In the documentation's code (https://codesandbox.io/s/cnvp4i?file=/demo.tsx), the drawer is triggered and opens when the "Open" button is clicked at the top. However, I want the drawer to be triggered and opened when the drawer is clicked instead. (onClick function)
What I've tried: I've tried attaching the onClick function to StyledBox and SwipeableDrawer ponents (https://codesandbox.io/s/cnvp4i?file=/demo.tsx) but the onClick function is not triggered and nothing happens. I've also tried enveloping div tags within the ponent tags to trigger the DOM directly like:
<SwipeableDrawer>
<div onClick={toggleDrawer(true)}></div>
</SwipeableDrawer>
What I need: If the documentation code (https://codesandbox.io/s/cnvp4i?file=/demo.tsx) can be modified so the drawer can be triggered when it is clicked on directly or a code snippet that works, that would be greatly appreciated.
Share Improve this question edited May 6, 2022 at 4:36 green555 asked May 6, 2022 at 4:13 green555green555 591 silver badge7 bronze badges2 Answers
Reset to default 5Adding pointerEvents: "all"
to the <StyledBox />
will capture the user events such as onClick
in this case.
Also, you don't need a div
inside <SwipeableDrawer />
, all you need is to pass a prop onClick={toggleDrawer(!open)}
to toggle the state of the drawer.
Codesandbox link
Note that in case you want to allow both open by click and open by touch drawing (e.g. to use the same drawer for touch and desktop devices) this is currently not possible. Touch drawing is disabled as soon as you put
<StyledBox
sx={{
...
pointerEvents: 'all',
}}
>
See confirmation in https://github./mui/material-ui/issues/30805
本文标签: javascriptSwipeable Drawer to open with onClick function (material ui)Stack Overflow
版权声明:本文标题:javascript - Swipeable Drawer to open with onClick function (material ui) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744708069a2620960.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论