|
1 | 1 | var assertions = require('./assertions'); |
2 | 2 |
|
3 | | -var assertAccessibility = (tagName, props, children) => { |
| 3 | +var deviceMatches = (test, deviceFilter) => { |
| 4 | + if (!test.device) { |
| 5 | + return true; |
| 6 | + } |
| 7 | + |
| 8 | + return (deviceFilter.indexOf(test.device) != -1); |
| 9 | +}; |
| 10 | + |
| 11 | +var assertAccessibility = (tagName, props, children, deviceFilter) => { |
4 | 12 | var key; |
5 | 13 | var failures = []; |
6 | | - |
7 | 14 | var tagTests = assertions.tags[tagName] || []; |
8 | 15 | for (key in tagTests) |
9 | | - if (tagTests[key] && !tagTests[key].test(tagName, props, children)) |
| 16 | + if (tagTests[key] && deviceMatches(tagTests[key], deviceFilter) && !tagTests[key].test(tagName, props, children)) |
10 | 17 | failures.push(tagTests[key].msg); |
11 | 18 |
|
12 | 19 | var propTests; |
13 | 20 | for (var propName in props) { |
14 | 21 | if (props[propName] === null || props[propName] === undefined) continue; |
15 | 22 | propTests = assertions.props[propName] || []; |
16 | 23 | for (key in propTests) |
17 | | - if (propTests[key] && !propTests[key].test(tagName, props, children)) |
| 24 | + if (propTests[key] && deviceMatches(propTests[key], deviceFilter) && !propTests[key].test(tagName, props, children)) |
18 | 25 | failures.push(propTests[key].msg); |
19 | 26 | } |
20 | 27 | return failures; |
@@ -104,13 +111,14 @@ var reactA11y = (React, options) => { |
104 | 111 | totalFailures = []; |
105 | 112 | var _createElement = React.createElement; |
106 | 113 | var includeSrcNode = options && !!options.includeSrcNode; |
| 114 | + var deviceFilter = options && options.device || ['desktop']; |
107 | 115 |
|
108 | 116 | React.createElement = (type, _props, ...children) => { |
109 | 117 | var props = _props || {}; |
110 | 118 | var reactEl; |
111 | 119 |
|
112 | 120 | if (typeof type === 'string') { |
113 | | - let failures = assertAccessibility(type, props, children); |
| 121 | + let failures = assertAccessibility(type, props, children, deviceFilter); |
114 | 122 | if (failures.length) { |
115 | 123 | // Generate an id if one doesn't exist |
116 | 124 | props.id = (props.id || 'a11y-' + nextId++); |
|
0 commit comments