patricknelson / svelte-retag

Light DOM custom element wrapper for Svelte 3 and 4 with slots, context and Vite HMR support
https://www.npmjs.com/package/svelte-retag
MIT License
39 stars 0 forks source link

Add ability to reflect prop changes back to attributes #43

Open patricknelson opened 9 months ago

patricknelson commented 9 months ago

Describe the problem

Currently it's not possible to reflect prop changes in the custom element attributes.

Describe the proposed solution

Due limitations caused by the fact that svelte-retag isn't able to hook into Svelte compiler options (at least not for now), the developer must first manually enable accessors in their component like so:

<svelte:options accessors />

svelte-retag would then add a new props option (if not already present, see #13) and include a reflect option, e.g.

svelteRetag({
  component: HelloWorld,
  tagname: 'hello-world',
  props: {
    greetPerson: { reflect: true },
  }
});

Once configured, modifications to greetPerson from within the component would be reflected in the greetperson custom element attribute.

Implementation Details

Alternatives considered

None.

Importance

nice to have