Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(modalizer): stop focus from leaving trapped modal w/ no focusable descendants #403

Merged
merged 5 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions src/Modalizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ export class Modalizer
findPropsOut
);

if (next === null) {
ling1726 marked this conversation as resolved.
Show resolved Hide resolved
next = currentElement;
}

outOfDOMOrder = true;
} else {
outOfDOMOrder = !!findPropsOut.outOfDOMOrder;
Expand Down
25 changes: 25 additions & 0 deletions tests/Modalizer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,31 @@ describe("Modalizer", () => {
.pressTab()
.activeElement((el) => expect(el?.attributes.id).toBe("foo"));
});

it("if trapped, should not escape modalizer if it has no focusables", async () => {
await new BroTest.BroTest(
(
<div {...getTabsterAttribute({ root: {} })}>
<div
id="modal"
aria-label="modal"
{...getTabsterAttribute({
modalizer: { id: "modal", isTrapped: true },
})}
tabIndex={0}
>
Hello
</div>
</div>
)
)
.focusElement("#modal")
.activeElement((el) => expect(el?.textContent).toEqual("Hello"))
.pressTab()
.activeElement((el) =>
expect(el?.textContent).toEqual("Hello")
);
});
});
});

Expand Down
Loading