8000 newly added item in small breakpoint layout shrinks in the bigger breakpoint layout · Issue #2110 · react-grid-layout/react-grid-layout · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

newly added item in small breakpoint layout shrinks in the bigger breakpoint layout #2110

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

Open
akshay-developer-2021 opened this issue Jan 1, 2025 · 3 comments

Comments

@akshay-developer-2021
Copy link

Describe the bug

I have a responsive dashboard, which allows users to add/remove widgets as well. I am saving the layouts in db.

When md breakpoint is active, I add a new item ( by just pushing a div with key and data-grid prop on it ), the onLayoutChange gets triggered I save the values of the second arg in db ( i.e. all layouts keyed by breakpoints )

However, when I start to increase the screen size, the newly added item shrinks because for bigger breakpoint the layout is not defined.

If we try the opposite, i.e. add a new item in the xl mode and then reduce the screen size everything works fine.

Your Example Website or App

https://codesandbox.io/p/sandbox/g6npg3

Steps to Reproduce the Bug or Issue

the example attached do not add/remove items but simulates the same problem. the layout for "2" is defined in md so it breaks in the lg.

  1. codesandbox -> https://codesandbox.io/p/sandbox/g6npg3
  2. increase/decrease the preview pane size

Expected behavior

it should either remain the same size or increase but definitely not shrink.

react-grid-layout library version

1.5.0

Operating System Version

macOS 14.4

Browser

Chrome

Additional context

No response

Screenshots or Videos

RGL.tsx.nodebox.CodeSandbox.-.2.January.2025.mp4
@Nitrammets
Copy link

Did you find a solution for this?

@akshay-developer-2021
Copy link
Author

@Nitrammets not yet.

@akshay-developer-2021
Copy link
Author
akshay-developer-2021 commented Jan 14, 2025

implemented a custom solution to generate the layout in all breakpoints.

const getLayoutForNewItem = ({
  inputParam,
  currentLayouts,
  currentCols,
}: {
  inputParam: NewItemInputParams;
  currentLayouts?: Layout[];
  currentCols: number;
}) => {
  const { key, width = 6, height = 6 } = inputParam;
  const _defaultReturn = {
    x: 0,
    y: 0,
    w: Math.min(width, currentCols),
    h: height,
    i: key,
  };

  const sortedLayout = currentLayouts?.sort((a, b) => {
    if (b.y !== a.y) {
      return b.y - a.y;
    }
    return b.x - a.x;
  });

  const _lastItem = sortedLayout?.[0];

  if (_lastItem && currentCols) {
    const leftX = _lastItem.x + _lastItem.w;
    const rightX = leftX + width;
    if (rightX > currentCols) {
      return { ..._defaultReturn, y: _lastItem.y + _lastItem.h };
    }
    return {
      i: key,
      w: width,
      x: leftX,
      y: _lastItem.y,
      h: height,
    };
  }
  return _defaultReturn;
};

this can be called for each breakpoint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0