Skip to content

Commit 9dff6ae

Browse files
committed
address comments
1 parent e3cd168 commit 9dff6ae

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

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

353354

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)