Skip to content

Commit

Permalink
Add panel.hasHeader property #8590
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov committed Jul 20, 2024
1 parent d30f80f commit bb05678
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
15 changes: 13 additions & 2 deletions src/panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1981,6 +1981,9 @@ export class PanelModel extends PanelModelBase implements IElement {
this.registerPropertyChangedHandlers(
["indent", "innerIndent", "rightIndent"], () => { this.onIndentChanged(); });
this.registerPropertyChangedHandlers(["colSpan"], () => { this.parent?.updateColumns(); });
this.registerPropertyChangedHandlers(["title", "description"], () => {
this.calcHasHeader();
});
}
public getType(): string {
return "panel";
Expand All @@ -1994,13 +1997,21 @@ export class PanelModel extends PanelModelBase implements IElement {
}
return super.getSurvey(live);
}
onSurveyLoad() {
public get hasHeader(): boolean {
return this.getPropertyValue("hasHeader");
}
private calcHasHeader(): void {
this.setPropertyValue("hasHeader", this.hasTitle || this.hasDescription && !!this.description);
}
onSurveyLoad(): void {
super.onSurveyLoad();
this.onIndentChanged();
this.calcHasHeader();
}
protected onSetData() {
protected onSetData(): void {
super.onSetData();
this.onIndentChanged();
this.calcHasHeader();
}
public get isPanel(): boolean {
return true;
Expand Down
4 changes: 1 addition & 3 deletions src/react/panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ export class SurveyPanel extends SurveyPanelBase {
);
}
protected renderHeader() {
if (!this.panel.hasTitle && !this.panel.hasDescription) {
return null;
}
if (!this.panel.hasHeader) return null;
return <SurveyElementHeader element={this.panel}></SurveyElementHeader>;
}
protected wrapElement(element: JSX.Element): JSX.Element {
Expand Down
21 changes: 21 additions & 0 deletions tests/paneltests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2872,4 +2872,25 @@ QUnit.test("Check if errors disappered in the closest questions on changing the
q1.value = 1;
assert.equal(q1.errors.length, 0, "q1.errors #3");
assert.equal(q2.errors.length, 0, "q2.errors #3");
});
QUnit.test("Panel hasHeader, Bug#8590", function (assert) {
const survey = new SurveyModel({
elements: [
{ type: "panel", name: "panel1" },
{ type: "panel", name: "panel2", title: "Panel 2" },
{ type: "panel", name: "panel3", description: "Panel 3" }
]
});
const panel1 = survey.getPanelByName("panel1");
const panel2 = survey.getPanelByName("panel2");
const panel3 = survey.getPanelByName("panel3");
assert.equal(panel1.hasHeader, false, "panel1 #1");
assert.equal(panel2.hasHeader, true, "panel2 #1");
assert.equal(panel3.hasHeader, true, "panel3 #1");
panel1.title = "Panel 1";
assert.equal(panel1.hasHeader, true, "panel1 #2");
panel2.title = "";
assert.equal(panel2.hasHeader, false, "panel2 #2");
panel3.description = "";
assert.equal(panel3.hasHeader, false, "panel3 #2");
});

0 comments on commit bb05678

Please sign in to comment.