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