Skip to content

Commit 6c0d13b

Browse files
chore: Use ResizeObserver to keep tab-height synced to tab-content
1 parent 7b87b0c commit 6c0d13b

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/components/DsfrTabs/DsfrTabs.stories.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,5 +253,6 @@ OngletsAvecAccordeon.args = {
253253
initialSelectedIndex: 0,
254254
title1: 'Un titre d’accordéon 1',
255255
title2: 'Un titre d’accordéon 2',
256+
title3: 'Un titre d’accordéon 3',
256257
expandedId: '',
257258
}

src/components/DsfrTabs/DsfrTabs.vue

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,34 @@ export default defineComponent({
4444
selectedIndex: this.initialSelectedIndex || 0,
4545
generatedIds: {},
4646
asc: true,
47+
resizeObserver: null,
4748
}
4849
},
4950
5051
mounted () {
51-
this.renderTabs()
52+
/*
53+
* Need to use a resize-observer as tab-content height can
54+
* change according to its inner components.
55+
*/
56+
if (window.ResizeObserver) {
57+
this.resizeObserver = new window.ResizeObserver(() => {
58+
this.renderTabs()
59+
})
60+
}
61+
62+
this.$el.querySelectorAll('.fr-tabs__panel').forEach((element) => {
63+
if (element) {
64+
this.resizeObserver?.observe(element)
65+
}
66+
})
67+
},
68+
69+
unmounted () {
70+
this.$el.querySelectorAll('.fr-tabs__panel').forEach((element) => {
71+
if (element) {
72+
this.resizeObserver?.unobserve(element)
73+
}
74+
})
5275
},
5376
5477
methods: {
@@ -67,8 +90,6 @@ export default defineComponent({
6790
this.asc = idx > this.selectedIndex
6891
this.selectedIndex = idx
6992
this.$emit('select-tab', idx)
70-
await this.$nextTick()
71-
this.renderTabs()
7293
},
7394
async selectPrevious () {
7495
const newIndex = this.selectedIndex === 0 ? this.tabTitles.length - 1 : this.selectedIndex - 1

0 commit comments

Comments
 (0)