Skip to content

Commit

Permalink
Fixed #8254 - [React] Console Warnings when running the Form Library …
Browse files Browse the repository at this point in the history
…demo - Warning: Cannot update during an existing state transition (such as within render)
  • Loading branch information
tsv2013 committed May 15, 2024
1 parent 6800676 commit 745c4fb
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,51 @@ import { BaseAngular } from "../../base-angular";
templateUrl: "./dropdown.component.html"
})
export class DropdownComponent extends BaseAngular implements OnInit {
@Input() model: any;
@ViewChild("inputElement") inputElementRef!: ElementRef<HTMLDivElement>;
get dropdownModel(): DropdownListModel {
return this.model?.dropdownListModel;
}
protected getModel() {
return this.model.dropdownListModel;
}
@Input() model: any;
@ViewChild("inputElement") inputElementRef!: ElementRef<HTMLDivElement>;
get dropdownModel(): DropdownListModel {
return this.model?.dropdownListModel;
}
protected getModel() {
return this.model.dropdownListModel;
}

override ngOnInit(): void {
super.ngOnInit();
if (!this.model.dropdownListModel) {
this.model.dropdownListModel = new DropdownListModel(this.model);
}
override ngOnInit(): void {
super.ngOnInit();
if (!this.model.dropdownListModel) {
this.model.dropdownListModel = new DropdownListModel(this.model);
}
}

click(event: any) {
this.dropdownModel?.onClick(event);
}
click(event: any) {
this.dropdownModel?.onClick(event);
}
chevronPointerDown(event: any) {
this.dropdownModel?.chevronPointerDown(event);
}
clear(event: any) {
this.dropdownModel?.onClear(event);
}
keyhandler(event: any) {
this.dropdownModel?.keyHandler(event);
}
blur(event: any) {
this.dropdownModel?.onBlur(event);
this.updateInputDomElement();
}
focus(event: any) {
this.dropdownModel?.onFocus(event);
}
inputChange(event: any) {
this.detectChanges();
}
updateInputDomElement() {
if (!!this.inputElementRef?.nativeElement) {
const control: any = this.inputElementRef.nativeElement;
const newValue = this.model.inputStringRendered;
if (!Helpers.isTwoValueEquals(newValue, control.value, false, true, false)) {
control.value = this.model.inputStringRendered || "";
}
}
clear(event: any) {
this.dropdownModel?.onClear(event);
}
keyhandler(event: any) {
this.dropdownModel?.keyHandler(event);
}
blur(event: any) {
this.dropdownModel?.onBlur(event);
this.updateInputDomElement();
}
focus(event: any) {
this.dropdownModel?.onFocus(event);
}
inputChange(event: any) {
this.detectChanges();
}
updateInputDomElement() {
if (!!this.inputElementRef?.nativeElement) {
const control: any = this.inputElementRef.nativeElement;
const newValue = this.model.inputStringRendered;
if (!Helpers.isTwoValueEquals(newValue, control.value, false, true, false)) {
control.value = this.model.inputStringRendered || "";
}
}
}
}
4 changes: 4 additions & 0 deletions src/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2551,13 +2551,17 @@ export class Question extends SurveyElement<Question>
protected getDesktopRenderAs(): string {
return "default";
}
protected onBeforeSetCompactRenderer(): void { }
protected onBeforeSetDesktopRenderer(): void { }
protected processResponsiveness(requiredWidth: number, availableWidth: number): any {
availableWidth = Math.round(availableWidth);
if (Math.abs(requiredWidth - availableWidth) > 2) {
const oldRenderAs = this.renderAs;
if (requiredWidth > availableWidth) {
this.onBeforeSetCompactRenderer();
this.renderAs = this.getCompactRenderAs();
} else {
this.onBeforeSetDesktopRenderer();
this.renderAs = this.getDesktopRenderAs();
}
return oldRenderAs !== this.renderAs;
Expand Down
5 changes: 5 additions & 0 deletions src/question_rating.ts
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,11 @@ export class QuestionRatingModel extends Question {
protected supportResponsiveness(): boolean {
return true;
}
protected onBeforeSetCompactRenderer(): void {
if (!this.dropdownListModel) {
this.dropdownListModel = new DropdownListModel(this);
}
}
protected getCompactRenderAs(): string {
return (this.displayMode == "buttons") ? "default" : "dropdown";
}
Expand Down

0 comments on commit 745c4fb

Please sign in to comment.