-
Notifications
You must be signed in to change notification settings - Fork 127
Expand file tree
/
Copy pathtabindex-uses-button.js
More file actions
48 lines (43 loc) · 1.71 KB
/
Copy pathtabindex-uses-button.js
File metadata and controls
48 lines (43 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import {
hiddenFromAT
} from '../util';
export default [{
tagName: 'a',
msg: 'You have an anchor with a `tabIndex`, no `href` and no `role` DOM property. '
+ 'Add `role="button"` or better yet, use a `<button/>`.',
url: 'https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_button_role',
test(_, props) {
const hidden = hiddenFromAT(props);
const href = 'href' in props;
const button = props.role === 'button';
const tabIndex = 'tabIndex' in props;
return hidden || !tabIndex || href || button;
}
}];
export const fail = [{
when: 'anchor has tabIndex but no button',
// eslint-disable-next-line jsx-a11y/anchor-has-content,jsx-a11y/tabindex-no-positive
render: React => <a tabIndex={1} />
}];
export const pass = [{
when: 'anchor has no `tabIndex`',
// eslint-disable-next-line jsx-a11y/anchor-has-content
render: React => <a />
}, {
when: 'anchor has `role="button"`',
// eslint-disable-next-line jsx-a11y/anchor-has-content,jsx-a11y/tabindex-no-positive
render: React => <a role="button" tabIndex={1} />
}, {
when: 'anchor has a `href`',
// eslint-disable-next-line jsx-a11y/anchor-has-content,jsx-a11y/tabindex-no-positive
render: React => <a href="foo" tabIndex={1} />
}, {
when: 'the anchor is hidden',
// eslint-disable-next-line jsx-a11y/anchor-has-content,jsx-a11y/tabindex-no-positive
render: React => <a tabIndex={1} aria-hidden />
}];
export const description = `
When an anchor has a \`tabIndex\`, but no \`href\` and no \`role\` properties,
it is likely you are using it to emulate a \`button\`. Prefer using \`role="button"\`
or just use the \`<button\` element.
`;