@@ -36,7 +36,7 @@ import {
3636import  { BooleanInput ,  coerceArray ,  coerceBooleanProperty }  from  '@angular/cdk/coercion' ; 
3737import  { SelectionModel }  from  '@angular/cdk/collections' ; 
3838import  { defer ,  merge ,  Observable ,  Subject }  from  'rxjs' ; 
39- import  { filter ,  map ,  startWith ,  switchMap ,  take ,   takeUntil }  from  'rxjs/operators' ; 
39+ import  { filter ,  map ,  startWith ,  switchMap ,  takeUntil }  from  'rxjs/operators' ; 
4040import  { 
4141  AbstractControl , 
4242  ControlValueAccessor , 
@@ -82,9 +82,9 @@ class ListboxSelectionModel<T> extends SelectionModel<T> {
8282    // The super class is always in multi-selection mode, so we need to override the behavior if 
8383    // this selection model actually belongs to a single-selection listbox. 
8484    if  ( this . multiple )  { 
85-       super . select ( ...values ) ; 
85+       return   super . select ( ...values ) ; 
8686    }  else  { 
87-       super . setSelection ( ...values ) ; 
87+       return   super . setSelection ( ...values ) ; 
8888    } 
8989  } 
9090} 
@@ -545,7 +545,7 @@ export class CdkListbox<T = unknown>
545545      if  ( this . _invalid )  { 
546546        this . selectionModel . clear ( false ) ; 
547547      } 
548-       this . selectionModel . select ( ...this . options . toArray ( ) . map ( option  =>  option . value ) ) ; 
548+       this . selectionModel . select ( ...this . options . map ( option  =>  option . value ) ) ; 
549549    } 
550550  } 
551551
@@ -635,15 +635,9 @@ export class CdkListbox<T = unknown>
635635  protected  triggerOption ( option : CdkOption < T >  |  null )  { 
636636    if  ( option  &&  ! option . disabled )  { 
637637      this . _lastTriggered  =  option ; 
638-       let  changed  =  false ; 
639-       this . selectionModel . changed 
640-         . pipe ( take ( 1 ) ,  takeUntil ( this . destroyed ) ) 
641-         . subscribe ( ( )  =>  ( changed  =  true ) ) ; 
642-       if  ( this . multiple )  { 
643-         this . toggle ( option ) ; 
644-       }  else  { 
645-         this . select ( option ) ; 
646-       } 
638+       const  changed  =  this . multiple 
639+         ? this . selectionModel . toggle ( option . value ) 
640+         : this . selectionModel . select ( option . value ) ; 
647641      if  ( changed )  { 
648642        this . _onChange ( this . value ) ; 
649643        this . valueChange . next ( { 
@@ -669,10 +663,12 @@ export class CdkListbox<T = unknown>
669663    } 
670664    this . _lastTriggered  =  trigger ; 
671665    const  isEqual  =  this . compareWith  ??  Object . is ; 
672-     const  options  =  this . options . toArray ( ) ; 
673-     const  updateValues  =  options 
674-       . slice ( Math . max ( 0 ,  Math . min ( from ,  to ) ) ,  Math . min ( options . length ,  Math . max ( from ,  to )  +  1 ) ) 
675-       . map ( option  =>  option . value ) ; 
666+     const  updateValues  =  this . options 
667+       . map ( option  =>  option . value ) 
668+       . slice ( 
669+         Math . max ( 0 ,  Math . min ( from ,  to ) ) , 
670+         Math . min ( this . options . length ,  Math . max ( from ,  to )  +  1 ) , 
671+       ) ; 
676672    const  selected  =  [ ...this . value ] ; 
677673    for  ( const  updateValue  of  updateValues )  { 
678674      const  selectedIndex  =  selected . findIndex ( selectedValue  => 
@@ -684,11 +680,7 @@ export class CdkListbox<T = unknown>
684680        selected . splice ( selectedIndex ,  1 ) ; 
685681      } 
686682    } 
687-     let  changed  =  false ; 
688-     this . selectionModel . changed 
689-       . pipe ( take ( 1 ) ,  takeUntil ( this . destroyed ) ) 
690-       . subscribe ( ( )  =>  ( changed  =  true ) ) ; 
691-     this . selectionModel . setSelection ( ...selected ) ; 
683+     let  changed  =  this . selectionModel . setSelection ( ...selected ) ; 
692684    if  ( changed )  { 
693685      this . _onChange ( this . value ) ; 
694686      this . valueChange . next ( { 
@@ -989,6 +981,7 @@ export class CdkListbox<T = unknown>
989981    return  values . filter ( value  =>  ! validValues . some ( validValue  =>  isEqual ( value ,  validValue ) ) ) ; 
990982  } 
991983
984+   /** Get the index of the last triggered option. */ 
992985  private  _getLastTriggeredIndex ( )  { 
993986    const  index  =  this . options . toArray ( ) . indexOf ( this . _lastTriggered ! ) ; 
994987    return  index  ===  - 1  ? null  : index ; 
0 commit comments