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

Unexpected behaviour with dynamic tabs #28

Closed
Bergamof opened this issue Jan 19, 2022 · 2 comments
Closed

Unexpected behaviour with dynamic tabs #28

Bergamof opened this issue Jan 19, 2022 · 2 comments

Comments

@Bergamof
Copy link

I need to implement a tab system like this

<script lang="ts">
    import Tabs from "spaper/components/Tabs/Tabs.svelte";
    import Tab from "spaper/components/Tabs/Tab.svelte";

    let tabs = [{id: 0}];
    let i = 0;

    function addTab() {
        tabs = [...tabs, {id: ++i}]
    }
</script>
<Tabs>
    {#each tabs as tab}
        <Tab label={tab.id}>
            {tab.id}
        </Tab>
    {/each}
    <Tab label="Add">
        <button on:click={addTab}>Click</button>
    </Tab>
</Tabs>

If at first, there is no problem, the newly created tabs are not placed as expected. I won't try an explanation, testing the snippet should be sufficient to understand.

Tried with Sveltekit, not with Svelte, but I don't think that makes a difference

@Oli8
Copy link
Owner

Oli8 commented Jan 20, 2022

Hey, unfortunately I have no way to quickly fix this. I'll try to look that up when I have more time.
In the meantime maybe you could do something like this :

<Tabs activeTab={1}>
  <Tab label="Add">
    <button on:click={addTab}>Click</button>
  </Tab>
  {#each tabs as tab}
    <Tab label={tab.id}>
      {tab.id}
    </Tab>
  {/each}
</Tabs>

@Bergamof
Copy link
Author

Thanks for the reply
I somehow fixed it by using the "native" way, with html tags.

@Oli8 Oli8 closed this as completed Jan 29, 2022
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