diff --git a/packages/survey-angular-ui/src/components/svg-icon/svg-icon.component.ts b/packages/survey-angular-ui/src/components/svg-icon/svg-icon.component.ts index 5ef0aeabf6..a87613581f 100644 --- a/packages/survey-angular-ui/src/components/svg-icon/svg-icon.component.ts +++ b/packages/survey-angular-ui/src/components/svg-icon/svg-icon.component.ts @@ -40,9 +40,11 @@ export class SvgIconComponent implements OnChanges { return "presentation"; } ngOnChanges(): void { - const el = this.viewContaierRef.element.nativeElement; - el.innerHTML = ""; - el.appendChild(document.createElementNS("http://www.w3.org/2000/svg", "use")); - this.createSvg(); + if (typeof document !== "undefined") { + const el = this.viewContaierRef.element.nativeElement; + el.innerHTML = ""; + el.appendChild(document.createElementNS("http://www.w3.org/2000/svg", "use")); + this.createSvg(); + } } } \ No newline at end of file diff --git a/packages/survey-angular-ui/src/svgbundle.component.ts b/packages/survey-angular-ui/src/svgbundle.component.ts index 48632db34c..47514bc9e5 100644 --- a/packages/survey-angular-ui/src/svgbundle.component.ts +++ b/packages/survey-angular-ui/src/svgbundle.component.ts @@ -8,8 +8,10 @@ import { Component, ElementRef, OnDestroy, OnInit, ViewChild } from "@angular/co export class SvgBundleComponent implements OnInit, OnDestroy { @ViewChild("svgContainer", { static: true }) svgContainer!: ElementRef; private onIconsChanged = () => { - if (!!this.svgContainer?.nativeElement) { - this.svgContainer.nativeElement.innerHTML = SvgRegistry.iconsRenderedHtml(); + if (typeof document !== "undefined") { + if (!!this.svgContainer?.nativeElement) { + this.svgContainer.nativeElement.innerHTML = SvgRegistry.iconsRenderedHtml(); + } } }; ngOnInit(): void { @@ -19,5 +21,4 @@ export class SvgBundleComponent implements OnInit, OnDestroy { ngOnDestroy(): void { SvgRegistry.onIconsChanged.remove(this.onIconsChanged); } - } \ No newline at end of file diff --git a/packages/survey-core/src/question.ts b/packages/survey-core/src/question.ts index 560898bce2..4d9ea5049a 100644 --- a/packages/survey-core/src/question.ts +++ b/packages/survey-core/src/question.ts @@ -21,7 +21,7 @@ import { PopupModel } from "./popup"; import { ConsoleWarnings } from "./console-warnings"; import { ProcessValue } from "./conditionProcessValue"; import { ITheme } from "./themes"; -import { DomWindowHelper } from "./global_variables_utils"; +import { DomDocumentHelper, DomWindowHelper } from "./global_variables_utils"; import { ITextArea, TextAreaModel } from "./utils/text-area"; import { Action } from "./actions/action"; import { QuestionSingleInputSummary } from "./questionSingleInputSummary"; @@ -1371,9 +1371,8 @@ export class Question extends SurveyElement if (this.supportComment() || this.supportOther()) { this.commentElements = []; this.getCommentElementsId().forEach(id => { - const { root } = settings.environment; - let el = root.getElementById(id); - if (el)this.commentElements.push(el); + const commentEl = el?.querySelector(`#${id}`); + if (commentEl)this.commentElements.push(commentEl as HTMLElement); }); this.updateCommentElements(); } @@ -3062,6 +3061,7 @@ export class Question extends SurveyElement } private triggerResponsivenessCallback: (hard: boolean) => void; private initResponsiveness(el: HTMLElement) { + if (!DomDocumentHelper.isAvailable()) { return; } this.destroyResizeObserver(); if (!!el && this.isDefaultRendering()) { const scrollableSelector = this.getObservedElementSelector(); diff --git a/packages/survey-core/src/question_comment.ts b/packages/survey-core/src/question_comment.ts index 07f3b10816..a0346fed58 100644 --- a/packages/survey-core/src/question_comment.ts +++ b/packages/survey-core/src/question_comment.ts @@ -135,8 +135,7 @@ export class QuestionCommentModel extends QuestionTextBase { return "comment"; } public afterRenderQuestionElement(el: HTMLElement): void { - const { root } = settings.environment; - this.element = root.getElementById(this.inputId) || el; + this.element = el?.querySelector(`#${this.inputId}`) || el; super.afterRenderQuestionElement(el); } public beforeDestroyQuestionElement(el: HTMLElement): void { diff --git a/packages/survey-core/src/question_signaturepad.ts b/packages/survey-core/src/question_signaturepad.ts index 8cde6458f1..afcdc9a5b2 100644 --- a/packages/survey-core/src/question_signaturepad.ts +++ b/packages/survey-core/src/question_signaturepad.ts @@ -64,9 +64,13 @@ export class QuestionSignaturePadModel extends QuestionFileModelBase { return "signaturepad"; } public afterRenderQuestionElement(el: HTMLElement) { - if (!!el) { - if (!this.isDesignMode)this.initSignaturePad(el); - this.element = el; + if (DomWindowHelper.isAvailable()) { + if (!!el) { + if (!this.isDesignMode) { + this.initSignaturePad(el); + } + this.element = el; + } } super.afterRenderQuestionElement(el); } diff --git a/packages/survey-core/src/scroll.ts b/packages/survey-core/src/scroll.ts index b9c5d7ff5c..88353ab47f 100644 --- a/packages/survey-core/src/scroll.ts +++ b/packages/survey-core/src/scroll.ts @@ -1,4 +1,5 @@ +import { DomDocumentHelper, DomWindowHelper } from "./global_variables_utils"; export class ScrollViewModel { private _containerElementValue: HTMLElement; private _scrollbarElement: HTMLElement; @@ -15,7 +16,7 @@ export class ScrollViewModel { this._scrollbarElement = element?.querySelector(".sv-scroll__scrollbar"); this._scrollbarSizerElement = element?.querySelector(".sv-scroll__scrollbar-sizer"); this._containerBodyElement = element?.querySelector(".sv-scroll__container"); - if (!element) return; + if (!element || !DomWindowHelper.isAvailable()) return; this._containerBodyResizeObserver = new ResizeObserver(entries => { for (let entry of entries) { const height = entry.contentBoxSize diff --git a/packages/survey-core/src/survey.ts b/packages/survey-core/src/survey.ts index 30a2071b34..5b0119fe62 100644 --- a/packages/survey-core/src/survey.ts +++ b/packages/survey-core/src/survey.ts @@ -5485,6 +5485,7 @@ export class SurveyModel extends SurveyElementCore private isSmoothScrollEnabled = false; private resizeObserver: ResizeObserver; afterRenderSurvey(htmlElement: any) { + if (!DomWindowHelper.isAvailable()) return; this.destroyResizeObserver(); if (Array.isArray(htmlElement)) { htmlElement = SurveyElement.GetFirstNonTextElement(htmlElement); diff --git a/packages/survey-core/tests/question_customtests.ts b/packages/survey-core/tests/question_customtests.ts index 6e44811b79..42a086b64c 100644 --- a/packages/survey-core/tests/question_customtests.ts +++ b/packages/survey-core/tests/question_customtests.ts @@ -1058,7 +1058,7 @@ QUnit.test("Single: onAfterRender and onAfterRenderContentElement", function ( elements: [{ type: "newquestion", name: "q1" }], }); var q = survey.getAllQuestions()[0]; - const el: HTMLElement = ({ a: 5 }); + const el: HTMLElement = ({ a: 5, querySelector: () => {} }); q.afterRender(el); assert.equal( afterRenderQuestion.name, @@ -1070,7 +1070,7 @@ QUnit.test("Single: onAfterRender and onAfterRenderContentElement", function ( 5, "onAfterRender, htmlElement parameter is correct" ); - q.contentQuestion.afterRender(7); + q.contentQuestion.afterRender({ b: 7, querySelector: () => {} } as any); assert.equal( afterRenderContentElementQuestion.name, "q1", @@ -1082,7 +1082,7 @@ QUnit.test("Single: onAfterRender and onAfterRenderContentElement", function ( "afterRenderContentElement, element parameter is correct" ); assert.equal( - afterRenderContentElementHtml, + (afterRenderContentElementHtml as any).b, 7, "afterRenderContentElement, htmlElement parameter is correct" ); diff --git a/packages/survey-vue3-ui/src/Comment.vue b/packages/survey-vue3-ui/src/Comment.vue index 5aff698a49..611d6d6a60 100644 --- a/packages/survey-vue3-ui/src/Comment.vue +++ b/packages/survey-vue3-ui/src/Comment.vue @@ -15,7 +15,7 @@ @@ -29,6 +29,9 @@ import { useQuestion } from "./base"; import { ref } from "vue"; defineOptions({ inheritAttrs: false }); const props = defineProps<{ question: QuestionCommentModel }>(); -const root = ref(null); +const root = ref(); +function getRef(el: HTMLElement) { + root.value = el; +} useQuestion(props, root); diff --git a/packages/survey-vue3-ui/src/components/TextArea.vue b/packages/survey-vue3-ui/src/components/TextArea.vue index e9780cdeb0..723aa072ca 100644 --- a/packages/survey-vue3-ui/src/components/TextArea.vue +++ b/packages/survey-vue3-ui/src/components/TextArea.vue @@ -1,6 +1,6 @@