Skip to content

Commit 32e394c

Browse files
fix: ensure alertdialog considered for inert logic (#132)
1 parent 9b957f1 commit 32e394c

File tree

3 files changed

+59
-3
lines changed

3 files changed

+59
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@guidepup/virtual-screen-reader",
3-
"version": "0.30.0",
3+
"version": "0.30.1",
44
"description": "Virtual Screen Reader driver for unit test automation.",
55
"author": "Craig Morten <[email protected]>",
66
"license": "MIT",

src/getNodeAccessibilityData/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { getAccessibleDescription } from "./getAccessibleDescription";
44
import { getAccessibleName } from "./getAccessibleName";
55
import { getAccessibleValue } from "./getAccessibleValue";
66
import { getLocalName } from "../getLocalName";
7+
import { isDialogRole } from "../isDialogRole";
78
import { isElement } from "../isElement";
89

910
// TODO: swap out with the html-aria package once it supports `dpub-aam` /
@@ -93,7 +94,7 @@ const getIsInert = ({
9394
getLocalName(node) === "dialog" && node.hasAttribute("open");
9495

9596
const isNonNativeModalDialog =
96-
role === "dialog" && node.hasAttribute("aria-modal");
97+
isDialogRole(role) && node.hasAttribute("aria-modal");
9798

9899
const isModalDialog = isNonNativeModalDialog || isNativeModalDialog;
99100
const isExplicitInert = node.hasAttribute("inert");

test/int/inert.int.test.ts

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ describe("inert", () => {
77
document.body.innerHTML = "";
88
});
99

10-
it("should hide inert elements from the tree unless they are modal dialog (non-native)", async () => {
10+
it("should hide inert elements from the tree unless they are modal dialog (non-native dialog)", async () => {
1111
document.body.innerHTML = `<p>visible paragraph</p>
1212
<p inert>hidden paragraph</p>
1313
@@ -116,4 +116,59 @@ describe("inert", () => {
116116
"end of dialog, visible dialog heading 5",
117117
]);
118118
});
119+
120+
it("should hide inert elements from the tree unless they are modal dialog (alertdialog)", async () => {
121+
document.body.innerHTML = `<p>visible paragraph</p>
122+
<p inert>hidden paragraph</p>
123+
124+
<!-- Explicitly inert modal dialog should be inert -->
125+
<div aria-labelledby="dialog-heading-1" aria-modal="true" inert role="alertdialog">
126+
<h1 id="dialog-heading-1">hidden dialog heading 1</h1>
127+
</div>
128+
129+
<!-- Explicitly inert dialog should be inert -->
130+
<div aria-labelledby="dialog-heading-2" inert role="alertdialog">
131+
<h1 id="dialog-heading-2">hidden dialog heading 2</h1>
132+
</div>
133+
134+
<div inert>
135+
<p>hidden paragraph</p>
136+
137+
<!-- Explicitly inert modal dialog should be inert -->
138+
<div aria-labelledby="dialog-heading-3" aria-modal="true" inert role="alertdialog">
139+
<h1 id="dialog-heading-3">hidden dialog heading 3</h1>
140+
</div>
141+
142+
<!-- Non-modal dialog should inherit inert -->
143+
<div aria-labelledby="dialog-heading-4" role="alertdialog">
144+
<h1 id="dialog-heading-4">hidden dialog heading 4</h1>
145+
</div>
146+
147+
<!-- Modal dialog should not inherit inert -->
148+
<div aria-labelledby="dialog-heading-5" aria-modal="true" role="alertdialog">
149+
<h1 id="dialog-heading-5">visible dialog heading 5</h1>
150+
</div>
151+
</div>
152+
`;
153+
154+
await virtual.start({ container: document.body });
155+
156+
while (
157+
(await virtual.lastSpokenPhrase()) !==
158+
"end of alertdialog, visible dialog heading 5, modal"
159+
) {
160+
await virtual.next();
161+
}
162+
163+
expect(await virtual.spokenPhraseLog()).toEqual([
164+
"document",
165+
"paragraph",
166+
"visible paragraph",
167+
"end of paragraph",
168+
"alertdialog, visible dialog heading 5, modal",
169+
"alertdialog, visible dialog heading 5, modal",
170+
"heading, visible dialog heading 5, level 1",
171+
"end of alertdialog, visible dialog heading 5, modal",
172+
]);
173+
});
119174
});

0 commit comments

Comments
 (0)