Skip to content

Commit

Permalink
Work for #5282 - If question width is small for text type then changi…
Browse files Browse the repository at this point in the history
…ng input type breaks adaptivity (#5306)

* Work for #5282 - If question width is small for text type then changing input type breaks adaptivity

* Work for #5282 - If question width is small for text type then changing input type breaks adaptivity - fixed vr-test

* Fixed #5282 - If question width is small for text type then changing input type breaks adaptivity

* Fixed typo

* Updated vr-test and etalon

* Fixed #5282 - If question width is small for text type then changing input type breaks adaptivity

* Work for #5282 - If question width is small for text type then changing input type breaks adaptivity - fixed f- and vr- tests

---------

Co-authored-by: tsv2013 <tsv2013@noreply.github.com>
  • Loading branch information
tsv2013 and tsv2013 committed Mar 11, 2024
1 parent ce6fe6c commit 049d235
Show file tree
Hide file tree
Showing 22 changed files with 123 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,8 @@ export class SurveyElementAdornerBase<T extends SurveyElement = SurveyElement> e
this.actionContainer = new SurveyElementActionContainer();
this.actionContainer.dotsItem.iconSize = 16;
this.actionContainer.dotsItem.popupModel.horizontalPosition = "center";
var actions: Array<Action> = [];
this.buildActions(actions);
this.setSurveyElement(surveyElement, false);
if (this.surveyElement) {
this.creator.sidebar.onPropertyChanged.add(this.sidebarFlyoutModeChangedFunc);
this.creator.onElementMenuItemsChanged(this.surveyElement, actions);
this.actionContainer.setItems(actions);
this.updateActionsProperties();
}
this.setSurveyElement(surveyElement);
this.creator.sidebar.onPropertyChanged.add(this.sidebarFlyoutModeChangedFunc);
this.setShowAddQuestionButton(true);
}

