diff --git a/packages/survey-core/src/survey.ts b/packages/survey-core/src/survey.ts index b76af45454..a1f464922d 100644 --- a/packages/survey-core/src/survey.ts +++ b/packages/survey-core/src/survey.ts @@ -5372,7 +5372,7 @@ export class SurveyModel extends SurveyElementCore }); }, elementsToRenderBefore); } else { - if (!elementPage && !this.isSinglePage && !this.isDesignMode && this.rootElement) { + if (element.isPage && !this.isSinglePage && !this.isDesignMode && this.rootElement) { const elementToScroll = this.rootElement.querySelector(classesToSelector(this.css.rootWrapper)) as HTMLElement; SurveyElement.ScrollElementToViewCore(elementToScroll, false, scrollIfVisible, scrollIntoViewOptions, onScolledCallback); } else { diff --git a/packages/survey-core/tests/surveytests.ts b/packages/survey-core/tests/surveytests.ts index 51d7168364..3e10ccb693 100644 --- a/packages/survey-core/tests/surveytests.ts +++ b/packages/survey-core/tests/surveytests.ts @@ -21019,3 +21019,45 @@ QUnit.test("onValueChanged event & isExpressionRunning parameter", function (ass { name: "q5", val: 8, reason: "trigger" }, { name: "q4", val: 3, reason: undefined }], "logs #3"); }); + +QUnit.test("#9110 check focus question inside paneldynamic works correctly", function (assert) { + let log = ""; + const oldScrollElementToViewCore = SurveyElement.ScrollElementToViewCore; + const oldScrollElementToTop = SurveyElement.ScrollElementToTop; + SurveyElement.ScrollElementToViewCore = ((el, _, __, ___, doneCallback) => { + log += `->${el.id}`; + doneCallback(); + }) as any; + SurveyElement.ScrollElementToTop = ((elId, _, __, doneCallback) => { + (SurveyElement as any).ScrollElementToViewCore({ id: elId }, null, null, null, doneCallback); + }) as any; + const survey = new SurveyModel({ + "elements": [ + { + type: "paneldynamic", + name: "p1", + templateElements: [ + { + type: "text", + name: "text" + } + ], + panelCount: 1 + }, + ], + }); + const panelDynamic = survey.getAllQuestions()[0]; + const rootElement = document.createElement("div"); + const rootWrapper = document.createElement("div"); + rootWrapper.id = "root-wrapper"; + rootWrapper.className = survey.css.rootWrapper; + rootElement.appendChild(rootWrapper); + survey.rootElement = rootElement; + const quesiton = panelDynamic.panels[0].questions[0]; + survey.scrollElementToTop(quesiton, quesiton, null as any, "text_question_id", false, null, null, () => { + log += "->focused text question"; + }); + assert.equal(log, "->text_question_id->focused text question"); + SurveyElement.ScrollElementToViewCore = oldScrollElementToViewCore; + SurveyElement.ScrollElementToTop = oldScrollElementToTop; +}); \ No newline at end of file