Skip to content

feat: make <svelte:option> customElement configuration's tag property optional (#12751) #12754

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

Theo-Steiner
Copy link
Contributor

@Theo-Steiner Theo-Steiner commented Aug 6, 2024

problem

As described in #12751, there are cases when users might want to use the advanced custom element configuration by <svelte:option customElement={...}> and still have control over when and how the custom element is defined with the customElements registry.

recap:

there are currently three possible options to set the tag name of a custom element in svelte

  1. As a string value set to customElement: <svelte:options customElement="my-element" />
  2. As a string value set to customElement.tag: <svelte:options customElement="{tag: 'my-element'}" />
  3. Not setting it at all using <svelte:options />, but instead using customElements.define('my-element', MyElement.element);

fix: making tag optional in the configuration object as well

this PR makes it so that the tag property of the customElement configuration object now too is optional.
If a tag name is set, the element is registered automatically. If not, registering the element is left to the user.
This basically mirrors the behavior of how the non-object variant of customElement works

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests and linting

  • Run the tests with pnpm test and lint the project with pnpm lint

Copy link

changeset-bot bot commented Aug 6, 2024

🦋 Changeset detected

Latest commit: dfbeb21

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Rich-Harris Rich-Harris merged commit 7ae21ea into sveltejs:main Aug 11, 2024
7 of 9 checks passed
@Rich-Harris
Copy link
Member

thanks!

dummdidumm added a commit that referenced this pull request Sep 9, 2024
Was missing from #12754 where we made the tag optional

fixes #13161
dummdidumm added a commit that referenced this pull request Sep 9, 2024
Was missing from #12754 where we made the tag optional

fixes #13161
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants