Skip to content

Commit

Permalink
#6038 - change expanded to collapsed, do not use undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
novikov82 committed Nov 12, 2024
1 parent 4ed0b31 commit 0182791
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
5 changes: 2 additions & 3 deletions packages/survey-creator-core/src/creator-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1954,11 +1954,10 @@ export class SurveyCreatorModel extends Base
const options: ElementGetExpandCollapseStateEvent = {
element: element,
reason: reason,
expanded: undefined
collapsed: defaultValue
};
this.onElementGetExpandCollapseState.fire(this, options);
if (options.expanded === undefined) return defaultValue;
return !options.expanded;
return options.collapsed;
}

private restoreState(element: SurveyElement) {
Expand Down
2 changes: 1 addition & 1 deletion packages/survey-creator-core/src/creator-events-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export interface HtmlToMarkdownEvent {
export type ElementGetExpandCollapseStateEventReason = "loading" | "collapse-all" | "expand-all" | "drag-start" | "drag-end";
export interface ElementGetExpandCollapseStateEvent {
element: Question | PanelModel | PageModel;
expanded: boolean | undefined;
collapsed: boolean;
reason: ElementGetExpandCollapseStateEventReason;
}

Expand Down
26 changes: 13 additions & 13 deletions packages/survey-creator-core/tests/tabs/designer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,27 +464,27 @@ test("expand/collapse event - loading", () => {

creator.onElementGetExpandCollapseState.add((_, o) => {
if (o.reason == "loading") {
if (o.element.name == "page2") o.expanded = true;
if (o.element.name == "question1") o.expanded = false;
if (o.element.name == "page2") o.collapsed = false;
if (o.element.name == "question1") o.collapsed = true;
}
if (o.reason == "collapse-all") {
if (o.element.name == "page2") o.expanded = false;
if (o.element.name == "question1") o.expanded = true;
if (o.element.name == "page2") o.collapsed = true;
if (o.element.name == "question1") o.collapsed = false;
}
if (o.reason == "expand-all") {
if (o.element.name == "page1") o.expanded = true;
if (o.element.name == "page2") o.expanded = true;
if (o.element.name == "question1") o.expanded = false;
if (o.element.name == "page1") o.collapsed = false;
if (o.element.name == "page2") o.collapsed = false;
if (o.element.name == "question1") o.collapsed = true;
}
if (o.reason == "drag-start") {
if (o.element.name == "page1") o.expanded = false;
if (o.element.name == "page2") o.expanded = true;
if (o.element.name == "panel1") o.expanded = false;
if (o.element.name == "page1") o.collapsed = true;
if (o.element.name == "page2") o.collapsed = false;
if (o.element.name == "panel1") o.collapsed = true;
}
if (o.reason == "drag-end") {
if (o.element.name == "page1") o.expanded = true;
if (o.element.name == "page2") o.expanded = true;
if (o.element.name == "panel1") o.expanded = false;
if (o.element.name == "page1") o.collapsed = false;
if (o.element.name == "page2") o.collapsed = false;
if (o.element.name == "panel1") o.collapsed = true;
}
});

Expand Down

0 comments on commit 0182791

Please sign in to comment.