-
Notifications
You must be signed in to change notification settings - Fork 63
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
Dynamic Tab creation doesn't work #474
Comments
Looking through the code, this may not be easily fixable with the current approach (lookup child nodes on first component mount and install relevant DOM event handlers). Still worth putting it out there I guess. |
Ok so I made a crude workaround using svelte's <script lang="ts">
import { Tabs, Stack, Button } from "@svelteuidev/core";
let tabsContent: number[] = [1, 2, 3];
let active: number = 0;
</script>
<Stack>
<Button on:click={() => (tabsContent = [...tabsContent, tabsContent.length + 1])}>Add tab</Button>
{#key tabsContent}
<Tabs {active} on:change={(e) => (active = e.detail.index)}>
{#each tabsContent as tab}
<Tabs.Tab label={tab}>Content: {tab}</Tabs.Tab>
{/each}
</Tabs>
{/key}
</Stack> Note that direct binding Not sure if this is helpful for enhancing the library, but if anyone stumbles on this issue and is looking for a quick-and-dirty workaround. |
Not a priority for right now, but definitely something to be improved, thank you! |
thanks for your solution |
What package has an issue
@svelteuidev/core
A clear and concise description of what the bug is
Trying to create Tabs dynamically doesn't work as expected. In particular, the newly added tab can't be selected with a mouse click, and navigating into it with arrow keys renders tab's content in the header.
In which browser(s) did the problem occur?
Brave (Chromium), Firefox
Steps To Reproduce
Here's the MRE:
When the code above is rendered, the first 3 tabs created initially are working OK, I can switch between them and see
Content: N
. However, while pressing theAdd tab
button renders the 4th added tab as expected, I can't click on it. If I navigate into it with arrow keys, the tab's content is rendered inside the tab label (see screenshot)Do you know how to fix the issue
No
Are you willing to participate in fixing this issue and create a pull request with the fix
Yes
Relevant Assets
No response
The text was updated successfully, but these errors were encountered: