Skip to content

fix(button-toggle): focus monitoring not being cleaned up on destroy #10580

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/lib/button-toggle/button-toggle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
EventEmitter,
forwardRef,
Input,
OnDestroy,
OnInit,
Optional,
Output,
Expand Down Expand Up @@ -331,7 +332,8 @@ export const _MatButtonToggleMixinBase = mixinDisableRipple(MatButtonToggleBase)
'[attr.id]': 'id',
}
})
export class MatButtonToggle extends _MatButtonToggleMixinBase implements OnInit, CanDisableRipple {
export class MatButtonToggle extends _MatButtonToggleMixinBase implements OnInit,
CanDisableRipple, OnDestroy {

private _isSingleSelector = false;
private _checked = false;
Expand All @@ -350,7 +352,7 @@ export class MatButtonToggle extends _MatButtonToggleMixinBase implements OnInit
/** Type of the button toggle. Either 'radio' or 'checkbox'. */
_type: ToggleType;

@ViewChild('input') _inputElement: ElementRef;
@ViewChild('input') _inputElement: ElementRef<HTMLInputElement>;

/** The parent button toggle group (exclusive selection). Optional. */
buttonToggleGroup: MatButtonToggleGroup;
Expand Down Expand Up @@ -400,7 +402,7 @@ export class MatButtonToggle extends _MatButtonToggleMixinBase implements OnInit

constructor(@Optional() toggleGroup: MatButtonToggleGroup,
private _changeDetectorRef: ChangeDetectorRef,
private _elementRef: ElementRef,
private _elementRef: ElementRef<HTMLElement>,
private _focusMonitor: FocusMonitor) {
super();

Expand All @@ -423,6 +425,10 @@ export class MatButtonToggle extends _MatButtonToggleMixinBase implements OnInit
this._focusMonitor.monitor(this._elementRef.nativeElement, true);
}

ngOnDestroy() {
this._focusMonitor.stopMonitoring(this._elementRef.nativeElement);
}

/** Focuses the button. */
focus(): void {
this._inputElement.nativeElement.focus();
Expand Down