1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | 'use strict';
|
12 |
|
13 | var DOMProperty = require('./DOMProperty');
|
14 | var ReactComponentTreeHook = require('react/lib/ReactComponentTreeHook');
|
15 |
|
16 | var warning = require('fbjs/lib/warning');
|
17 |
|
18 | var warnedProperties = {};
|
19 | var rARIA = new RegExp('^(aria)-[' + DOMProperty.ATTRIBUTE_NAME_CHAR + ']*$');
|
20 |
|
21 | function validateProperty(tagName, name, debugID) {
|
22 | if (warnedProperties.hasOwnProperty(name) && warnedProperties[name]) {
|
23 | return true;
|
24 | }
|
25 |
|
26 | if (rARIA.test(name)) {
|
27 | var lowerCasedName = name.toLowerCase();
|
28 | var standardName = DOMProperty.getPossibleStandardName.hasOwnProperty(lowerCasedName) ? DOMProperty.getPossibleStandardName[lowerCasedName] : null;
|
29 |
|
30 |
|
31 |
|
32 | if (standardName == null) {
|
33 | warnedProperties[name] = true;
|
34 | return false;
|
35 | }
|
36 |
|
37 | if (name !== standardName) {
|
38 | process.env.NODE_ENV !== 'production' ? warning(false, 'Unknown ARIA attribute %s. Did you mean %s?%s', name, standardName, ReactComponentTreeHook.getStackAddendumByID(debugID)) : void 0;
|
39 | warnedProperties[name] = true;
|
40 | return true;
|
41 | }
|
42 | }
|
43 |
|
44 | return true;
|
45 | }
|
46 |
|
47 | function warnInvalidARIAProps(debugID, element) {
|
48 | var invalidProps = [];
|
49 |
|
50 | for (var key in element.props) {
|
51 | var isValid = validateProperty(element.type, key, debugID);
|
52 | if (!isValid) {
|
53 | invalidProps.push(key);
|
54 | }
|
55 | }
|
56 |
|
57 | var unknownPropString = invalidProps.map(function (prop) {
|
58 | return '`' + prop + '`';
|
59 | }).join(', ');
|
60 |
|
61 | if (invalidProps.length === 1) {
|
62 | process.env.NODE_ENV !== 'production' ? warning(false, 'Invalid aria prop %s on <%s> tag. ' + 'For details, see https://fb.me/invalid-aria-prop%s', unknownPropString, element.type, ReactComponentTreeHook.getStackAddendumByID(debugID)) : void 0;
|
63 | } else if (invalidProps.length > 1) {
|
64 | process.env.NODE_ENV !== 'production' ? warning(false, 'Invalid aria props %s on <%s> tag. ' + 'For details, see https://fb.me/invalid-aria-prop%s', unknownPropString, element.type, ReactComponentTreeHook.getStackAddendumByID(debugID)) : void 0;
|
65 | }
|
66 | }
|
67 |
|
68 | function handleElement(debugID, element) {
|
69 | if (element == null || typeof element.type !== 'string') {
|
70 | return;
|
71 | }
|
72 | if (element.type.indexOf('-') >= 0 || element.props.is) {
|
73 | return;
|
74 | }
|
75 |
|
76 | warnInvalidARIAProps(debugID, element);
|
77 | }
|
78 |
|
79 | var ReactDOMInvalidARIAHook = {
|
80 | onBeforeMountComponent: function (debugID, element) {
|
81 | if (process.env.NODE_ENV !== 'production') {
|
82 | handleElement(debugID, element);
|
83 | }
|
84 | },
|
85 | onBeforeUpdateComponent: function (debugID, element) {
|
86 | if (process.env.NODE_ENV !== 'production') {
|
87 | handleElement(debugID, element);
|
88 | }
|
89 | }
|
90 | };
|
91 |
|
92 | module.exports = ReactDOMInvalidARIAHook; |
\ | No newline at end of file |