Expand All @@ -131,11 +124,17 @@ export class SurveyElementAdornerBase<T extends SurveyElement = SurveyElement> e
surveyElement.onPropertyChanged.add(this.selectedPropPageFunc);
}
}
protected setSurveyElement(surveyElement: T, updateActions: boolean = true): void {
protected setSurveyElement(surveyElement: T): void {
this.detachElement(this.surveyElement);
this.surveyElement = surveyElement;
this.attachElement(this.surveyElement);
if (updateActions) {
if (this.surveyElement) {
var actions: Array<Action> = [];
this.buildActions(actions);
this.creator.onElementMenuItemsChanged(this.surveyElement, actions);
const prevActions = this.actionContainer.actions;
prevActions.forEach(action => action.dispose && action.dispose());
this.actionContainer.setItems(actions);
this.updateActionsProperties();
}
}
Expand Down
8 changes: 4 additions & 4 deletions packages/survey-creator-react/src/ImageItemValueWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ export class ImageItemValueAdornerComponent extends CreatorModelElement<
super(props);
this.rootRef = React.createRef();
}
protected createModel(): void {
protected createModel(props: any): void {
this.model = new ImageItemValueWrapperViewModel(
this.props.componentData.creator,
this.props.question,
this.props.item,
props.componentData.creator,
props.question,
props.item,
null,
null
);
Expand Down
8 changes: 4 additions & 4 deletions packages/survey-creator-react/src/ItemValueWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ export class ItemValueAdornerComponent extends CreatorModelElement<
any
> {
model: ItemValueWrapperViewModel;
protected createModel(): void {
protected createModel(props: any): void {
this.model = new ItemValueWrapperViewModel(
this.props.componentData.creator,
this.props.question,
this.props.item
props.componentData.creator,
props.question,
props.item
);
}
protected getUpdatedModelProps(): string[] {
Expand Down
4 changes: 2 additions & 2 deletions packages/survey-creator-react/src/LogoImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ export class LogoImageComponent extends CreatorModelElement<ILogoImageComponentP
super(props);
this.rootRef = React.createRef();
}
protected createModel(): void {
protected createModel(props: any): void {
let prevRoot: HTMLDivElement = null;
if (!!this.model) {
prevRoot = this.model.root;
}
this.model = new LogoImageViewModel(this.props.data, prevRoot);
this.model = new LogoImageViewModel(props.data, prevRoot);
}
protected getUpdatedModelProps(): string[] {
return ["data"];
Expand Down
9 changes: 7 additions & 2 deletions packages/survey-creator-react/src/MatrixCellWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,20 @@ export class MatrixCellAdornerComponent extends CreatorModelElement<
any
> {
model: MatrixCellWrapperViewModel;
protected createModel(): void {
const data = this.props.componentData;
protected createModel(props: any): void {
const data = props.componentData;
let prevIsSelected = false;
if (!!this.model) {
prevIsSelected = this.model.isSelected;
}
this.model = new MatrixCellWrapperViewModel(
data.creator,
data.element,
data.question,
data.row,
data.column || data.element.cell?.column,
);
this.model.isSelected = prevIsSelected;
}
protected getUpdatedModelProps(): string[] {
return ["componentData"];
Expand Down
23 changes: 13 additions & 10 deletions packages/survey-creator-react/src/ModelElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,24 @@ import { SurveyElementBase } from "survey-react-ui";
export class CreatorModelElement<P, S> extends SurveyElementBase<P, S> {
constructor(props: P) {
super(props);
this.createModel();
this.createModel(props);
}
componentDidUpdate(prevProps: any, prevState: any): void {
super.componentDidUpdate(prevProps, prevState);
if(this.needUpdateModel(prevProps)) {
this.createModel();
shouldComponentUpdate(nextProps: any, nextState: any): boolean {
const result = super.shouldComponentUpdate(nextProps, nextState);
if (result) {
if (this.needUpdateModel(nextProps)) {
this.createModel(nextProps);
}
}
return result;
}
protected createModel(): void {}
protected needUpdateModel(prevProps: any): boolean {
protected createModel(props: any): void { }
protected needUpdateModel(nextProps: any): boolean {
const names = this.getUpdatedModelProps();
if(!Array.isArray(names)) return true;
for(var i = 0; i < names.length; i ++) {
if (!Array.isArray(names)) return true;
for (var i = 0; i < names.length; i++) {
const key = names[i];
if(this.props[key] !== prevProps[key]) return true;
if (this.props[key] !== nextProps[key]) return true;
}
return false;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/survey-creator-react/src/PageNavigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ export class SurveyPageNavigator extends CreatorModelElement<
super(props);
this.containerRef = React.createRef();
}
protected createModel(): void {
protected createModel(props: any): void {
if (this.model) {
this.model.dispose();
}
this.model = new PageNavigatorViewModel(
this.props.pagesController,
this.props.pageEditMode
props.pagesController,
props.pageEditMode
);
}
protected getUpdatedModelProps(): string[] {
Expand Down
4 changes: 2 additions & 2 deletions packages/survey-creator-react/src/Results.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ export class SurveyResults extends CreatorModelElement<
any
> {
model: SurveyResultsModel;
protected createModel(): void {
protected createModel(props: any): void {
if (this.props.survey) {
this.model = new SurveyResultsModel(this.props.survey);
this.model = new SurveyResultsModel(props.survey);
}
}
protected getUpdatedModelProps(): string[] {
Expand Down
4 changes: 2 additions & 2 deletions packages/survey-creator-react/src/StringEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ export class SurveyLocStringEditor extends CreatorModelElement<any, any> {
this.state = { changed: 0 };
this.svStringEditorRef = React.createRef();
}
protected createModel(): void {
protected createModel(props: any): void {
if (this.baseModel) {
this.baseModel.dispose();
}
this.baseModel = new StringEditorViewModelBase(this.locString, this.creator);
this.baseModel = new StringEditorViewModelBase(props.locStr.locStr, props.locStr.creator);
}
protected getUpdatedModelProps(): string[] {
return ["creator", "locString"];
Expand Down
6 changes: 3 additions & 3 deletions packages/survey-creator-react/src/adorners/CellQuestion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ export class CellQuestionAdornerComponent extends CreatorModelElement<
any
> {
model: QuestionAdornerViewModel;
protected createModel(): void {
protected createModel(props: any): void {
this.model = new QuestionAdornerViewModel(
this.props.componentData,
this.props.question,
props.componentData,
props.question,
null
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ export class CellQuestionDropdownAdornerComponent extends CreatorModelElement<
any
> {
model: QuestionAdornerViewModel;
protected createModel(): void {
protected createModel(props: any): void {
this.model = new QuestionAdornerViewModel(
this.props.componentData,
this.props.question,
props.componentData,
props.question,
null
);
}
Expand Down
6 changes: 3 additions & 3 deletions packages/survey-creator-react/src/adorners/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ export class CreatorSurveyPageComponent extends CreatorModelElement<
super(props);
this.rootRef = React.createRef();
}
protected createModel(): void {
protected createModel(props: any): void {
this.model = new PageAdorner(
this.props.creator,
this.props.page
props.creator,
props.page
);
}
protected getUpdatedModelProps(): string[] {
Expand Down
10 changes: 5 additions & 5 deletions packages/survey-creator-react/src/adorners/Question.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ export class QuestionAdornerComponent extends CreatorModelElement<
private modelValue: QuestionAdornerViewModel;
protected rootRef: React.RefObject<HTMLDivElement>;

protected createModel(): void {
protected createModel(props: any): void {
if (this.modelValue) {
this.modelValue.dispose();
}
this.modelValue = this.createQuestionViewModel();
this.modelValue = this.createQuestionViewModel(props);
}
protected createQuestionViewModel(): QuestionAdornerViewModel {
protected createQuestionViewModel(props: any): QuestionAdornerViewModel {
return new QuestionAdornerViewModel(
this.props.componentData,
this.props.question,
props.componentData,
props.question,
null
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ export class QuestionDropdownAdornerComponent extends QuestionAdornerComponent {
constructor(props: QuestionAdornerComponentProps) {
super(props);
}
protected createQuestionViewModel(): QuestionDropdownAdornerViewModel {
protected createQuestionViewModel(props: any): QuestionDropdownAdornerViewModel {
return new QuestionDropdownAdornerViewModel(
this.props.componentData,
this.props.question as QuestionDropdownModel,
props.componentData,
props.question as QuestionDropdownModel,
null
);
}
Expand Down
8 changes: 4 additions & 4 deletions packages/survey-creator-react/src/adorners/QuestionImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ export class QuestionImageAdornerComponent extends QuestionAdornerComponent {
super(props);
this.rootRef = React.createRef();
}
protected createQuestionViewModel(): QuestionAdornerViewModel {
protected createQuestionViewModel(props: any): QuestionAdornerViewModel {
return new QuestionImageAdornerViewModel(
this.props.componentData,
this.props.question as any,
props.componentData,
props.question as any,
null,
null
);
Expand Down Expand Up @@ -58,7 +58,7 @@ export class QuestionImageAdornerComponent extends QuestionAdornerComponent {
</div>);
}
renderChooseButton(): JSX.Element {
return(<div className="svc-image-question-controls">
return (<div className="svc-image-question-controls">
{this.model.allowEdit ? attachKey2click(<span
className="svc-context-button"
onClick={() => this.imageModel.chooseFile(this.imageModel)}
Expand Down
10 changes: 5 additions & 5 deletions packages/survey-creator-react/src/adorners/QuestionRating.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import { CreatorModelElement } from "../ModelElement";
export class QuestionRatingAdornerComponent extends CreatorModelElement<QuestionAdornerComponentProps, any> {
private modelValue: QuestionRatingAdornerViewModel;

protected createModel(): void {
this.modelValue = this.createQuestionViewModel();
protected createModel(props: any): void {
this.modelValue = this.createQuestionViewModel(props);
}
protected createQuestionViewModel(): QuestionRatingAdornerViewModel {
protected createQuestionViewModel(props: any): QuestionRatingAdornerViewModel {
return new QuestionRatingAdornerViewModel(
this.props.componentData,
this.props.question as any,
props.componentData,
props.question as any,
null
);
}
Expand Down
6 changes: 3 additions & 3 deletions packages/survey-creator-react/src/adorners/QuestionWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import {
import { attachKey2click, ReactElementFactory, SvgIcon } from "survey-react-ui";

export class QuestionWidgetAdornerComponent extends QuestionAdornerComponent {
protected createQuestionViewModel(): QuestionAdornerViewModel {
protected createQuestionViewModel(props: any): QuestionAdornerViewModel {
return new QuestionAdornerViewModel(
this.props.componentData,
this.props.question as any,
props.componentData,
props.question as any,
null
);
}
Expand Down
6 changes: 3 additions & 3 deletions packages/survey-creator-react/src/adorners/Row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ export class RowWrapper extends CreatorModelElement<
constructor(props: RowWrapperComponentProps) {
super(props);
}
protected createModel(): void {
protected createModel(props: any): void {
this.model = new RowViewModel(
this.props.componentData.creator,
this.props.row,
props.componentData.creator,
props.row,
null
);
}
Expand Down
10 changes: 5 additions & 5 deletions packages/survey-creator-react/src/toolbox/ToolboxItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ export class SurveyCreatorToolboxTool extends CreatorModelElement<
constructor(props) {
super(props);
}
protected createModel(): void {
this.model = new ToolboxToolViewModel(this.item, this.props.creator);
protected createModel(props: any): void {
this.model = new ToolboxToolViewModel(props.item, props.creator);
}
protected getUpdatedModelProps(): string[] {
return ["creator", "item"];
Expand Down Expand Up @@ -89,9 +89,9 @@ export class SurveyCreatorToolboxItem extends CreatorModelElement<
constructor(props) {
super(props);
}
protected createModel(): void {
const toolboxItem: IQuestionToolboxItem = this.props.item;
this.model = new ToolboxToolViewModel(toolboxItem, this.props.creator);
protected createModel(props: any): void {
const toolboxItem: IQuestionToolboxItem = props.item;
this.model = new ToolboxToolViewModel(toolboxItem, props.creator);
}
protected getUpdatedModelProps(): string[] {
return ["creator", "item"];
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 049d235

Please sign in to comment.