Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/overlay/src/overlay-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ export class OverlayStack {

public constructor() {
this.addEventListeners();
this.initTabTrapping();
}

private canTabTrap = true;
private trappingInited = false;
private tabTrapper!: HTMLElement;
private overlayHolder!: HTMLElement;

Expand Down Expand Up @@ -90,6 +90,11 @@ export class OverlayStack {
}

private startTabTrapping(): void {
if (!this.trappingInited) {
this.initTabTrapping();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might work a little better to have a disableTabTrapping option. I'd rather not cause all clients to do extra work if they're not running into the Safari issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the boolean check, I don't particularly count this as extra work. I had previously been making this call in the constructor() which means if an application doesn't use tab trapping this change now means they do less work.

A universal disabledTabTrapping options is interesting, however. Where do you think you'd want to apply that? Currently, there are no packages that leverage tab trapping on their own (IIRC), so an implementing app could also not use type="modal" (or manage their own usage of that value) and this would never be needed in that application.

This does point to the benefit of a more durable solution. To prevent such a solution from adding work to non-Safari browsers, what are you thoughts on in component browser checking?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh never mind -- I just misunderstood this logic. I'm not even sure how 🙈. This looks perfect.

this.trappingInited = true;
}
/* c8 ignore next 3 */
if (!this.canTabTrap) {
return;
}
Expand All @@ -99,7 +104,7 @@ export class OverlayStack {

private stopTabTrapping(): void {
/* c8 ignore next 3 */
if (!this.canTabTrap) {
if (!this.canTabTrap || !this.trappingInited) {
return;
}
this.tabTrapper.removeAttribute('tabindex');
Expand Down