Reputation: 1995
I am trying to add Swipeable edge to SwipeableDrawer:
The edge should appear even when the drawer is closed so that the user can click on it and slide the drawer to open it.
The problem is that on my app, when it's closed it does not appear. It only appears when the drawer has been opened with the Open button.
Here's the code in my app:
import * as React from "react";
import PropTypes from "prop-types";
import { Global } from "@emotion/react";
import { styled } from "@material-ui/core/styles";
import CssBaseline from "@material-ui/core/CssBaseline";
import { grey } from "@material-ui/core/colors";
import Button from "@material-ui/core/Button";
import Box from "@material-ui/core/Box";
// import Skeleton from "@material-ui/core/Skeleton";
import Typography from "@material-ui/core/Typography";
import SwipeableDrawer from "@material-ui/core/SwipeableDrawer";
const drawerBleeding = 56;
const Root = styled("div")(({ theme }) => ({
height: "100%",
backgroundColor:
theme.palette.mode === "light"
? grey[100]
: theme.palette.background.default,
}));
const StyledBox = styled(Box)(({ theme }) => ({
backgroundColor: theme.palette.mode === "light" ? "#fff" : grey[800],
}));
const Puller = styled(Box)(({ theme }) => ({
width: 30,
height: 6,
backgroundColor: theme.palette.mode === "light" ? grey[300] : grey[900],
borderRadius: 3,
position: "absolute",
top: 8,
left: "calc(50% - 15px)",
}));
function SwipeableEdgeDrawer(props) {
const { window } = props;
const [open, setOpen] = React.useState(false);
const toggleDrawer = (newOpen) => () => {
setOpen(newOpen);
};
// This is used only for the example
const container =
window !== undefined ? () => window().document.body : undefined;
return (
<Root>
<CssBaseline />
<Global
styles={{
".MuiDrawer-root > .MuiPaper-root": {
height: `calc(50% - ${drawerBleeding}px)`,
overflow: "visible",
},
}}
/>
{/* <Box sx={{ textAlign: "center", pt: 1 }}> */}
<Button className="btn-round" color="danger" onClick={toggleDrawer(true)}>
Open
</Button>
{/* </Box> */}
<SwipeableDrawer
container={container}
anchor="bottom"
open={open}
onClose={toggleDrawer(false)}
onOpen={toggleDrawer(true)}
swipeAreaWidth={drawerBleeding}
disableSwipeToOpen={false}
ModalProps={{
keepMounted: true,
}}
>
<StyledBox
sx={{
position: "absolute",
top: -drawerBleeding,
borderTopLeftRadius: 8,
borderTopRightRadius: 8,
visibility: "visible",
right: 0,
left: 0,
}}
>
<Puller />
<Typography sx={{ p: 2, color: "text.secondary" }}>
51 results
</Typography>
</StyledBox>
<StyledBox
sx={{
px: 2,
pb: 2,
height: "100%",
overflow: "auto",
}}
></StyledBox>
</SwipeableDrawer>
</Root>
);
}
SwipeableEdgeDrawer.propTypes = {
/**
* Injected by the documentation to work in an iframe.
* You won't need it on your project.
*/
window: PropTypes.func,
};
export default SwipeableEdgeDrawer;
The only difference with the code in the documentation is that I removed this:
// import Skeleton from "@material-ui/core/Skeleton";
Because I am using @material-ui/core
instead of @mui/material
and Skeleton does not exist in @material-ui/core
. I don't think this has any impact. But, I thought I should mention it.
Upvotes: 0
Views: 1684
Reputation: 28
I just had the same problem and noticed that the MuiPaper which is also used for the SwipeableDrawer has overflow-y set to auto. Therefore the overflowing part which is to be shown is not visible.
I solved it by adding this StyledSwipeableDrawer component:
const SwipeableDrawerStyled = styled(SwipeableDrawer)({
"& .MuiDrawer-paper": {
overflowY: "visible",
},
});
Upvotes: 1