Skip to content

Commit ce57fd1

Browse files
committed
fix: anchors being created too soon
1 parent f6f9e61 commit ce57fd1

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/lib/core/a11y/focus-trap.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import {coerceBooleanProperty} from '../coercion/boolean-property';
2020
* This will be replaced with a more intelligent solution before the library is considered stable.
2121
*/
2222
export class FocusTrap {
23-
private _startAnchor: HTMLElement = this._createAnchor();
24-
private _endAnchor: HTMLElement = this._createAnchor();
23+
private _startAnchor: HTMLElement;
24+
private _endAnchor: HTMLElement;
2525

2626
/** Whether the focus trap is active. */
2727
get enabled(): boolean { return this._enabled; }
@@ -60,6 +60,14 @@ export class FocusTrap {
6060
* in the constructor, but can be deferred for cases like directives with `*ngIf`.
6161
*/
6262
attachAnchors(): void {
63+
if (!this._startAnchor) {
64+
this._startAnchor = this._createAnchor();
65+
}
66+
67+
if (!this._endAnchor) {
68+
this._endAnchor = this._createAnchor();
69+
}
70+
6371
this._ngZone.runOutsideAngular(() => {
6472
this._element
6573
.insertAdjacentElement('beforebegin', this._startAnchor)

0 commit comments

Comments
 (0)