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

Fixed #9032 - Advanced header. The text should use a container's width as max-width when text-width property's value is 0px #9033

Closed
wants to merge 3 commits 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
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
<ng-template [component]="{ name: model.survey.getElementWrapperComponentName(model.survey, 'logo-image'), data: { data: model.survey.getElementWrapperComponentData(model.survey, 'logo-image') } }"></ng-template>
</div>
</div>
<div *ngIf="model.showTitle" class="sv-header__title" [style]="{ maxWidth: model.textAreaWidth }">
<div *ngIf="model.showTitle" class="sv-header__title" [style]="{ maxWidth: model.renderedtextAreaWidth }">
<sv-ng-element-title [element]="model.survey"></sv-ng-element-title>
</div>
<div *ngIf="model.showDescription" class="sv-header__description" [style]="{ maxWidth: model.textAreaWidth }">
<div *ngIf="model.showDescription" class="sv-header__description" [style]="{ maxWidth: model.renderedtextAreaWidth }">
<div *ngIf="model.survey.renderedHasDescription" [class]="model.survey.css.description" [model]="model.survey.locDescription" sv-ng-string></div>
</div>
</div>
Expand Down
15 changes: 14 additions & 1 deletion packages/survey-core/src/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ export class CoverCell {
get textAreaWidth(): string {
return this.cover.renderedTextAreaWidth;
}
get renderedtextAreaWidth(): string {
return this.cover.renderedTextAreaWidth;
}
}

export class Cover extends Base {
Expand Down Expand Up @@ -181,8 +184,18 @@ export class Cover extends Base {
}
return undefined;
}

public get renderedTextAreaWidth(): string {
return this.textAreaWidth ? this.textAreaWidth + "px" : undefined;
if (this.textAreaWidth) {
return this.textAreaWidth + "px";
}
if (this.survey && this.survey.width) {
return this.survey.width;
}
// if (this.survey.responsiveStartWidth) {
// return this.survey.responsiveStartWidth + "px";
// }
return "100%";
}
public get isEmpty(): boolean {
return !this.survey.hasLogo && !this.survey.hasTitle && !this.survey.renderedHasDescription;
Expand Down
24 changes: 21 additions & 3 deletions packages/survey-core/tests/headerTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ QUnit.test("cell calculations - test width",
function (assert) {
const cover = new Cover();

assert.equal(cover.cells[0].textAreaWidth, undefined, "default");
assert.equal(cover.cells[0].textAreaWidth, undefined, "equal to cover + px");
assert.equal(cover.textAreaWidth, 0, "default");
assert.equal(cover.cells[0].textAreaWidth, "100%", "equal to cover textAreaWidth");

cover.textAreaWidth = 120;
assert.equal(cover.textAreaWidth, 120, "cover text width");
Expand Down Expand Up @@ -304,4 +304,22 @@ QUnit.test("calculateActualHeight mobile",
cover.actualHeight = 0;
assert.equal(cover.renderedHeight, "100px", "mobile height, no title, no logo, no description");
}
);
);

QUnit.test("renderedTextAreaWidth",
function (assert) {
const cover = new Cover();
cover.survey = {
width: undefined,
onPropertyChanged: { add: () => { } },
calculateWidthMode: () => { }
} as any;
assert.equal(cover.renderedTextAreaWidth, "100%", "default text area width");
cover.textAreaWidth = 300;
assert.equal(cover.renderedTextAreaWidth, "300px", "given text area width");
cover.textAreaWidth = 0;
assert.equal(cover.renderedTextAreaWidth, "100%", "full width text area width");
cover.survey.width = "400px";
assert.equal(cover.renderedTextAreaWidth, "400px", "text area width from survey");
}
);
5 changes: 3 additions & 2 deletions packages/survey-react-ui/src/components/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export class HeaderMobile extends React.Component<any, any> {
{this.renderLogoImage()}
</div>) : null}
{this.model.survey.hasTitle ? (<div className="sv-header__title" style={{ maxWidth: this.model.renderedTextAreaWidth }}>

{/* {ReactElementFactory.Instance.createElement("survey-element-title", { element: this.model.survey })} */}
<TitleElement element={this.model.survey} />
</div>) : null}
Expand Down Expand Up @@ -69,11 +70,11 @@ export class HeaderCell extends React.Component<any, any> {
{this.model.showLogo ? (<div className="sv-header__logo">
{this.renderLogoImage()}
</div>) : null}
{this.model.showTitle ? (<div className="sv-header__title" style={{ maxWidth: this.model.textAreaWidth }}>
{this.model.showTitle ? (<div className="sv-header__title" style={{ maxWidth: this.model.renderedtextAreaWidth }}>
{/* {ReactElementFactory.Instance.createElement("survey-element-title", { element: this.model.survey })} */}
<TitleElement element={this.model.survey} />
</div>) : null}
{this.model.showDescription ? (<div className="sv-header__description" style={{ maxWidth: this.model.textAreaWidth }}>
{this.model.showDescription ? (<div className="sv-header__description" style={{ maxWidth: this.model.renderedtextAreaWidth }}>
<div className={this.model.survey.css.description}>
{SurveyElementBase.renderLocString(this.model.survey.locDescription)}
</div>
Expand Down
4 changes: 2 additions & 2 deletions packages/survey-vue3-ui/src/components/header/HeaderCell.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<div
v-if="model.showTitle"
class="sv-header__title"
:style="{ maxWidth: model.textAreaWidth }"
:style="{ maxWidth: model.renderedtextAreaWidth }"
>
<SvComponent
:is="'survey-element-title'"
Expand All @@ -27,7 +27,7 @@
<div
v-if="model.showDescription"
class="sv-header__description"
:style="{ maxWidth: model.textAreaWidth }"
:style="{ maxWidth: model.renderedtextAreaWidth }"
>
<div
v-if="model.survey.renderedHasDescription"
Expand Down