fix(csr): make dialog visibility testable and cover the focus trap
The focus trap and scroll lock shipped in 0.8.5 gated on getBoundingClientRect, which the test DOM always reports as zero, so a dialog never counted as open and none of that behaviour ran under test. focusableWithin had the same measurement gate and would have found no items even once the visibility check was fixed. Both now use the hidden attribute and the data-show marker the components already emit. Behaviour in a real browser is unchanged; the difference is that it is now covered. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -993,3 +993,40 @@ test("nested roving groups do not capture the outer group items", () => {
|
||||
a.dispatchEvent(new win.KeyboardEvent("keydown", { key: "ArrowRight", bubbles: true }));
|
||||
expect(doc.activeElement!.id).toBe("b");
|
||||
});
|
||||
|
||||
test("opening a modal dialog traps Tab inside it", () => {
|
||||
const win = mount(
|
||||
`<div>
|
||||
<button id="outside">Outside</button>
|
||||
<div data-show="true">
|
||||
<section role="dialog" aria-modal="true" tabindex="-1">
|
||||
<button id="first">First</button>
|
||||
<button id="last">Last</button>
|
||||
</section>
|
||||
</div>
|
||||
</div>`,
|
||||
);
|
||||
const doc = win.document;
|
||||
const last = doc.querySelector("#last") as unknown as HTMLElement;
|
||||
last.focus();
|
||||
last.dispatchEvent(new win.KeyboardEvent("keydown", { key: "Tab", bubbles: true }));
|
||||
expect(doc.activeElement!.id).toBe("first");
|
||||
});
|
||||
|
||||
test("a hidden dialog does not trap Tab", () => {
|
||||
const win = mount(
|
||||
`<div>
|
||||
<button id="outside">Outside</button>
|
||||
<div data-show="false">
|
||||
<section role="dialog" aria-modal="true" tabindex="-1">
|
||||
<button id="first">First</button>
|
||||
</section>
|
||||
</div>
|
||||
</div>`,
|
||||
);
|
||||
const doc = win.document;
|
||||
const outside = doc.querySelector("#outside") as unknown as HTMLElement;
|
||||
outside.focus();
|
||||
outside.dispatchEvent(new win.KeyboardEvent("keydown", { key: "Tab", bubbles: true }));
|
||||
expect(doc.activeElement!.id).toBe("outside");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user