-
-
Notifications
You must be signed in to change notification settings - Fork 425
Expand file tree
/
Copy pathPanel.vue
More file actions
33 lines (28 loc) · 902 Bytes
/
Panel.vue
File metadata and controls
33 lines (28 loc) · 902 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<script setup lang="ts">
defineOptions({ name: 'TabPanel' })
const props = defineProps<{
value: string
panelId?: string
}>()
const selected = inject<WritableComputedRef<string>>('tabs-selected')
const getTabId = inject<(value: string) => string>('tabs-tab-id')
const getPanelId = inject<(value: string) => string>('tabs-panel-id')
if (!selected || !getTabId || !getPanelId) {
throw new Error('TabPanel must be used inside a TabRoot component')
}
const isSelected = computed(() => selected.value === props.value)
const resolvedPanelId = computed(() => props.panelId ?? getPanelId(props.value))
const resolvedTabId = computed(() => getTabId(props.value))
</script>
<template>
<div
v-if="isSelected"
:id="resolvedPanelId"
role="tabpanel"
:aria-labelledby="resolvedTabId"
:data-selected="isSelected ? '' : undefined"
:tabindex="0"
>
<slot />
</div>
</template>