Skip to content

Commit

Permalink
fix: fix stacked overlays inert mechanism (#2736)
Browse files Browse the repository at this point in the history
  • Loading branch information
dauriamarco committed Jun 11, 2024
1 parent f732a6d commit b611271
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/elements/core/overlay/overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,21 @@ const getAncestors = (overlay: HTMLElement, root: HTMLElement): HTMLElement[] =>
return ancestors;
};

const setDataSbbInert = (el: HTMLElement): void => {
el.setAttribute(
'data-sbb-inert',
`${+(el.getAttribute('data-sbb-inert') ?? undefined)! + 1 || 0}`,
);
};

/**
* Set the inert and the data-sbb-inert attributes.
*/
const setSbbInert = (el: HTMLElement): void => {
if (!el.inert) {
el.inert = true;
if (el.matches(IS_OPEN_OVERLAY_QUERY)) {
el.setAttribute('data-sbb-inert', `${+el.getAttribute('data-sbb-inert')! + 1 || 0}`);
setDataSbbInert(el);
} else {
el.toggleAttribute('data-sbb-inert', true);
}
Expand Down Expand Up @@ -92,7 +99,7 @@ export function applyInertMechanism(overlay: HTMLElement): void {
) as HTMLElement[],
);
if (el.matches(IS_OPEN_OVERLAY_QUERY)) {
el.setAttribute('data-sbb-inert', `${+el.getAttribute('data-sbb-inert')! + 1 || 0}`);
setDataSbbInert(el);
}
}

Expand Down

0 comments on commit b611271

Please sign in to comment.