Skip to content

Commit 6585fb7

Browse files
committed
address comments
1 parent 485bc75 commit 6585fb7

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

src/cdk/a11y/focus-monitor.ts

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,7 @@ export class FocusMonitor {
6565
private _unregisterGlobalListeners = () => {};
6666

6767
/** The number of elements currently being monitored. */
68-
private get _monitoredElementCount() {
69-
return this._monitoredElementCountGetterSetterBacking;
70-
}
71-
private set _monitoredElementCount(n) {
72-
// Register global listeners when first element is monitored.
73-
if (!this._monitoredElementCountGetterSetterBacking && n) {
74-
this._registerGlobalListeners();
75-
}
76-
// Unregister global listeners when last element is unmonitored.
77-
else if (this._monitoredElementCountGetterSetterBacking && !n) {
78-
this._unregisterGlobalListeners();
79-
this._unregisterGlobalListeners = () => {};
80-
}
81-
this._monitoredElementCountGetterSetterBacking = n;
82-
}
83-
private _monitoredElementCountGetterSetterBacking = 0;
68+
private _monitoredElementCount = 0;
8469

8570
constructor(private _ngZone: NgZone, private _platform: Platform) {}
8671

@@ -126,7 +111,7 @@ export class FocusMonitor {
126111
subject: new Subject<FocusOrigin>()
127112
};
128113
this._elementInfo.set(element, info);
129-
this._monitoredElementCount++;
114+
this._incrementMonitoredElementCount();
130115

131116
// Start listening. We need to listen in capture phase since focus events don't bubble.
132117
let focusListener = (event: FocusEvent) => this._onFocus(event, element);
@@ -158,7 +143,7 @@ export class FocusMonitor {
158143

159144
this._setClasses(element);
160145
this._elementInfo.delete(element);
161-
this._monitoredElementCount--;
146+
this._decrementMonitoredElementCount();
162147
}
163148
}
164149

@@ -350,6 +335,22 @@ export class FocusMonitor {
350335
this._setClasses(element);
351336
elementInfo.subject.next(null);
352337
}
338+
339+
private _incrementMonitoredElementCount() {
340+
// Register global listeners when first element is monitored.
341+
if (++this._monitoredElementCount == 1) {
342+
this._registerGlobalListeners();
343+
}
344+
}
345+
346+
private _decrementMonitoredElementCount() {
347+
// Unregister global listeners when last element is unmonitored.
348+
if (!--this._monitoredElementCount) {
349+
this._unregisterGlobalListeners();
350+
this._unregisterGlobalListeners = () => {};
351+
}
352+
}
353+
353354
}
354355

355356

src/lib/sidenav/sidenav.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,4 @@ is clicked or <kbd>ESCAPE</kbd> is pressed. To add custom logic on backdrop clic
8181
<mat-sidenav-container (backdropClick)="customBackdropClickHandler()">
8282
<mat-sidenav disableClose (keydown)="customKeydownHandler($event)"></mat-sidenav>
8383
</mat-sidenav-container>
84-
```
84+
```

0 commit comments

Comments
 (0)