Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MUI Swipeable Drawer but let some part be always visible

I aim to have a swipeable footer, similar to:

enter image description here

MUI Swipeable Drawer looks very close to that, if only I could make it to not close completely and to remain some part visible. Is it possible to do?

like image 987
Anna Avatar asked Oct 29 '25 03:10

Anna


2 Answers

I have a similar task, maybe this codesandbox will help you https://codesandbox.io/s/ykj8t?file=/demo.tsx

like image 99
aironrich Avatar answered Oct 30 '25 16:10

aironrich


you can do something with button like this :

const useStyles = makeStyles({
  list: {
    width: 250,
  },
  fullList: {
    width: 'auto',
  },
  buttonDrawer: {
    position:"absolute",
bottom:0,
left:0,
border:"1px solid ",
borderRadius:0
  }
});

export default function SwipeableTemporaryDrawer() {
  const classes = useStyles();
  const [state, setState] = React.useState({
    top: false,
    left: false,
    bottom: false,
    right: false,
  });

  const toggleDrawer = (anchor, open) => (event) => {
    if (event && event.type === 'keydown' && (event.key === 'Tab' || event.key === 'Shift')) {
      return;
    }

    setState({ ...state, [anchor]: open });
  };

  const list = (anchor) => (
    <div
      className={clsx(classes.list, {
        [classes.fullList]: anchor === 'top' || anchor === 'bottom',
      })}
      role="presentation"
      onClick={toggleDrawer(anchor, false)}
      onKeyDown={toggleDrawer(anchor, false)}
    >
      <List>
        {['Inbox', 'Starred', 'Send email', 'Drafts'].map((text, index) => (
          <ListItem button key={text}>
            <ListItemIcon>{index % 2 === 0 ? <InboxIcon /> : <MailIcon />}</ListItemIcon>
            <ListItemText primary={text} />
          </ListItem>
        ))}
      </List>
      <Divider />
      <List>
        {['All mail', 'Trash', 'Spam'].map((text, index) => (
          <ListItem button key={text}>
            <ListItemIcon>{index % 2 === 0 ? <InboxIcon /> : <MailIcon />}</ListItemIcon>
            <ListItemText primary={text} />
          </ListItem>
        ))}
      </List>
    </div>
  );

  return (
    <div>
      {[ 'bottom'].map((anchor) => (
        <React.Fragment key={anchor}>
          <Button fullWidth className={classes.buttonDrawer}   onClick={toggleDrawer(anchor, true)}><KeyboardArrowUpIcon/></Button>
          <SwipeableDrawer
            anchor={anchor}
            open={state[anchor]}
            onClose={toggleDrawer(anchor, false)}
            onOpen={toggleDrawer(anchor, true)}
          >
             <Button fullWidth    onClick={toggleDrawer(anchor, false)}><KeyboardArrowDownIcon/></Button>
            {list(anchor)}
          </SwipeableDrawer>
        </React.Fragment>
      ))}
    </div>
  );
}

sandBox here
this is based on material ui demo sandbox and the style is, of course, completely customizable ;-)

like image 42
antoineso Avatar answered Oct 30 '25 18:10

antoineso



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!