@@ -176,6 +176,10 @@ export class CdkOption<T = unknown> implements ListKeyManagerOption, Highlightab
176
176
}
177
177
}
178
178
179
+ getElementRef ( ) {
180
+ return this . _elementRef ;
181
+ }
182
+
179
183
/** Sets the active property to true to enable the active css class. */
180
184
setActiveStyles ( ) {
181
185
this . _active = true ;
@@ -273,6 +277,7 @@ export class CdkListbox<T> implements AfterContentInit, OnDestroy, OnInit, Contr
273
277
@Input ( 'parentPanel' ) private readonly _explicitPanel : CdkComboboxPanel ;
274
278
275
279
constructor (
280
+ private readonly _elementRef : ElementRef ,
276
281
@Optional ( ) @Inject ( PANEL ) readonly _parentPanel ?: CdkComboboxPanel < T > ,
277
282
) { }
278
283
@@ -421,6 +426,10 @@ export class CdkListbox<T> implements AfterContentInit, OnDestroy, OnInit, Contr
421
426
422
427
if ( ! this . useActiveDescendant ) {
423
428
this . _activeOption . focus ( ) ;
429
+ } else {
430
+ if ( document . activeElement === this . _activeOption . getElementRef ( ) . nativeElement ) {
431
+ this . _elementRef . nativeElement . focus ( ) ;
432
+ }
424
433
}
425
434
}
426
435
@@ -458,6 +467,7 @@ export class CdkListbox<T> implements AfterContentInit, OnDestroy, OnInit, Contr
458
467
/** Updates the key manager's active item to the given option. */
459
468
setActiveOption ( option : CdkOption < T > ) {
460
469
this . _listKeyManager . updateActiveItem ( option ) ;
470
+ this . _updateActiveOption ( ) ;
461
471
}
462
472
463
473
/**
@@ -488,6 +498,11 @@ export class CdkListbox<T> implements AfterContentInit, OnDestroy, OnInit, Contr
488
498
this . disabled = isDisabled ;
489
499
}
490
500
501
+ /** Returns the values of the currently selected options. */
502
+ getSelectedValues ( ) : T [ ] {
503
+ return this . _options . filter ( option => option . selected ) . map ( option => option . value ) ;
504
+ }
505
+
491
506
/** Selects an option that has the corresponding given value. */
492
507
private _setSelectionByValue ( values : T | T [ ] ) {
493
508
for ( const option of this . _options . toArray ( ) ) {
0 commit comments