Skip to content

Commit

Permalink
A question selector dropdown disappears (#494)
Browse files Browse the repository at this point in the history
Fixes #493

Co-authored-by: tsv2013 <tsv2013@noreply.github.com>
  • Loading branch information
tsv2013 and tsv2013 authored Dec 18, 2024
1 parent 1efcc9c commit d4451e0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/visualizationPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,11 @@ export class VisualizationPanel extends VisualizerBase {
order.forEach(name => {
newElements.push(this._elements.filter(el => el.name === name)[0]);
});
this._elements.forEach(el => {
if(order.indexOf(el.name) == -1) {
newElements.push(el);
}
});
this._elements = newElements;
this.visibleElementsChanged(undefined, "REORDERED");
}
Expand Down
33 changes: 33 additions & 0 deletions tests/visualizationPanel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -791,3 +791,36 @@ test("reorderVisibleElements", () => {
expect(state2.elements?.map(el => el.name)).toStrictEqual(["q2", "q1", "q3"]);
expect(stateChagedCounter).toBe(1);
});

test("keep hidden element on reorder", () => {
const json = {
elements: [
{
type: "text",
name: "q1",
},
{
type: "text",
name: "q2",
},
{
type: "text",
name: "q3",
}
],
};
const survey = new SurveyModel(json);
let visPanel = new VisualizationPanel(survey.getAllQuestions(), [], { layoutEngine: new LayoutEngine(true) });

expect(visPanel.getElements().length).toEqual(3);
expect(visPanel.getElements().map(el => el.isVisible)).toStrictEqual([true, true, true]);
expect(visPanel.getElements().map(el => el.name)).toStrictEqual(["q1", "q2", "q3"]);
visPanel.hideElement("q1");
expect(visPanel.getElements().length).toEqual(3);
expect(visPanel.getElements().map(el => el.isVisible)).toStrictEqual([false, true, true]);
expect(visPanel.getElements().map(el => el.name)).toStrictEqual(["q1", "q2", "q3"]);
visPanel.reorderVisibleElements(["q3", "q2"]);
expect(visPanel.getElements().length).toEqual(3);
expect(visPanel.getElements().map(el => el.isVisible)).toStrictEqual([true, true, false]);
expect(visPanel.getElements().map(el => el.name)).toStrictEqual(["q3", "q2", "q1"]);
});

0 comments on commit d4451e0

Please sign in to comment.