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

Bug/8590 panel title rendering #8599

Merged
merged 2 commits into from
Jul 22, 2024
Merged
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
17 changes: 14 additions & 3 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"], () => {
this.calcHasTextInTitle();
});
}
public getType(): string {
return "panel";
Expand All @@ -1994,13 +1997,21 @@ export class PanelModel extends PanelModelBase implements IElement {
}
return super.getSurvey(live);
}
onSurveyLoad() {
get hasTextInTitle(): boolean {
return this.getPropertyValue("hasTextInTitle");
}
private calcHasTextInTitle(): void {
this.setPropertyValue("hasTextInTitle", !!this.title);
}
onSurveyLoad(): void {
super.onSurveyLoad();
this.onIndentChanged();
this.calcHasTextInTitle();
}
protected onSetData() {
protected onSetData(): void {
super.onSetData();
this.onIndentChanged();
this.calcHasTextInTitle();
}
public get isPanel(): boolean {
return true;
Expand Down Expand Up @@ -2247,7 +2258,7 @@ export class PanelModel extends PanelModelBase implements IElement {
public get cssTitle(): string {
return new CssClassBuilder()
.append(this.getCssTitle(this.cssClasses.panel))
.append(this.cssClasses.panel.titleHidden, !this.title && this.isDesignMode)
.append(this.cssClasses.panel.titleHidden, !this.hasTextInTitle && this.isDesignMode)
.toString();
}
public get showErrorsAbovePanel(): boolean {
Expand Down
16 changes: 16 additions & 0 deletions tests/paneltests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2872,4 +2872,20 @@ 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 hasTextInTitle - reactive property, Bug:https://github.com/surveyjs/survey-creator/issues/5720", function (assert) {
const survey = new SurveyModel({
elements: [
{ type: "panel", name: "panel1" },
{ type: "panel", name: "panel2", title: "Panel 2" }
]
});
const panel1 = survey.getPanelByName("panel1");
const panel2 = survey.getPanelByName("panel2");
assert.equal(panel1.hasTextInTitle, false, "panel1 #1");
assert.equal(panel2.hasTextInTitle, true, "panel2 #1");
panel1.title = "Panel 1";
assert.equal(panel1.hasTextInTitle, true, "panel1 #2");
panel2.title = "";
assert.equal(panel2.hasTextInTitle, false, "panel2 #2");
});
Loading