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

Persist resize pane width on reload (Feature request) #795

Open
abhishekmg opened this issue Apr 16, 2024 · 3 comments
Open

Persist resize pane width on reload (Feature request) #795

abhishekmg opened this issue Apr 16, 2024 · 3 comments

Comments

@abhishekmg
Copy link

When the changes the width of a pane and then refreshes the changes width needs to persist

current behaviour

Screen.Recording.2024-04-16.at.1.27.00.PM.mov
@vimalsharma124
Copy link

I'm searching similar

@vimalsharma124
Copy link

vimalsharma124 commented May 9, 2024

@AruhaMaeda
Copy link

You can achieve it using local storage.

Here is the sample code.

import { Allotment } from "allotment"

const LOCAL_STORAGE_KEY = "splitSizes"
let initialSizes = [500, 500, 500]
if (typeof window !== "undefined") {
  const savedSizes = localStorage.getItem(LOCAL_STORAGE_KEY)
  if (savedSizes) {
    initialSizes = JSON.parse(savedSizes)
  }
}

function Test() {
  return (
    <>
      <Allotment
        defaultSizes={initialSizes}
        onDragEnd={(sizes) => {
          if (typeof window !== "undefined") {
            localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(sizes))
          }
        }}
      >
        <div>First</div>
        <div>Second</div>
        <div>Third</div>
      </Allotment>
    </>
  )
}
export default Test

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

3 participants