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 @@ -10,6 +10,7 @@ import {
10
10
} from 'aria-query'
11
11
import {
12
12
computeAriaSelected ,
13
+ computeAriaBusy ,
13
14
computeAriaChecked ,
14
15
computeAriaPressed ,
15
16
computeAriaCurrent ,
@@ -47,6 +48,7 @@ const queryAllByRole: AllByRole = (
47
48
description,
48
49
queryFallbacks = false ,
49
50
selected,
51
+ busy,
50
52
checked,
51
53
pressed,
52
54
current,
@@ -72,6 +74,16 @@ const queryAllByRole: AllByRole = (
72
74
}
73
75
}
74
76
77
+ if ( busy !== undefined ) {
78
+ // guard against unknown roles
79
+ if (
80
+ allRoles . get ( role as ARIARoleDefinitionKey ) ?. props [ 'aria-busy' ] ===
81
+ undefined
82
+ ) {
83
+ throw new Error ( `"aria-busy" is not supported on role "${ role } ".` )
84
+ }
85
+ }
86
+
75
87
if ( checked !== undefined ) {
76
88
// guard against unknown roles
77
89
if (
@@ -203,6 +215,9 @@ const queryAllByRole: AllByRole = (
203
215
if ( selected !== undefined ) {
204
216
return selected === computeAriaSelected ( element )
205
217
}
218
+ if ( busy !== undefined ) {
219
+ return busy === computeAriaBusy ( element )
220
+ }
206
221
if ( checked !== undefined ) {
207
222
return checked === computeAriaChecked ( element )
208
223
}
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
@@ -369,6 +378,7 @@ export {
369
378
prettyRoles ,
370
379
isInaccessible ,
371
380
computeAriaSelected ,
381
+ computeAriaBusy ,
372
382
computeAriaChecked ,
373
383
computeAriaPressed ,
374
384
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