vrugtehagel / yozo

A custom element library for simple, robust and readable components
https://yozo.ooo
5 stars 0 forks source link

Add built-in support for `ElementInternals` #19

Closed vrugtehagel closed 2 weeks ago

vrugtehagel commented 2 weeks ago

It'd be neat if Yozo automatically attached element internals throught .attachInternals(). Gotta be a bit careful with this one, since old versions of iOS Safari don't have it; probably a polyfill should be recommended in the docs page for it.

It'd be cleanest to expose an internals variable (or $.internals) within <script>, optionally in the template as well. Note that this would be a breaking change, since components that already use .attachInternals() will no longer be able to do so (calling it twice is an error).

Adding this internally has some "security" benefits; if an author wants a closed shadow root, but does not call .attachInternals(), then component users can call it, gaining access to a reference to the shadowRoot, making it essentially open.

If the shadow root is open, then having element internals available is not necessarily a security benefit but probably also not an issue. For consistency it'd be nice either way.

Relevant issue: https://github.com/vrugtehagel/yozo/issues/18

vrugtehagel commented 2 weeks ago

Included in Yozo 0.6.0!