Skip to content

Commit c9a2416

Browse files
authored
Merge branch 'main' into feat/byrole-value
2 parents 29f9277 + 8c40a21 commit c9a2416

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

src/__tests__/ariaAttributes.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,28 @@ test('`expanded` throws on unsupported roles', () => {
3636
)
3737
})
3838

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+
3961
test('`checked: true|false` matches `checked` checkboxes', () => {
4062
const {getByRole} = renderIntoDocument(
4163
`<div>

src/queries/role.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
} from 'aria-query'
1111
import {
1212
computeAriaSelected,
13+
computeAriaBusy,
1314
computeAriaChecked,
1415
computeAriaPressed,
1516
computeAriaCurrent,
@@ -47,6 +48,7 @@ const queryAllByRole: AllByRole = (
4748
description,
4849
queryFallbacks = false,
4950
selected,
51+
busy,
5052
checked,
5153
pressed,
5254
current,
@@ -72,6 +74,16 @@ const queryAllByRole: AllByRole = (
7274
}
7375
}
7476

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+
7587
if (checked !== undefined) {
7688
// guard against unknown roles
7789
if (
@@ -203,6 +215,9 @@ const queryAllByRole: AllByRole = (
203215
if (selected !== undefined) {
204216
return selected === computeAriaSelected(element)
205217
}
218+
if (busy !== undefined) {
219+
return busy === computeAriaBusy(element)
220+
}
206221
if (checked !== undefined) {
207222
return checked === computeAriaChecked(element)
208223
}

src/role-helpers.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,15 @@ function computeAriaSelected(element) {
240240
return checkBooleanAttribute(element, 'aria-selected')
241241
}
242242

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+
243252
/**
244253
* @param {Element} element -
245254
* @returns {boolean | undefined} - false/true if (not)checked, undefined if not checked-able
@@ -369,6 +378,7 @@ export {
369378
prettyRoles,
370379
isInaccessible,
371380
computeAriaSelected,
381+
computeAriaBusy,
372382
computeAriaChecked,
373383
computeAriaPressed,
374384
computeAriaCurrent,

types/queries.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ export interface ByRoleOptions {
8080
* selected in the accessibility tree, i.e., `aria-selected="true"`
8181
*/
8282
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
8388
/**
8489
* If true only includes elements in the query set that are marked as
8590
* checked in the accessibility tree, i.e., `aria-checked="true"`

0 commit comments

Comments
 (0)