Open metaboulie opened 1 week ago
This is because you are adding the styles outside of the widget: document.head.appendChild(style);
.
We use shadow-doms with widgets so they don't pollute the global css space, which Jupyter does not.
There is a _css
field on the widget that you should use for styles.
Feel free to re-open if there are other issues
I've moved the css to _css
, however, the annotation action -- select a range of words, click one of the buttons below doesn't work
Looks like an issue with getSelection
. I don't think ShadowRoots support selection consistently today in browsers. Each browser seems to implement it their own way:
https://stackoverflow.com/questions/62054839/shadowroot-getselection
The state of affairs as of Dec 2023:
ShadowRoot.getSelection is a non-standard API.
Selection.getComposedRanges is a standards proposal to support selection with Shadow DOM.
On Chromium, calling document.getSelection will not pierce into the Shadow DOM and gives you some unhelpful high-level element. But it does expose the non-standard getSelection method on the ShadowRoot.
On Firefox, it does not implement ShadowRoot.getSelection, but document.getSelection will pierce through shadow dom and give you the exact element.
On Safari, Selection.getComposedRanges is supported as of v17. On versions before that, ShadowRoot.getSelection is not supported and apparently document.getSelection does not pierce the Shadow DOM, meaning you are just out of luck.
@metaboulie i can leave this open to track for now. others may be able to post workarounds
Describe the bug
Colab link of this anywidget
Here is a comparison of an
anywidget
I built in Jupyter and marimo.Jupyter
marimo
The main reason may be that the html styles are not read and rendered correctly in marimo.
Environment
Code to reproduce