Skip to content

Commit 016f9c2

Browse files
committed
chore: more null checks
1 parent ce57fd1 commit 016f9c2

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ export class FocusTrap {
2727
get enabled(): boolean { return this._enabled; }
2828
set enabled(val: boolean) {
2929
this._enabled = val;
30-
this._startAnchor.tabIndex = this._endAnchor.tabIndex = this._enabled ? 0 : -1;
30+
31+
if (this._startAnchor && this._endAnchor) {
32+
this._startAnchor.tabIndex = this._endAnchor.tabIndex = this._enabled ? 0 : -1;
33+
}
3134
}
3235
private _enabled: boolean = true;
3336

@@ -44,11 +47,11 @@ export class FocusTrap {
4447

4548
/** Destroys the focus trap by cleaning up the anchors. */
4649
destroy() {
47-
if (this._startAnchor.parentNode) {
50+
if (this._startAnchor && this._startAnchor.parentNode) {
4851
this._startAnchor.parentNode.removeChild(this._startAnchor);
4952
}
5053

51-
if (this._endAnchor.parentNode) {
54+
if (this._endAnchor && this._endAnchor.parentNode) {
5255
this._endAnchor.parentNode.removeChild(this._endAnchor);
5356
}
5457

0 commit comments

Comments
 (0)