Skip to content

Commit

Permalink
Features/7435 multipletext titlewidth (#7474)
Browse files Browse the repository at this point in the history
* Add titleWidth property into multipletext #7435

* Add visual regression test #7435
  • Loading branch information
andrewtelnov authored Dec 8, 2023
1 parent c90aa0e commit f6cc002
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<ng-container *ngIf="!model.isErrorsCell">
<label [class]="question.getItemLabelCss(item)">
<span [class]="question.getItemTitleCss()">
<span [class]="question.getItemTitleCss()" [style]="{ minWidth: question.titleWidth, width: question.titleWidth }">
<span *ngIf=" item.editor.isRequireTextBeforeTitle || item.editor.isRequireTextOnStart"
[class]="question.cssClasses.requiredText">{{ item.editor.requiredText }}</span>
<sv-ng-string [model]="item.locTitle"></sv-ng-string>
Expand Down
2 changes: 1 addition & 1 deletion packages/survey-vue3-ui/src/MultipletextItem.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<label v-if="!cell.isErrorsCell" :class="question.getItemLabelCss(item)">
<span :class="question.getItemTitleCss()">
<span :class="question.getItemTitleCss()" :style="{ minWidth: question.titleWidth, width: question.titleWidth }">
<span
v-if="
item.editor.isRequireTextBeforeTitle ||
Expand Down
2 changes: 1 addition & 1 deletion src/knockout/templates/question-multipletext.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<td data-bind="css: cell.className">
<!-- ko ifnot: cell.isErrorsCell -->
<label data-bind="css: question.getItemLabelCss(item)">
<span data-bind="css: question.koItemTitleCss">
<span data-bind="css: question.koItemTitleCss, style: { minWidth: question.titleWidth, width: question.titleWidth }">
<!-- ko component: { name: 'survey-element-title-content', params: {element: cell.item.editor} } --><!-- /ko -->
</span>
<div data-bind="css: question.koItemCss, event: {focusin: cell.item.focusIn }">
Expand Down
12 changes: 11 additions & 1 deletion src/question_multipletext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,15 @@ export class QuestionMultipleTextModel extends Question
public set itemSize(val: number) {
this.setPropertyValue("itemSize", val);
}
/**
* A width for item. Accepts CSS values.
*/
public get titleWidth(): string {
return this.getPropertyValue("titleWidth") || "";
}
public set titleWidth(val: string) {
this.setPropertyValue("titleWidth", val);
}
@propertyArray() rows: Array<MutlipleTextRow>;

protected onRowCreated(row: MutlipleTextRow) {
Expand Down Expand Up @@ -848,7 +857,8 @@ Serializer.addClass(
{ name: "!items:textitems", className: "multipletextitem", isArray: true },
{ name: "itemSize:number", minValue: 0 },
{ name: "colCount:number", default: 1, choices: [1, 2, 3, 4, 5] },
{ name: "itemErrorLocation", default: "default", choices: ["default", "top", "bottom"], visible: false }
{ name: "itemErrorLocation", default: "default", choices: ["default", "top", "bottom"], visible: false },
{ name: "titleWidth", category: "layout" }
],
function () {
return new QuestionMultipleTextModel("");
Expand Down
7 changes: 6 additions & 1 deletion src/react/reactquestion_multipletext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,13 @@ export class SurveyMultipleTextItem extends ReactSurveyElement {
protected renderElement() {
const item = this.item;
const cssClasses = this.cssClasses;
const titleStyle: any = {};
if (!!this.question.titleWidth) {
titleStyle.minWidth = this.question.titleWidth;
titleStyle.width = this.question.titleWidth;
}
return (<label className={this.question.getItemLabelCss(item)}>
<span className={cssClasses.itemTitle}>
<span className={cssClasses.itemTitle} style={titleStyle}>
<TitleContent element={item.editor} cssClasses={item.editor.cssClasses}></TitleContent>
</span>
<SurveyMultipleTextItemEditor
Expand Down
2 changes: 1 addition & 1 deletion src/vue/multipletextitem.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<label v-if="!cell.isErrorsCell" :class="question.getItemLabelCss(item)">
<span :class="question.getItemTitleCss()">
<span :class="question.getItemTitleCss()" :style="{ minWidth: question.titleWidth, width: question.titleWidth }">
<span
v-if="
item.editor.isRequireTextBeforeTitle ||
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions visualRegressionTests/tests/defaultV2/multipletext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,36 @@ frameworks.forEach(framework => {
await takeElementScreenshot("mutlipletext-error-bottom.png", questionRoot, t, comparer);
});
});
test("Check multipletext titleWidth", async (t) => {
await wrapVisualTest(t, async (t, comparer) => {
await t.resizeWindow(1920, 1080);
await initSurvey(framework, {
width: "900px",
questions: [
{
type: "multipletext",
name: "q1",
titleWidth: "400px",
items: [
{
name: "item1",
title: "A very long first item title"
},
{
name: "item2",
title: "A medium long title"
},
{
name: "item3",
title: "Short title"
},
]
},
]
});

const questionRoot = Selector(".sd-question");
await takeElementScreenshot("mutlipletext-titlewidth.png", questionRoot, t, comparer);
});
});
});

0 comments on commit f6cc002

Please sign in to comment.