Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dashboardLayout] Support a resizable drawer #4374

Open
prakhargupta1 opened this issue Nov 6, 2024 · 2 comments
Open

[dashboardLayout] Support a resizable drawer #4374

prakhargupta1 opened this issue Nov 6, 2024 · 2 comments
Labels
component: layout This is the name of the generic UI component, not the React module! new feature New feature or request plan: Pro Impact at least one Pro user scope: toolpad-core Abbreviated to "core" waiting for 👍 Waiting for upvotes

Comments

@prakhargupta1
Copy link
Member

prakhargupta1 commented Nov 6, 2024

Currently, we support a sidebarExpandedWidth prop in DashboardLayout. But it remains fixed for the end user. It could be interesting to offer a draggable handle to let them resize it.

Originally posted by @Janpot in #4266 (comment)


Example

https://drag-to-resize-sidebar.vercel.app/

@github-actions github-actions bot added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Nov 6, 2024
@prakhargupta1 prakhargupta1 added scope: toolpad-core Abbreviated to "core" new feature New feature or request waiting for 👍 Waiting for upvotes plan: Pro Impact at least one Pro user and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Nov 6, 2024
@oliviertassinari oliviertassinari added the component: layout This is the name of the generic UI component, not the React module! label Nov 7, 2024
@oliviertassinari oliviertassinari changed the title [core] Support a resizable drawer [toolpad-core] Support a resizable drawer Nov 8, 2024
@prakhargupta1 prakhargupta1 changed the title [toolpad-core] Support a resizable drawer [dashboardLayout] Support a resizable drawer Nov 12, 2024
@kdj309
Copy link

kdj309 commented Mar 13, 2025

Hi @prakhargupta1 I am working on this issue, My Approach is to create a Custom ResizePanel Component and allow the user to resize in bigger view ports

import * as React from 'react';
import Box from '@mui/material/Box';
import { styled } from '@mui/material';

const StyledResizeHandle = styled(Box)(({ theme }) => ({
  position: 'absolute',
  right: -4,
  top: 0,
  bottom: 0,
  width: 8,
  cursor: 'col-resize',
  '&:hover': {
    '&::after': {
      backgroundColor: theme.palette.primary.main,
    },
  },
  '&::after': {
    content: '""',
    position: 'absolute',
    top: 0,
    left: 4,
    width: 1,
    height: '100%',
    backgroundColor: theme.palette.divider,
    transition: theme.transitions.create('background-color'),
  },
}));

export interface ResizeHandleProps {
  onResize: (newWidth: number) => void;
}

export function ResizeHandle({ onResize }: ResizeHandleProps) {
  const handleMouseDown = React.useCallback((event: React.MouseEvent) => {
    const startX = event.clientX;
    const handleMouseMove = (moveEvent: MouseEvent) => {
      const delta = moveEvent.clientX - startX;
      onResize(delta);
    };

    const handleMouseUp = () => {
      document.removeEventListener('mousemove', handleMouseMove);
      document.removeEventListener('mouseup', handleMouseUp);
    };

    document.addEventListener('mousemove', handleMouseMove);
    document.addEventListener('mouseup', handleMouseUp);
  }, [onResize]);

  return <StyledResizeHandle onMouseDown={handleMouseDown} />;
}

And use it on the getDrawerContent Dashboard like this

const handleResize = React.useCallback((delta: number) => {
  setCurrentSidebarWidth((prev) => {
    const newWidth = typeof prev === 'number' ? prev + delta : parseInt(prev, 10) + delta;
    return Math.max(240, Math.min(newWidth, 600)); // Min 240px, max 600px
  });
}, []);

{!isDesktopMini && !disableCollapsibleSidebar && (
  <ResizeHandle onResize={handleResize} />
)}

My question is, do we need to use a library like React-Split for this feature, or do custom components work?
And from a user perspective, it should be optional, so are we keeping it?

waiting for the answers
Thanks and Regards
Kartik Joshi

@kdj309
Copy link

kdj309 commented Mar 16, 2025

Hi @prakhargupta1, I am on this feature, please let me know how to proceed further?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: layout This is the name of the generic UI component, not the React module! new feature New feature or request plan: Pro Impact at least one Pro user scope: toolpad-core Abbreviated to "core" waiting for 👍 Waiting for upvotes
Projects
Status: Backlog
Development

No branches or pull requests

3 participants