Skip to content

Commit

Permalink
Fix survey is scrolled when focusing question inside paneldynamic/mat…
Browse files Browse the repository at this point in the history
…rixdynamic (#9116)
  • Loading branch information
dk981234 authored Nov 28, 2024
1 parent 8c2adad commit f72936c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/survey-core/src/survey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
42 changes: 42 additions & 0 deletions packages/survey-core/tests/surveytests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <QuestionPanelDynamicModel>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;
});

0 comments on commit f72936c

Please sign in to comment.