Skip to content

Commit

Permalink
fix(event-display): persist children toggle state in Phoenix menu
Browse files Browse the repository at this point in the history
  • Loading branch information
9inpachi authored Feb 15, 2021
2 parents 83721e5 + e96136b commit 5d62995
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ export class PhoenixMenuNode {
nodeLevel: number = 0;
/** Parent of the node. */
private parent: PhoenixMenuNode;
/**
* Previous toggle state of child nodes. This is so that the
* previous state of child can be restored if we toggle the parent back on.
* */
private childrenToggleState = {};

/** If the node children are active or not. */
childrenActive: boolean = false;
Expand Down Expand Up @@ -124,7 +129,15 @@ export class PhoenixMenuNode {
this.onToggle?.(value);
this.toggleState = value;
for (const child of this.children) {
child.toggleSelfAndDescendants(value);
if (!value) {
// Save previous toggle state of children and toggle them false
this.childrenToggleState[child.name] = child.toggleState;
child.toggleSelfAndDescendants(value);
} else {
// Restore previous toggle state of children
child.toggleState = this.childrenToggleState[child.name];
child.toggleSelfAndDescendants(child.toggleState);
}
}
}

Expand Down

0 comments on commit 5d62995

Please sign in to comment.