Objective: If user clicks any top level mat-expansion-panel-header element then collapse any open nested level mat-expansion-panel-header elements, eg:
- Click Main heading 1 to expand it
- Click Subheading 1 to expand it
- Click Main heading 1 to collapse it. This should fire an event that collapses Subheading 1.
This is essentially a 'housekeeping' task to clean up if user leaves panels expanded.
Issue: If you double click one of the top level mat-expansion-panel-header elements in quick succession (eg: whilst the expand/collapse animations are still running), the following error is thrown in the console:
ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'mat-expanded: false'. Current value: 'mat-expanded: true'.
If you continue to fire these errors, eventually it keeps firing indefinitely and the browser completely locks up.
See Stackblitz project here: https://stackblitz.com/edit/expression-changed-error
I was considering doing something like disabling clicks until the open/close animation has finished, but I'm sure there must be a reason that this is happening and a proper fix for it.