Skip to content
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

The "slot" attribute should be allowed to effectively direct descendant of the component #7184

Closed
andirady opened this issue Jan 25, 2022 · 3 comments

Comments

@andirady
Copy link

Describe the bug

Currently the following code would fail to compile with the error ValidationError: Element with a slot='...' attribute must be a child of a component or a descendant of a custom element.

<Input>
  {#if issuer == 'visa' || issuer == 'master'}
    <i slot="icon">{issuer}</i>
  {/if}
</Input>

I believe this should not fail, since the <i> element is effectively direct descendant of the component.

Reproduction

https://svelte.dev/repl/2c8730b239ab48779b6b9666f7ad0508?version=3.46.2

Logs

No response

System Info

Browser: any

Severity

annoyance

@sandipmalla44
Copy link

It only works if you add descendant component outside {#if}.
Example:
<Input>
  <div slot="icon">
  {#if issuer == 'visa' || issuer == 'master'}
    <i>{issuer}</i>
  {/if}
  </div>
</Input>

@dummdidumm
Copy link
Member

Duplicate of #5604

@dummdidumm dummdidumm marked this as a duplicate of #5604 Jan 25, 2022
@andirady
Copy link
Author

It only works if you add descendant component outside {#if}.
Example:
<Input>
  <div slot="icon">
  {#if issuer == 'visa' || issuer == 'master'}
    <i>{issuer}</i>
  {/if}
  </div>
</Input>

The idea is to not have any child element if the issuer is neither visa nor master. Current workaround is to introduce a child element. It's fine for small application, but for enterprise ones, you might end up with too many files. :(

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

No branches or pull requests

3 participants