Skip to content

Commit

Permalink
[docs][material-ui][Drawer] Resolve flickering when double-clicking o…
Browse files Browse the repository at this point in the history
…n the backdrop to close it (mui#40343)

Signed-off-by: Marija Najdova <[email protected]>
Co-authored-by: Marija Najdova <[email protected]>
  • Loading branch information
aacevski and mnajdova authored Jan 9, 2024
1 parent 191d684 commit d816fb0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
17 changes: 15 additions & 2 deletions docs/data/material/components/drawers/ResponsiveDrawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,21 @@ const drawerWidth = 240;
function ResponsiveDrawer(props) {
const { window } = props;
const [mobileOpen, setMobileOpen] = React.useState(false);
const [isClosing, setIsClosing] = React.useState(false);

const handleDrawerClose = () => {
setIsClosing(true);
setMobileOpen(false);
};

const handleDrawerTransitionEnd = () => {
setIsClosing(false);
};

const handleDrawerToggle = () => {
setMobileOpen(!mobileOpen);
if (!isClosing) {
setMobileOpen(!mobileOpen);
}
};

const drawer = (
Expand Down Expand Up @@ -97,7 +109,8 @@ function ResponsiveDrawer(props) {
container={container}
variant="temporary"
open={mobileOpen}
onClose={handleDrawerToggle}
onTransitionEnd={handleDrawerTransitionEnd}
onClose={handleDrawerClose}
ModalProps={{
keepMounted: true, // Better open performance on mobile.
}}
Expand Down
17 changes: 15 additions & 2 deletions docs/data/material/components/drawers/ResponsiveDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,21 @@ interface Props {
export default function ResponsiveDrawer(props: Props) {
const { window } = props;
const [mobileOpen, setMobileOpen] = React.useState(false);
const [isClosing, setIsClosing] = React.useState(false);

const handleDrawerClose = () => {
setIsClosing(true);
setMobileOpen(false);
};

const handleDrawerTransitionEnd = () => {
setIsClosing(false);
};

const handleDrawerToggle = () => {
setMobileOpen(!mobileOpen);
if (!isClosing) {
setMobileOpen(!mobileOpen);
}
};

const drawer = (
Expand Down Expand Up @@ -104,7 +116,8 @@ export default function ResponsiveDrawer(props: Props) {
container={container}
variant="temporary"
open={mobileOpen}
onClose={handleDrawerToggle}
onTransitionEnd={handleDrawerTransitionEnd}
onClose={handleDrawerClose}
ModalProps={{
keepMounted: true, // Better open performance on mobile.
}}
Expand Down

0 comments on commit d816fb0

Please sign in to comment.