@@ -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
@@ -422,6 +427,10 @@ export class CdkListbox<T> implements AfterContentInit, OnDestroy, OnInit, Contr
422
427
423
428
if ( ! this . useActiveDescendant ) {
424
429
this . _activeOption . focus ( ) ;
430
+ } else {
431
+ if ( document . activeElement === this . _activeOption . getElementRef ( ) . nativeElement ) {
432
+ this . _elementRef . nativeElement . focus ( ) ;
433
+ }
425
434
}
426
435
}
427
436
@@ -459,6 +468,7 @@ export class CdkListbox<T> implements AfterContentInit, OnDestroy, OnInit, Contr
459
468
/** Updates the key manager's active item to the given option. */
460
469
setActiveOption ( option : CdkOption < T > ) {
461
470
this . _listKeyManager . updateActiveItem ( option ) ;
471
+ this . _updateActiveOption ( ) ;
462
472
}
463
473
464
474
/**
@@ -489,6 +499,11 @@ export class CdkListbox<T> implements AfterContentInit, OnDestroy, OnInit, Contr
489
499
this . disabled = isDisabled ;
490
500
}
491
501
502
+ /** Returns the values of the currently selected options. */
503
+ getSelectedValues ( ) : T [ ] {
504
+ return this . _options . filter ( option => option . selected ) . map ( option => option . value ) ;
505
+ }
506
+
492
507
/** Selects an option that has the corresponding given value. */
493
508
private _setSelectionByValue ( values : T | T [ ] ) {
494
509
for ( const option of this . _options . toArray ( ) ) {
0 commit comments