Skip to content

Commit

Permalink
refactor(cdk/a11y): use classList.toggle
Browse files Browse the repository at this point in the history
With Angular dropping IE11 support in version 13, we can now use `classList.toggle` with the second `force` param. Related to angular#7374
  • Loading branch information
jelbourn committed Aug 2, 2021
1 parent 368a5ed commit 5ba8c4b
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions src/cdk/a11y/focus-monitor/focus-monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,6 @@ export class FocusMonitor implements OnDestroy {
return doc.defaultView || window;
}

private _toggleClass(element: Element, className: string, shouldSet: boolean) {
if (shouldSet) {
element.classList.add(className);
} else {
element.classList.remove(className);
}
}

private _getFocusOrigin(focusEventTarget: HTMLElement | null): FocusOrigin {
if (this._origin) {
// If the origin was realized via a touch interaction, we need to perform additional checks
Expand Down Expand Up @@ -368,11 +360,11 @@ export class FocusMonitor implements OnDestroy {
* @param origin The focus origin.
*/
private _setClasses(element: HTMLElement, origin?: FocusOrigin): void {
this._toggleClass(element, 'cdk-focused', !!origin);
this._toggleClass(element, 'cdk-touch-focused', origin === 'touch');
this._toggleClass(element, 'cdk-keyboard-focused', origin === 'keyboard');
this._toggleClass(element, 'cdk-mouse-focused', origin === 'mouse');
this._toggleClass(element, 'cdk-program-focused', origin === 'program');
element.classList.toggle('cdk-focused', !!origin);
element.classList.toggle('cdk-touch-focused', origin === 'touch');
element.classList.toggle('cdk-keyboard-focused', origin === 'keyboard');
element.classList.toggle('cdk-mouse-focused', origin === 'mouse');
element.classList.toggle('cdk-program-focused', origin === 'program');
}

/**
Expand Down

0 comments on commit 5ba8c4b

Please sign in to comment.