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

feat: ✨ allow to separate tabs #883

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions demo-app/views/AppTabs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const tabListName = 'Liste d’onglet'
const tabTitles = [
{ title: 'Onglet avec accordéon', icon: 'ri-checkbox-circle-line', tabId: 'tab-0', panelId: 'tab-content-0' },
{ title: 'Titre 2', icon: 'ri-checkbox-circle-line', tabId: 'tab-1', panelId: 'tab-content-1' },
{ title: 'Onglet sur la droite', icon: 'ri-close-circle-line', tabId: 'tab-2', panelId: 'tab-content-2' },
]
const selectedTabIndex = ref(0)
const asc = ref(true)
Expand All @@ -30,6 +31,7 @@ function selectTab (idx) {
:tab-list-name="tabListName"
:tab-titles="tabTitles"
:initial-selected-index="initialSelectedIndex"
:expand-at-index="1"
@select-tab="selectTab"
>
<DsfrTabContent
Expand Down Expand Up @@ -84,5 +86,13 @@ function selectTab (idx) {
title="title"
/>
</DsfrTabContent>
<DsfrTabContent
panel-id="tab-content-2"
tab-id="tab-2"
:selected="selectedTabIndex === 2"
:asc="asc"
>
Fermer l'onglet ?
</DsfrTabContent>
</DsfrTabs>
</template>
2 changes: 2 additions & 0 deletions src/components/DsfrTabs/DsfrTabItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type { DsfrTabItemProps }

const props = withDefaults(defineProps<DsfrTabItemProps>(), {
icon: undefined,
expand: false,
})

const emit = defineEmits<{
Expand Down Expand Up @@ -48,6 +49,7 @@ function onKeyDown (event: KeyboardEvent) {
<template>
<li
role="presentation"
:class="props.expand ? 'grow' : ''"
>
<button
:id="tabId"
Expand Down
2 changes: 2 additions & 0 deletions src/components/DsfrTabs/DsfrTabs.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export type DsfrTabItemProps = {
tabId: string
selected?: boolean
icon?: string
expand: boolean
}

export type DsfrTabContentProps = {
Expand All @@ -17,4 +18,5 @@ export type DsfrTabsProps = {
tabTitles: (Partial<DsfrTabItemProps> & { title: string })[]
tabContents?: string[]
initialSelectedIndex?: number
expandAtIndex?: number
}
2 changes: 2 additions & 0 deletions src/components/DsfrTabs/DsfrTabs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const props = withDefaults(defineProps<DsfrTabsProps>(), {
tabContents: () => [],
tabTitles: () => [],
initialSelectedIndex: 0,
expandAtIndex: -1,
})

const emit = defineEmits<{ (e: 'selectTab', payload: number): void }>()
Expand Down Expand Up @@ -134,6 +135,7 @@ defineExpose({
:panel-id="tabTitle.panelId || `${getIdFromIndex(index)}-panel`"
:tab-id="tabTitle.tabId || getIdFromIndex(index)"
:selected="isSelected(index)"
:expand="index - 1 === props.expandAtIndex"
@click="selectIndex(index)"
@next="selectNext()"
@previous="selectPrevious()"
Expand Down
Loading