Skip to content

Commit

Permalink
Merge pull request #9107 from surveyjs/tsv2013/issue9104
Browse files Browse the repository at this point in the history
Comment is scrolled on expand the question content
  • Loading branch information
andrewtelnov authored Nov 27, 2024
2 parents 93c9f0d + 8e4def2 commit e88c14a
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, ElementRef, Input, ViewChild } from "@angular/core";
import { Component, ElementRef, Input, OnDestroy, ViewChild } from "@angular/core";
import { TextAreaModel } from "survey-core";
import { AngularComponentFactory } from "../../component-factory";
import { EmbeddedViewContentComponent } from "../../embedded-view-content.component";
Expand All @@ -8,7 +8,7 @@ import { EmbeddedViewContentComponent } from "../../embedded-view-content.compon
templateUrl: "./text-area.component.html",
styleUrls: ["../../hide-host.scss"]
})
export class TextAreaComponent extends EmbeddedViewContentComponent {
export class TextAreaComponent extends EmbeddedViewContentComponent implements OnDestroy {
@Input() model!: TextAreaModel;
@ViewChild("contentElement") elementContentRef!: ElementRef<HTMLElement>;

Expand All @@ -22,6 +22,9 @@ export class TextAreaComponent extends EmbeddedViewContentComponent {
this.model.setElement(element as HTMLTextAreaElement);
}
}
public ngOnDestroy(): void {
!!this.model && this.model.dispose();
}
}

AngularComponentFactory.Instance.registerComponent("sv-text-area", TextAreaComponent);
8 changes: 7 additions & 1 deletion packages/survey-core/src/question_comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,13 @@ export class QuestionCommentModel extends QuestionTextBase {
super.setNewValue(newValue);
}
protected getValueSeparator(): string { return "\n"; }
public get className() {
protected notifyStateChanged(prevState: string): void {
super.notifyStateChanged(prevState);
if (!this.isCollapsed) {
this.textAreaModel.updateElement();
}
}
public get className(): string {
return (this.cssClasses ? this.getControlClass() : "panel-comment-root") || undefined;
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/survey-core/src/utils/text-area.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface ITextArea {
export class TextAreaModel {
private element: HTMLTextAreaElement;

private updateElement(): void {
public updateElement(): void {
if (this.element && this.autoGrow) {
setTimeout(() => increaseHeightByContent(this.element), 1);
}
Expand All @@ -54,7 +54,7 @@ export class TextAreaModel {
this.updateElement();
}
}
public resetElement() {
public resetElement(): void {
this.element = undefined as any;
}

Expand Down
16 changes: 15 additions & 1 deletion packages/survey-react-ui/src/components/text-area.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ interface ITextAreaProps {
}

export class TextAreaComponent extends SurveyElementBase<ITextAreaProps, any> {
private textareaRef: React.RefObject<HTMLTextAreaElement>;
private initialValue;

constructor(props: ITextAreaProps) {
super(props);
this.initialValue = this.viewModel.getTextValue() || "";
this.textareaRef = React.createRef();
}
get viewModel(): TextAreaModel {
return this.props.viewModel;
Expand All @@ -21,12 +23,24 @@ export class TextAreaComponent extends SurveyElementBase<ITextAreaProps, any> {
return !!this.viewModel.question;
}

componentDidMount() {
super.componentDidMount();
let el = this.textareaRef.current;
if (!!el) {
this.viewModel.setElement(el);
}
}
componentWillUnmount() {
super.componentWillUnmount();
this.viewModel.resetElement();
}

protected renderElement(): JSX.Element {
return (
<textarea
id={this.viewModel.id}
className={this.viewModel.className}
ref={(textarea) => (this.viewModel.setElement(textarea))}
ref={this.textareaRef}
disabled={this.viewModel.isDisabledAttr}
readOnly={this.viewModel.isReadOnlyAttr}
rows={this.viewModel.rows}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions visualRegressionTests/tests/defaultV2/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,44 @@ frameworks.forEach(framework => {
});
});

test("Update comment height", async (t) => {
await wrapVisualTest(t, async (t, comparer) => {
await t.resizeWindow(1500, 900);
await initSurvey(framework, {
logoPosition: "right",
pages: [
{
name: "puslapis1",
validationType: "none",
elements: [
{
type: "comment",
name: "klausimas1",
state: "collapsed",
defaultValueExpression:
"'To enhance experience of designers working with large forms in SurveyJS Creator, with v2.0, we plan to introduce the expand/collapse feature for form pages, panels and elements.To enhance experience of designers working with large forms in SurveyJS Creator, with v2.0, we plan to introduce the expand/collapse feature for form pages, panels and elements.'",
readOnly: true,
autoGrow: true,
},
],
},
],
widthMode: "static",
width: "500px",
autosaveMode: "ON_BLUR",
});

await ClientFunction(() => {
(window as any).survey.allowResizeComment = false;
(window as any).survey.autoGrowComment = true;
})();
const questionRoot = Selector(".sd-question");
await t.click(questionRoot);
await t.wait(500);
await takeElementScreenshot("question-comment-ajust-height.png", questionRoot, t, comparer);
});
});

test("Remaining character counter - mobile view", async (t) => {
await wrapVisualTest(t, async (t, comparer) => {
await t.resizeWindow(350, 900);
Expand Down

0 comments on commit e88c14a

Please sign in to comment.