File tree 4 files changed +52
-0
lines changed
4 files changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,28 @@ test('`expanded` throws on unsupported roles', () => {
36
36
)
37
37
} )
38
38
39
+ test ( '`busy` throws on unsupported roles' , ( ) => {
40
+ const { getByRole} = render (
41
+ `<div aria-busy="true" role="none">Hello, Dave!</div>` ,
42
+ )
43
+ expect ( ( ) =>
44
+ getByRole ( 'none' , { busy : true } ) ,
45
+ ) . toThrowErrorMatchingInlineSnapshot (
46
+ `"aria-busy" is not supported on role "none".` ,
47
+ )
48
+ } )
49
+
50
+ test ( '`busy: true|false` matches `busy` regions' , ( ) => {
51
+ const { getByRole} = renderIntoDocument (
52
+ `<div>
53
+ <div role="log" aria-busy="true" />
54
+ <div role="log" aria-busy="false" />
55
+ </div>` ,
56
+ )
57
+ expect ( getByRole ( 'log' , { busy : true } ) ) . toBeInTheDocument ( )
58
+ expect ( getByRole ( 'log' , { busy : false } ) ) . toBeInTheDocument ( )
59
+ } )
60
+
39
61
test ( '`checked: true|false` matches `checked` checkboxes' , ( ) => {
40
62
const { getByRole} = renderIntoDocument (
41
63
`<div>
Original file line number Diff line number Diff line change 9
9
} from 'aria-query'
10
10
import {
11
11
computeAriaSelected ,
12
+ computeAriaBusy ,
12
13
computeAriaChecked ,
13
14
computeAriaPressed ,
14
15
computeAriaCurrent ,
@@ -42,6 +43,7 @@ const queryAllByRole: AllByRole = (
42
43
description,
43
44
queryFallbacks = false ,
44
45
selected,
46
+ busy,
45
47
checked,
46
48
pressed,
47
49
current,
@@ -61,6 +63,16 @@ const queryAllByRole: AllByRole = (
61
63
}
62
64
}
63
65
66
+ if ( busy !== undefined ) {
67
+ // guard against unknown roles
68
+ if (
69
+ allRoles . get ( role as ARIARoleDefinitionKey ) ?. props [ 'aria-busy' ] ===
70
+ undefined
71
+ ) {
72
+ throw new Error ( `"aria-busy" is not supported on role "${ role } ".` )
73
+ }
74
+ }
75
+
64
76
if ( checked !== undefined ) {
65
77
// guard against unknown roles
66
78
if (
@@ -152,6 +164,9 @@ const queryAllByRole: AllByRole = (
152
164
if ( selected !== undefined ) {
153
165
return selected === computeAriaSelected ( element )
154
166
}
167
+ if ( busy !== undefined ) {
168
+ return busy === computeAriaBusy ( element )
169
+ }
155
170
if ( checked !== undefined ) {
156
171
return checked === computeAriaChecked ( element )
157
172
}
Original file line number Diff line number Diff line change @@ -240,6 +240,15 @@ function computeAriaSelected(element) {
240
240
return checkBooleanAttribute ( element , 'aria-selected' )
241
241
}
242
242
243
+ /**
244
+ * @param {Element } element -
245
+ * @returns {boolean } -
246
+ */
247
+ function computeAriaBusy ( element ) {
248
+ // https://www.w3.org/TR/wai-aria-1.1/#aria-busy
249
+ return element . getAttribute ( 'aria-busy' ) === 'true'
250
+ }
251
+
243
252
/**
244
253
* @param {Element } element -
245
254
* @returns {boolean | undefined } - false/true if (not)checked, undefined if not checked-able
@@ -333,6 +342,7 @@ export {
333
342
prettyRoles ,
334
343
isInaccessible ,
335
344
computeAriaSelected ,
345
+ computeAriaBusy ,
336
346
computeAriaChecked ,
337
347
computeAriaPressed ,
338
348
computeAriaCurrent ,
Original file line number Diff line number Diff line change @@ -80,6 +80,11 @@ export interface ByRoleOptions {
80
80
* selected in the accessibility tree, i.e., `aria-selected="true"`
81
81
*/
82
82
selected ?: boolean
83
+ /**
84
+ * If true only includes elements in the query set that are marked as
85
+ * busy in the accessibility tree, i.e., `aria-busy="true"`
86
+ */
87
+ busy ?: boolean
83
88
/**
84
89
* If true only includes elements in the query set that are marked as
85
90
* checked in the accessibility tree, i.e., `aria-checked="true"`
You can’t perform that action at this time.
0 commit comments