From 7f9fad624db5f177f20103c10f7245737031fb03 Mon Sep 17 00:00:00 2001 From: Andrew Telnov Date: Mon, 12 Feb 2024 17:01:55 +0200 Subject: [PATCH] Focus first input question in new added panel in panel dynamic fix #7858 --- src/question_paneldynamic.ts | 1 + testCafe/questions/paneldynamic.ts | 59 ++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/src/question_paneldynamic.ts b/src/question_paneldynamic.ts index a5b3c313dd..bc23f8003e 100644 --- a/src/question_paneldynamic.ts +++ b/src/question_paneldynamic.ts @@ -1247,6 +1247,7 @@ export class QuestionPanelDynamicModel extends Question if (this.renderMode === "list" && this.panelsState !== "default") { newPanel.expand(); } + newPanel.focusFirstQuestion(); return newPanel; } /** diff --git a/testCafe/questions/paneldynamic.ts b/testCafe/questions/paneldynamic.ts index 8f15a0ed1e..23fb05c3e1 100644 --- a/testCafe/questions/paneldynamic.ts +++ b/testCafe/questions/paneldynamic.ts @@ -465,4 +465,63 @@ frameworks.forEach((framework) => { await t.expect(Selector("button").withText("#Add#").exists).ok(); await t.expect(Selector("button").withText("#Remove#").exists).ok(); }); + test("Focus first input on adding a new panel", async (t) => { + await initSurvey(framework, { + elements: [ + { + type: "paneldynamic", + name: "panel1", + panelCount: 0, + newPanelPosition: "next", + templateElements: [ + { + type: "text", + name: "name" + }, + ], + } + ] + }); + await t.click(Selector("button").withText("Add")) + .pressKey("1 2 3") + .click(Selector("button").withText("Add")) + .pressKey("4 5 6") + .click(Selector("button").withText("Add")) + .pressKey("7 8 9") + .click(Selector(".sd-navigation__complete-btn")); + + await t.expect(await getSurveyResult()).eql({ + panel1: [{ name: "123" }, { name: "456" }, { name: "789" }] + }); + }); + test("Focus first input on adding a new panel, renderMode='tab'", async (t) => { + await initSurvey(framework, { + elements: [ + { + type: "paneldynamic", + name: "panel1", + panelCount: 0, + renderMode: "tab", + newPanelPosition: "next", + templateElements: [ + { + type: "text", + name: "name" + }, + ], + } + ] + }); + await t.click(Selector("button").withText("Add")) + .pressKey("1 2 3") + .click(Selector("button").withText("Add")) + .pressKey("4 5 6") + .click(Selector("button").withText("Add")) + .pressKey("7 8 9") + .click(Selector(".sd-navigation__complete-btn")); + + await t.expect(await getSurveyResult()).eql({ + panel1: [{ name: "123" }, { name: "456" }, { name: "789" }] + }); + }); }); \ No newline at end of file