What is the best way to programmically resize a component in goldenlayout 2?

Author: foobarbecueCreated Jan 17, 2026Updated Jan 18, 2026

I want to resize a component at runtime. Specifically, I'm adding collapse / expand buttons to the header. I've managed to hack together something that kind of works but wonder if there's a better way.

To get the stack:

import { GoldenLayout } from "https://esm.sh/[email protected]";
const goldenLayout = new GoldenLayout(containerElement);
...
        goldenLayout.on('stackCreated', (event) => {
            const stack = event.target;
            addCollapseButton(stack);
        });

And then addCollapseButton sets up a click handler that has this in it:

stack.size = newSize
goldenLayout.updateSize()

That works, but is that the right way to do it? I haven't figured out the "restore to original size" part yet. Not sure if the original configured size is still in there or if I destroyed that info.

Source: golden-layout/golden-layout