From 45dfbb26cfeb97c58a0da813e96a137e23dfe548 Mon Sep 17 00:00:00 2001 From: Eric Liu Date: Mon, 30 Nov 2020 11:31:48 -0800 Subject: [PATCH] docs(tabs): add dynamic example --- docs/src/pages/components/Tabs.svx | 8 +++ docs/src/pages/framed/Tabs/TabsDynamic.svelte | 65 +++++++++++++++---- 2 files changed, 61 insertions(+), 12 deletions(-) diff --git a/docs/src/pages/components/Tabs.svx b/docs/src/pages/components/Tabs.svx index 19f1e72f..bf6340f7 100644 --- a/docs/src/pages/components/Tabs.svx +++ b/docs/src/pages/components/Tabs.svx @@ -33,6 +33,14 @@ components: ["Tabs", "Tab", "TabContent", "TabsSkeleton"] +### Re-rendering tabs + +Use the [`#key` block](https://svelte.dev/docs#key) to dynamically update tab items or content. + +The example below shows tabs and the bound `selected` index being programmatically updated. + + + ### Skeleton \ No newline at end of file diff --git a/docs/src/pages/framed/Tabs/TabsDynamic.svelte b/docs/src/pages/framed/Tabs/TabsDynamic.svelte index 59344d8d..7af795c3 100644 --- a/docs/src/pages/framed/Tabs/TabsDynamic.svelte +++ b/docs/src/pages/framed/Tabs/TabsDynamic.svelte @@ -1,5 +1,12 @@ + + {#key tabs} {#each tabs as tab (tab.title)} @@ -37,6 +50,34 @@

Selected index: {selected}

-{#each tabs as { title } (title)} - -{/each} +
+ + {#each tabs as { title } (title)} + + {/each} + +
+ +
+ +