Skip to content

Commit 41a5566

Browse files
committed
inlined most the assertions
1 parent a237873 commit 41a5566

1 file changed

Lines changed: 13 additions & 69 deletions

File tree

lib/assertions.js

Lines changed: 13 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -11,63 +11,11 @@ var hasAlt = (props) => {
1111
return typeof props.alt === 'string';
1212
};
1313

14-
var altIsRedundant = (alt) => {
15-
return alt.match('image');
16-
};
17-
1814
var isInteractive = (tagName, props) => {
1915
var tag = INTERACTIVE[tagName];
2016
return (typeof tagName === 'function') ? tag(props) : tag;
2117
};
2218

23-
var hasClick = (props) => {
24-
return typeof props.onClick === 'function';
25-
};
26-
27-
var hasRole = (props) => {
28-
return typeof props.role === 'string';
29-
};
30-
31-
var hasTabIndex = (props) => {
32-
return typeof props.tabIndex === 'string';
33-
};
34-
35-
var needsAriaRole = (tagName, props) => {
36-
return (
37-
!isInteractive(tagName, props) &&
38-
hasClick(props) &&
39-
!hasRole(props)
40-
);
41-
};
42-
43-
var needsTabIndex = (tagName, props) => {
44-
return (
45-
!isInteractive(tagName, props) &&
46-
hasClick(props) &&
47-
!hasTabIndex(props)
48-
);
49-
};
50-
51-
var hrefIsHash = (props) => {
52-
return props.href === '#';
53-
};
54-
55-
var needsButtonRole = (props) => {
56-
return (
57-
hasClick(props) &&
58-
hrefIsHash(props)
59-
);
60-
};
61-
62-
63-
var hasLabel = (props) => {
64-
return typeof props['aria-label'] === 'string';
65-
};
66-
67-
var hasLabelledBy = (props) => {
68-
return typeof props['aria-labelled-by'] === 'string';
69-
};
70-
7119
var hasChildTextNode = (props, children) => {
7220
var hasText = false;
7321
React.Children.forEach(children, (child) => {
@@ -81,37 +29,33 @@ var hasChildTextNode = (props, children) => {
8129
return hasText;
8230
};
8331

84-
var needsLabel = (props, children) => {
85-
return (
86-
hasClick(props) &&
87-
!(
88-
hasLabel(props) ||
89-
hasLabelledBy(props) ||
90-
hasChildTextNode(props, children)
91-
)
92-
);
93-
};
94-
9532
exports.props = {
9633
onClick: {
9734
NO_ROLE: {
9835
msg: 'You have a click handler on a non-interactive element but no `role` DOM property. It will be unclear what this element is supposed to do to a screen-reader user. http://www.w3.org/TR/wai-aria/roles#role_definitions',
9936
test (tagName, props, children) {
100-
return !needsAriaRole(tagName, props);
37+
return !(!isInteractive(tagName, props) && !props.role);
10138
}
10239
},
10340

10441
NO_TABINDEX: {
10542
msg: 'You have a click handler on a non-interactive element but no `tabIndex` DOM property. The element will not be navigable or interactive by keyboard users. http://www.w3.org/TR/wai-aria-practices/#focus_tabindex',
10643
test (tagName, props, children) {
107-
return !needsTabIndex(tagName, props);
44+
return !(
45+
!isInteractive(tagName, props) &&
46+
!props.tabIndex
47+
);
10848
}
10949
},
11050

11151
NO_LABEL: {
11252
msg: 'You have a click handler on an element with no screen-readable text. Add `aria-label` or `aria-labelled-by` attribute, or put some text in the element.',
11353
test (tagName, props, children) {
114-
return !needsLabel(props, children);
54+
return (
55+
props['aria-label'] ||
56+
props['aria-labelled-by'] ||
57+
hasChildTextNode(props, children)
58+
);
11559
}
11660
},
11761

@@ -135,9 +79,9 @@ exports.props = {
13579
exports.tags = {
13680
a: {
13781
HASH_HREF_NEEDS_BUTTON: {
138-
msg: 'You have a click handler on an anchor with an `href` DOM property and no `role` DOM property. Add `role="button"` to your markup, or you should probably just use a `<button/>`.',
82+
msg: 'You have an anchor with `href="#"` and no `role` DOM property. Add `role="button"` or better yet, use a `<button/>`.',
13983
test (tagName, props, children) {
140-
return !needsButtonRole(props);
84+
return !(!props.role && props.href === '#');
14185
}
14286
}
14387
},
@@ -154,7 +98,7 @@ exports.tags = {
15498
// TODO: have some way to set localization strings to match against
15599
msg: 'Screen-readers already announce `img` tags as an image, you don\'t need to use the word "image" in the description',
156100
test (tagName, props, children) {
157-
return !(hasAlt(props) && altIsRedundant(props.alt));
101+
return !(hasAlt(props) && props.alt.match('image'));
158102
}
159103
}
160104
}

0 commit comments

Comments
 (0)