From bab9e9d1497322a52e37ddc6444d26c5d951575f Mon Sep 17 00:00:00 2001 From: Benjamin Canac Date: Thu, 3 Aug 2023 11:52:49 +0200 Subject: [PATCH] feat(Tabs): control selected index --- .../content/examples/TabsExampleChange.vue | 22 ++++++ .../content/examples/TabsExampleVModel.vue | 34 +++++++++ docs/content/5.navigation/4.tabs.md | 72 +++++++++++++++++++ src/runtime/components/navigation/Tabs.vue | 42 +++++++++-- 4 files changed, 165 insertions(+), 5 deletions(-) create mode 100644 docs/components/content/examples/TabsExampleChange.vue create mode 100644 docs/components/content/examples/TabsExampleVModel.vue diff --git a/docs/components/content/examples/TabsExampleChange.vue b/docs/components/content/examples/TabsExampleChange.vue new file mode 100644 index 0000000000..751e7741f0 --- /dev/null +++ b/docs/components/content/examples/TabsExampleChange.vue @@ -0,0 +1,22 @@ + + + diff --git a/docs/components/content/examples/TabsExampleVModel.vue b/docs/components/content/examples/TabsExampleVModel.vue new file mode 100644 index 0000000000..aa76745b1d --- /dev/null +++ b/docs/components/content/examples/TabsExampleVModel.vue @@ -0,0 +1,34 @@ + + + diff --git a/docs/content/5.navigation/4.tabs.md b/docs/content/5.navigation/4.tabs.md index 43110faac0..5066c24cbb 100644 --- a/docs/content/5.navigation/4.tabs.md +++ b/docs/content/5.navigation/4.tabs.md @@ -83,6 +83,78 @@ const items = [...] ``` :: +::callout{icon="i-heroicons-exclamation-triangle"} + This will have no effect if you are using a `v-model` to control the selected index. +:: + +### Listen to changes :u-badge{label="Edge" class="ml-2 align-text-bottom !rounded-full" variant="subtle"} + +You can listen to changes by using the `@change` event. The event will emit the index of the selected item. + +::component-example +#default +:tabs-example-change{class="w-full"} + +#code +```vue + + + +``` +:: + +### Control the selected index :u-badge{label="Edge" class="ml-2 align-text-bottom !rounded-full" variant="subtle"} + +Use a `v-model` to control the selected index. + +::component-example +#default +:tabs-example-v-model{class="w-full"} + +#code +```vue + + + +``` +:: + +::callout{icon="i-heroicons-information-circle"} +In this example, we are binding tabs to the route query. Refresh the page to see the selected tab change. +:: + ## Slots You can use slots to customize the buttons and items content of the Accordion. diff --git a/src/runtime/components/navigation/Tabs.vue b/src/runtime/components/navigation/Tabs.vue index 1f3e1df073..b7f8611077 100644 --- a/src/runtime/components/navigation/Tabs.vue +++ b/src/runtime/components/navigation/Tabs.vue @@ -1,6 +1,7 @@