Skip to content

Svelte slot name cannot be dynamic #7000

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

Closed
Mrbeyond opened this issue Dec 8, 2021 · 1 comment
Closed

Svelte slot name cannot be dynamic #7000

Mrbeyond opened this issue Dec 8, 2021 · 1 comment

Comments

@Mrbeyond
Copy link

Mrbeyond commented Dec 8, 2021

Describe the problem

I was trying to componentize a data table in my project and I wanted to include custom features that
are not just ordinary text but with the likes of menu icon, buttons, delete icon etc. For reusability it has to be
dynamic using named slots.

The REPL link is:
https://svelte.dev/repl/4bdd5fc5f12a41fc8ec51129c8015be4?version=3.44.2

This code sample is shown below:

Table.svelte COMPONENT

<script> let headers = [{name:"usa", value:"text"},{slot: true, name:"canada", value:"num"},]; let data= [{text:"one", num:1},{text:"two", num:2},{text:"three", num:3},] </script> {#each headers as item} {/each} {#each data as row,i (i)} {#each headers as item} {#if item.slot} {:else} {/if} {/each} {/each}
{item.name}
**** {row[item.value]}

App.svelte COMPONENT

<script> import Table from './Table.svelte'; </script> {payload.num}
<style> .btn { background-color: #ff3e00; color: white; padding-left: 14px; padding-right: 14px; } </style>

Describe the proposed solution

I would like the dynamic slot name to be enabled like :

 <td>
          **<slot name="{item.name}" payload={row}></slot>**
        </td>

Alternatives considered

For now, I have to declare the name explicitly which makes it not dynamic again.

Importance

would make my life easier

@Conduitry
Copy link
Member

Duplicate of #6493.

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

2 participants