Skip to content

Commit 48c70da

Browse files
kseamonandrewseguin
authored andcommitted
chore(a11y): Allow FocusTrap to be extended (#15770)
This will be used to allow tabbing from edit lenses to another table cell in popover edit.
1 parent d61036a commit 48c70da

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

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

Lines changed: 6 additions & 6 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

tools/public_api_guard/cdk/a11y.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ export declare type FocusOrigin = 'touch' | 'mouse' | 'keyboard' | 'program' | n
8787

8888
export declare class FocusTrap {
8989
enabled: boolean;
90+
protected endAnchorListener: () => boolean;
91+
protected startAnchorListener: () => boolean;
9092
constructor(_element: HTMLElement, _checker: InteractivityChecker, _ngZone: NgZone, _document: Document, deferAnchors?: boolean);
9193
attachAnchors(): boolean;
9294
destroy(): void;

0 commit comments

Comments
 (0)