unplugin / unplugin-icons

🤹 Access thousands of icons as components on-demand universally.
https://www.npmjs.com/package/unplugin-icons
MIT License
3.66k stars 131 forks source link

fix: Custom Elements - fix crash, add Shadow DOM option #257

Closed developit closed 1 year ago

developit commented 1 year ago

Description

The current Web Components compiler produces an invalid Custom Element. When instantiated via document.createElement('icon-a-b'), it will throw an error: "Failed to construct 'CustomElement': The result must not have children". The recommended solution from the CE spec is to append light DOM children in connectedCallback, so I've made that change here. I've also added a shadow option to have the generated CE use an open Shadow Root instead of light DOM children.

Linked Issues

(none)

Additional context

I made this change via GH web, so it doesn't include any of the TypeScript definition changes for the new options.shadow boolean.