@@ -483,12 +483,15 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy {
483483 id : data . moduleId === undefined ? data . sectionId : undefined ,
484484 } ) ;
485485
486- // Select the root section.
487- this . sectionChanged ( parents [ 0 ] ?? section ) ;
486+ // If a section is selected (no moduleId), or all sections are not displayed. Change section.
487+ if ( ! data . moduleId || ! this . selectedSection || this . selectedSection . id !== this . allSectionsId ) {
488+ // Select the root section.
489+ this . sectionChanged ( parents [ 0 ] ?? section ) ;
490+ }
488491
489- if ( parents . length && section ) {
490- // It's a subsection. Expand all the parents and the subsection .
491- for ( let i = 1 ; i < parents . length ; i ++ ) {
492+ if ( section ) {
493+ // It's a subsection. Expand its parents too .
494+ for ( let i = 0 ; i < parents . length ; i ++ ) {
492495 this . setSectionExpanded ( parents [ i ] ) ;
493496 }
494497
@@ -811,6 +814,9 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy {
811814 */
812815 accordionMultipleChange ( ev : AccordionGroupChangeEventDetail ) : void {
813816 const sectionIds = ev . value as string [ ] | undefined ;
817+
818+ this . accordionMultipleValue = ev . value ;
819+
814820 const allSections = CoreCourseHelper . flattenSections ( this . sections ) ;
815821 allSections . forEach ( ( section ) => {
816822 section . expanded = false ;
@@ -836,8 +842,14 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy {
836842 */
837843 protected setSectionExpanded ( section : CoreCourseSectionToDisplay ) : void {
838844 section . expanded = true ;
845+
839846 if ( ! this . accordionMultipleValue . includes ( section . id . toString ( ) ) ) {
840- this . accordionMultipleValue . push ( section . id . toString ( ) ) ;
847+ // Force detect changes to update the view.
848+ this . accordionMultipleValue = [
849+ ...this . accordionMultipleValue ,
850+ section . id . toString ( ) ,
851+ ] ;
852+
841853 this . saveExpandedSections ( ) ;
842854 }
843855 }
0 commit comments