Skip to content

Commit 8faf1a8

Browse files
committed
chore(a11y): Allow FocusTrap to be extended
This will be used to allow tabbing from edit lenses to another table cell in popover edit.
1 parent 1a84770 commit 8faf1a8

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

src/cdk/a11y/focus-trap/focus-trap.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ export class FocusTrap {
3737
private _hasAttached = false;
3838

3939
// Event listeners for the anchors. Need to be regular functions so that we can unbind them later.
40-
private _startAnchorListener = () => this.focusLastTabbableElement();
41-
private _endAnchorListener = () => this.focusFirstTabbableElement();
40+
protected startAnchorListener = () => this.focusLastTabbableElement();
41+
protected endAnchorListener = () => this.focusFirstTabbableElement();
4242

4343
/** Whether the focus trap is active. */
4444
get enabled(): boolean { return this._enabled; }
@@ -70,15 +70,15 @@ export class FocusTrap {
7070
const endAnchor = this._endAnchor;
7171

7272
if (startAnchor) {
73-
startAnchor.removeEventListener('focus', this._startAnchorListener);
73+
startAnchor.removeEventListener('focus', this.startAnchorListener);
7474

7575
if (startAnchor.parentNode) {
7676
startAnchor.parentNode.removeChild(startAnchor);
7777
}
7878
}
7979

8080
if (endAnchor) {
81-
endAnchor.removeEventListener('focus', this._endAnchorListener);
81+
endAnchor.removeEventListener('focus', this.endAnchorListener);
8282

8383
if (endAnchor.parentNode) {
8484
endAnchor.parentNode.removeChild(endAnchor);
@@ -103,12 +103,12 @@ export class FocusTrap {
103103
this._ngZone.runOutsideAngular(() => {
104104
if (!this._startAnchor) {
105105
this._startAnchor = this._createAnchor();
106-
this._startAnchor!.addEventListener('focus', this._startAnchorListener);
106+
this._startAnchor!.addEventListener('focus', this.startAnchorListener);
107107
}
108108

109109
if (!this._endAnchor) {
110110
this._endAnchor = this._createAnchor();
111-
this._endAnchor!.addEventListener('focus', this._endAnchorListener);
111+
this._endAnchor!.addEventListener('focus', this.endAnchorListener);
112112
}
113113
});
114114

@@ -333,15 +333,10 @@ export class FocusTrap {
333333
/** Factory that allows easy instantiation of focus traps. */
334334
@Injectable({providedIn: 'root'})
335335
export class FocusTrapFactory {
336-
private _document: Document;
337-
338336
constructor(
339337
private _checker: InteractivityChecker,
340338
private _ngZone: NgZone,
341-
@Inject(DOCUMENT) _document: any) {
342-
343-
this._document = _document;
344-
}
339+
@Inject(DOCUMENT) private _document: any) {}
345340

346341
/**
347342
* Creates a focus-trapped region around the given element.

0 commit comments

Comments
 (0)