Skip to content

Commit 954d989

Browse files
committed
refactor(selection-list): avoid deprecated method
* use `FocusKeyManager`'s `updateActiveItem` method instead of deprecated `updateActiveItemIndex` * fix description of `MatSelectionList`'s `focus` method * remove `MatSelectionList`'s redundant `(focus)` event listener
1 parent d232d7c commit 954d989

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/lib/list/selection-list.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,6 @@ export class MatListOption extends _MatListOptionMixinBase
300300
'role': 'listbox',
301301
'[tabIndex]': 'tabIndex',
302302
'class': 'mat-selection-list mat-list-base',
303-
'(focus)': 'focus()',
304303
'(blur)': '_onTouched()',
305304
'(keydown)': '_keydown($event)',
306305
'aria-multiselectable': 'true',
@@ -416,7 +415,7 @@ export class MatSelectionList extends _MatSelectionListMixinBase implements Focu
416415
this._modelChanges.unsubscribe();
417416
}
418417

419-
/** Focuses the last active list option. */
418+
/** Focuses the selection list. */
420419
focus() {
421420
this._element.nativeElement.focus();
422421
}
@@ -444,11 +443,12 @@ export class MatSelectionList extends _MatSelectionListMixinBase implements Focu
444443
const optionIndex = this._getOptionIndex(option);
445444

446445
if (optionIndex > -1 && this._keyManager.activeItemIndex === optionIndex) {
446+
const options = this.options.toArray();
447447
// Check whether the option is the last item
448448
if (optionIndex > 0) {
449-
this._keyManager.updateActiveItemIndex(optionIndex - 1);
450-
} else if (optionIndex === 0 && this.options.length > 1) {
451-
this._keyManager.updateActiveItemIndex(Math.min(optionIndex + 1, this.options.length - 1));
449+
this._keyManager.updateActiveItem(options[optionIndex - 1]);
450+
} else if (optionIndex === 0 && options.length > 1) {
451+
this._keyManager.updateActiveItem(options[Math.min(optionIndex + 1, options.length - 1)]);
452452
}
453453
}
454454

0 commit comments

Comments
 (0)