Skip to content

Commit 013b47d

Browse files
committed
SVY-20614 Accordion adding many tabs results in increase of the height
and the forms in the tabs are not seen Add scrollable functionality to accordion component
1 parent a60ed74 commit 013b47d

3 files changed

Lines changed: 56 additions & 7 deletions

File tree

components/projects/bootstrapcomponents/src/accordion/accordion.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div ngbAccordion [closeOthers]="true" #element class="bts-accordion" [id]="servoyApi.getMarkupId()" [sabloTabseq]="tabSeq" [sabloTabseqConfig]="{container: true, reservedGap: 50}">
1+
<div ngbAccordion [closeOthers]="true" #element class="bts-accordion svy-accordion-scrollable" [id]="servoyApi.getMarkupId()" [sabloTabseq]="tabSeq" [sabloTabseqConfig]="{container: true, reservedGap: 50}">
22
@for (tab of tabs; track tab; let i = $index) {
33
<div ngbAccordionItem [disabled]="tab.disabled || !tab.containedForm" [id]="tab._id" [collapsed]="getSelectedTabId() !== tab._id">
44
<div ngbAccordionHeader>

components/projects/bootstrapcomponents/src/accordion/accordion.ts

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Component, Renderer2, ViewChild, SimpleChanges, ElementRef, ChangeDetectorRef, ChangeDetectionStrategy } from '@angular/core';
2-
import { WindowRefService } from '@servoy/public';
2+
import { WindowRefService, ServoyPublicService } from '@servoy/public';
33

44
import { ServoyBootstrapBaseTabPanel,Tab } from '../bts_basetabpanel';
55

@@ -13,14 +13,26 @@ export class ServoyBootstrapAccordion extends ServoyBootstrapBaseTabPanel<HTMLDi
1313

1414
@ViewChild('content', { static: false, read: ElementRef}) contentElementRef: ElementRef<HTMLDivElement>;
1515
panelHeight: number;
16+
17+
formHeightMap: { [formName: string]: number } = {};
1618

17-
constructor(renderer: Renderer2,protected cdRef: ChangeDetectorRef, windowRefService: WindowRefService) {
19+
constructor(renderer: Renderer2,protected cdRef: ChangeDetectorRef, windowRefService: WindowRefService, protected servoyPublic: ServoyPublicService) {
1820
super(renderer,cdRef, windowRefService);
1921
}
2022

2123
svyOnChanges( changes: SimpleChanges ) {
22-
if (changes['height'] || changes['tabs']) {
23-
this.updateContentHeight();
24+
if (changes['height'] || changes['tabs'] || changes['tabIndex']) {
25+
const currentTab = this.tabs?.[this.getRealTabIndex()];
26+
const formName = currentTab?.containedForm;
27+
28+
if (formName) {
29+
const cachedHeight = this.formHeightMap[formName];
30+
if (cachedHeight) {
31+
this.updateContentHeight();
32+
} else {
33+
this.getFormState(formName, currentTab, true);
34+
}
35+
}
2436
}
2537
super.svyOnChanges(changes);
2638
}
@@ -31,7 +43,15 @@ export class ServoyBootstrapAccordion extends ServoyBootstrapBaseTabPanel<HTMLDi
3143
}
3244

3345
private updateContentHeight() {
34-
let totalHeight = this.height;
46+
const currentTab = this.tabs?.[this.getRealTabIndex()];
47+
const formName = currentTab?.containedForm;
48+
if (formName && this.formHeightMap[formName]) {
49+
this.panelHeight = this.formHeightMap[formName];
50+
this.cdRef.detectChanges();
51+
return;
52+
}
53+
54+
let totalHeight = typeof this.height === 'string' ? parseInt(this.height, 10) : this.height;
3555
let paneHeight = 49;
3656
let borderWidth = 2;
3757
let wrapper = null;
@@ -46,7 +66,14 @@ export class ServoyBootstrapAccordion extends ServoyBootstrapBaseTabPanel<HTMLDi
4666
if (headerElement){
4767
paneHeight = headerElement.offsetHeight;
4868
}
49-
totalHeight = totalHeight - paneHeight * this.tabs.length - borderWidth ;
69+
70+
if (paneHeight * this.tabs.length + borderWidth + 50 <= totalHeight) {
71+
// If all headers fit, use remaining space
72+
totalHeight = totalHeight - paneHeight * this.tabs.length - borderWidth;
73+
} else {
74+
// Not enough space: show current tab + one extra
75+
totalHeight = totalHeight - (paneHeight * 2) - (borderWidth * 2);
76+
}
5077
}
5178
this.panelHeight = totalHeight;
5279

@@ -72,4 +99,17 @@ export class ServoyBootstrapAccordion extends ServoyBootstrapBaseTabPanel<HTMLDi
7299
tabClicked(tab: Tab,tabIndexClicked: number, event){
73100
this.servoyApi.callServerSideApi('setTabIndexInternal', [tabIndexClicked +1]);
74101
}
102+
103+
private getFormState(form: string, tab: Tab, formWillShow: boolean) {
104+
if (formWillShow) {
105+
this.servoyApi.formWillShow(form, ('relationName' in tab) ? tab.relationName : null).then(() => {
106+
const formCache = this.servoyPublic.getFormCacheByName(form);
107+
if (formCache && formCache.absolute) {
108+
this.formHeightMap[form] = formCache.size.height;
109+
this.panelHeight = this.formHeightMap[form];
110+
this.cdRef.detectChanges();
111+
}
112+
});
113+
}
114+
}
75115
}

components/projects/bootstrapcomponents/svy_bootstrapcomponents.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,15 @@
7575
padding:0px;
7676
}
7777

78+
.bts-accordion .accordion-collapse {
79+
transition: none !important;
80+
}
81+
82+
.svy-accordion-scrollable {
83+
height: 100%;
84+
overflow-y: auto;
85+
}
86+
7887
.svy-wrapper > * > .bts-button {
7988
width: 100%;
8089
height: 100%;

0 commit comments

Comments
 (0)