How to best implement a resizable widget #941
|
Thanks for the awesome library! I was wondering about the output DOM element, the In So my plan is to instead use another container to implement the sizing. But for certain things to work, the output element (the |
Replies: 1 comment 2 replies
|
Great question! The short answer is: you can't make many assumptions about
This means things like What I'd recommend: treat function render({ model, el }) {
const container = document.createElement("div");
container.style.position = "relative";
// ... all your sizing/resizing logic on `container`
el.appendChild(container);
return () => {
// can cleanup any listeners if necessary
}
}This way you own the full styling context and aren't at the mercy of what each platform does (or undoes) to |

Great question! The short answer is: you can't make many assumptions about
elbeyond it being anHTMLElement.elis not created or managed by anywidget. It's provided by the host platform (Jupyter Notebook, JupyterLab, VS Code, marimo, Colab, etc.). Each platform creates and manages that element differently, so anywidget intentionally makes no guarantees about its styling, positioning, or behavior beyond the AFM spec, which just says it's anHTMLElementthat represents your widget's display area.This means things like
position,display, sizing behavior, and whether inline styles get reset are all platform-specific. The behavior you're seeing (VS Code resetting certain inline styles) is a…