Skip to content

Commit 2c57055

Browse files
jlp-craigmorteneps1lonMatanBobi
authoredSep 14, 2023
feat: upgrade aria-query to 5.3.0 (#1241)
* feat: upgrade aria-query to 5.3.0 * fix: correctly handle img with empty alt * feat: pin `aria-query` version * chore: add accessibility-alt-text-bot (#1240) * chore: add accessibility-alt-text-bot * fix formatting issues * test: add coverage for footer to confirm it's expected implicit role as contentinfo --------- Co-authored-by: Sebastian Silbermann <silbermann.sebastian@gmail.com> Co-authored-by: Matan Borenkraout <Matanbobi@gmail.com>
1 parent 452097b commit 2c57055

File tree

7 files changed

+112
-53
lines changed

7 files changed

+112
-53
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Accessibility-alt-text-bot
2+
on:
3+
issues:
4+
types: [opened, edited]
5+
pull_request:
6+
types: [opened, edited]
7+
issue_comment:
8+
types: [created, edited]
9+
discussion:
10+
types: [created, edited]
11+
discussion_comment:
12+
types: [created, edited]
13+
14+
permissions:
15+
issues: write
16+
pull-requests: write
17+
discussions: write
18+
19+
jobs:
20+
accessibility_alt_text_bot:
21+
name: Check alt text is set on issue or pull requests
22+
runs-on: ubuntu-latest
23+
if:
24+
${{ github.event.issue || github.event.pull_request ||
25+
github.event.discussion }}
26+
steps:
27+
- name: Get action 'github/accessibility-alt-text-bot'
28+
uses: github/accessibility-alt-text-bot@v1.2.0 # Set to latest

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"@babel/code-frame": "^7.10.4",
6363
"@babel/runtime": "^7.12.5",
6464
"@types/aria-query": "^5.0.1",
65-
"aria-query": "5.1.3",
65+
"aria-query": "5.3.0",
6666
"chalk": "^4.1.0",
6767
"dom-accessibility-api": "^0.5.9",
6868
"lz-string": "^1.5.0",

‎src/__tests__/__snapshots__/role-helpers.js.snap

+26-26
Original file line numberDiff line numberDiff line change
@@ -52,32 +52,6 @@ Name "":
5252
data-testid="a-article"
5353
/>
5454
55-
--------------------------------------------------
56-
command:
57-
58-
Name "":
59-
<menuitem
60-
data-testid="a-menuitem-1"
61-
/>
62-
63-
Name "":
64-
<menuitem
65-
data-testid="a-menuitem-2"
66-
/>
67-
68-
--------------------------------------------------
69-
menuitem:
70-
71-
Name "":
72-
<menuitem
73-
data-testid="a-menuitem-1"
74-
/>
75-
76-
Name "":
77-
<menuitem
78-
data-testid="a-menuitem-2"
79-
/>
80-
8155
--------------------------------------------------
8256
list:
8357
@@ -216,5 +190,31 @@ Name "":
216190
data-testid="a-dd"
217191
/>
218192
193+
--------------------------------------------------
194+
img:
195+
196+
Name "":
197+
<img
198+
data-testid="a-img-1"
199+
src="http://example.com/image.png"
200+
/>
201+
202+
Name "a meaningful description":
203+
<img
204+
alt="a meaningful description"
205+
data-testid="a-img-3"
206+
src="http://example.com/image.png"
207+
/>
208+
209+
--------------------------------------------------
210+
presentation:
211+
212+
Name "":
213+
<img
214+
alt=""
215+
data-testid="a-img-2"
216+
src="http://example.com/image.png"
217+
/>
218+
219219
--------------------------------------------------
220220
`;

‎src/__tests__/role-helpers.js

+26-18
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function setup() {
1919
<header data-testid="a-header">Banner header</header>
2020
<section aria-label="a region" data-testid='named-section'>
2121
<a href="http://whatever.com" data-testid="a-link">link</a>
22-
<a>invalid link</a>
22+
<a data-testid="invalid-link">invalid link</a>
2323
2424
<nav data-testid='a-nav' />
2525
@@ -28,14 +28,6 @@ function setup() {
2828
<h3 data-testid='a-h3'>Tertiary Heading</h3>
2929
3030
<article data-testid='a-article'>
31-
<!-- menuitem is currently deprecated, but is the only
32-
tag currently that aria-query returns multiple roles for
33-
(roles: command, menuitem).
34-
It's used here in case a future tag also has multiple
35-
roles -->
36-
<menuitem data-testid='a-menuitem-1'>1</menuitem>
37-
<menuitem data-testid='a-menuitem-2'>2</menuitem>
38-
3931
<ul data-testid='a-list'>
4032
<li data-testid='a-list-item-1'>Item 1</li>
4133
<li data-testid='a-list-item-2'>Item 2</li>
@@ -66,12 +58,17 @@ function setup() {
6658
6759
<form data-testid="a-form" />
6860
<section data-testid="a-section" />
69-
</article>
70-
<dl>
61+
</article>
62+
<dl>
7163
<dt data-testid="a-dt">Term</dt>
7264
<dd data-testid="a-dd">Definition</dd>
73-
</dl>
65+
</dl>
66+
67+
<img src="http://example.com/image.png" data-testid='a-img-1'/>
68+
<img alt="" src="http://example.com/image.png" data-testid='a-img-2'/>
69+
<img alt="a meaningful description" src="http://example.com/image.png" data-testid='a-img-3'/>
7470
</section>
71+
<footer data-testid="a-footer">Contentinfo footer</footer>
7572
`)
7673

7774
return {
@@ -83,8 +80,6 @@ function setup() {
8380
h3: getByTestId('a-h3'),
8481
nav: getByTestId('a-nav'),
8582
article: getByTestId('a-article'),
86-
menuItem: getByTestId('a-menuitem-1'),
87-
menuItem2: getByTestId('a-menuitem-2'),
8883
aUl: getByTestId('a-list'),
8984
aLi1: getByTestId('a-list-item-1'),
9085
aLi2: getByTestId('a-list-item-2'),
@@ -107,6 +102,11 @@ function setup() {
107102
dt: getByTestId('a-dt'),
108103
dd: getByTestId('a-dd'),
109104
header: getByTestId('a-header'),
105+
invalidAnchor: getByTestId('invalid-link'),
106+
unnamedImg: getByTestId('a-img-1'),
107+
presentationImg: getByTestId('a-img-2'),
108+
namedImg: getByTestId('a-img-3'),
109+
footer: getByTestId('a-footer'),
110110
}
111111
}
112112

@@ -118,8 +118,6 @@ test('getRoles returns expected roles for various dom nodes', () => {
118118
h3,
119119
nav,
120120
article,
121-
menuItem,
122-
menuItem2,
123121
aUl,
124122
aLi1,
125123
aLi2,
@@ -142,6 +140,12 @@ test('getRoles returns expected roles for various dom nodes', () => {
142140
dd,
143141
dt,
144142
header,
143+
invalidAnchor,
144+
unnamedSection,
145+
unnamedImg,
146+
presentationImg,
147+
namedImg,
148+
footer,
145149
} = setup()
146150

147151
expect(getRoles(namedSection)).toEqual({
@@ -157,16 +161,20 @@ test('getRoles returns expected roles for various dom nodes', () => {
157161
cell: [td1, td2, td3],
158162
textbox: [input, input2, textarea],
159163
rowgroup: [tbody],
160-
command: [menuItem, menuItem2],
161-
menuitem: [menuItem, menuItem2],
162164
form: [namedForm],
163165
region: [namedSection],
164166
term: [dt],
165167
definition: [dd],
168+
generic: [invalidAnchor, unnamedSection],
169+
img: [unnamedImg, namedImg],
170+
presentation: [presentationImg],
166171
})
167172
expect(getRoles(header)).toEqual({
168173
banner: [header],
169174
})
175+
expect(getRoles(footer)).toEqual({
176+
contentinfo: [footer],
177+
})
170178
})
171179

172180
test('logRoles calls console.log with output from prettyRoles', () => {

‎src/__tests__/role.js

+18
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,12 @@ test('accessible name comparison is case sensitive', () => {
248248
<h1 />
249249
250250
--------------------------------------------------
251+
emphasis:
252+
253+
Name "":
254+
<em />
255+
256+
--------------------------------------------------
251257
252258
Ignored nodes: comments, script, style
253259
<div>
@@ -296,6 +302,12 @@ test('TextMatch serialization in error message', () => {
296302
<h1 />
297303
298304
--------------------------------------------------
305+
emphasis:
306+
307+
Name "":
308+
<em />
309+
310+
--------------------------------------------------
299311
300312
Ignored nodes: comments, script, style
301313
<div>
@@ -320,6 +332,12 @@ test('TextMatch serialization in error message', () => {
320332
<h1 />
321333
322334
--------------------------------------------------
335+
emphasis:
336+
337+
Name "":
338+
<em />
339+
340+
--------------------------------------------------
323341
324342
Ignored nodes: comments, script, style
325343
<div>

‎src/__tests__/suggestions.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,9 @@ test('escapes regular expressions in suggestion', () => {
196196
const {container} = renderIntoDocument(`
197197
<label for="superInput">inp-t lab^l w{th c+ars to esc\\pe</label>
198198
<input id="superInput" type="text" value="my super string +-('{}^$)" placeholder="should escape +-'(/" />
199-
<p>
199+
<span>
200200
Loading ... (1)
201-
</p>
201+
</span>
202202
<img src="foo.png" alt="The Problem (picture of a question mark)" data-testid="foo" />
203203
`)
204204

@@ -214,7 +214,7 @@ test('escapes regular expressions in suggestion', () => {
214214
).toString(),
215215
).toEqual(`getByAltText(/the problem \\(picture of a question mark\\)/i)`)
216216

217-
expect(getSuggestedQuery(container.querySelector('p')).toString()).toEqual(
217+
expect(getSuggestedQuery(container.querySelector('span')).toString()).toEqual(
218218
`getByText(/loading \\.\\.\\. \\(1\\)/i)`,
219219
)
220220

‎src/role-helpers.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,18 @@ function buildElementRoleList(elementRolesMap) {
8282
return `${name}${attributes
8383
.map(({name: attributeName, value, constraints = []}) => {
8484
const shouldNotExist = constraints.indexOf('undefined') !== -1
85-
if (shouldNotExist) {
86-
return `:not([${attributeName}])`
87-
} else if (value) {
85+
const shouldBeNonEmpty = constraints.indexOf('set') !== -1
86+
const hasExplicitValue = typeof value !== 'undefined'
87+
88+
if (hasExplicitValue) {
8889
return `[${attributeName}="${value}"]`
89-
} else {
90-
return `[${attributeName}]`
90+
} else if (shouldNotExist) {
91+
return `:not([${attributeName}])`
92+
} else if (shouldBeNonEmpty) {
93+
return `[${attributeName}]:not([${attributeName}=""])`
9194
}
95+
96+
return `[${attributeName}]`
9297
})
9398
.join('')}`
9499
}

0 commit comments

Comments
 (0)
Please sign in to comment.