Skip to content

Commit 2426b23

Browse files
committed
Merge pull request #4 from wrakky/empty_attributes
Fixes #3 - Add boolean type attribute handling
2 parents 492441b + 4c32bf5 commit 2426b23

File tree

9 files changed

+241
-184
lines changed

9 files changed

+241
-184
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* List of boolean attributes
3+
* These attributes should have their React attribute value set to be the same as their name
4+
* E.g. <input disabled> = <input disabled>
5+
* <input disabled=""> = <input disabled>
6+
* <input disabled="disabled"> = <input disabled>
7+
* @type {Array}
8+
*/
9+
export default [
10+
'allowfullScreen',
11+
'async',
12+
'autoplay',
13+
'capture',
14+
'checked',
15+
'controls',
16+
'default',
17+
'defer',
18+
'disabled',
19+
'formnovalidate',
20+
'hidden',
21+
'loop',
22+
'multiple',
23+
'muted',
24+
'novalidate',
25+
'open',
26+
'readonly',
27+
'required',
28+
'reversed',
29+
'scoped',
30+
'seamless',
31+
'selected',
32+
'itemscope'
33+
];
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
/**
2+
* Mapping of standard HTML attributes to their React counterparts
3+
* List taken and reversed from react/src/renderers/dom/shared/HTMLDOMPropertyConfig.js
4+
* https://github.com/facebook/react/blob/c9c3c339b757682f1154f1c915eb55e6a8766933/src/renderers/dom/shared/HTMLDOMPropertyConfig.js
5+
* @type {Object}
6+
*/
7+
export default {
8+
/**
9+
* Standard Properties
10+
*/
11+
accept: 'accept',
12+
'accept-charset': 'acceptCharset',
13+
accesskey: 'accessKey',
14+
action: 'action',
15+
allowfullscreen: 'allowFullScreen',
16+
allowtransparency: 'allowTransparency',
17+
alt: 'alt',
18+
async: 'async',
19+
autocomplete: 'autoComplete',
20+
autoplay: 'autoPlay',
21+
capture: 'capture',
22+
cellpadding: 'cellPadding',
23+
cellspacing: 'cellSpacing',
24+
charset: 'charSet',
25+
challenge: 'challenge',
26+
checked: 'checked',
27+
classid: 'classID',
28+
class: 'className',
29+
cols: 'cols',
30+
colspan: 'colSpan',
31+
content: 'content',
32+
contenteditable: 'contentEditable',
33+
contextmenu: 'contextMenu',
34+
controls: 'controls',
35+
coords: 'coords',
36+
crossorigin: 'crossOrigin',
37+
data: 'data',
38+
datetime: 'dateTime',
39+
default: 'default',
40+
defer: 'defer',
41+
dir: 'dir',
42+
disabled: 'disabled',
43+
download: 'download',
44+
draggable: 'draggable',
45+
enctype: 'encType',
46+
form: 'form',
47+
formaction: 'formAction',
48+
formenctype: 'formEncType',
49+
formmethod: 'formMethod',
50+
formnovalidate: 'formNoValidate',
51+
formtarget: 'formTarget',
52+
frameborder: 'frameBorder',
53+
headers: 'headers',
54+
height: 'height',
55+
hidden: 'hidden',
56+
high: 'high',
57+
href: 'href',
58+
hreflang: 'hrefLang',
59+
for: 'htmlFor',
60+
'http-equiv': 'httpEquiv',
61+
icon: 'icon',
62+
id: 'id',
63+
inputmode: 'inputMode',
64+
integrity: 'integrity',
65+
is: 'is',
66+
keyparams: 'keyParams',
67+
keytype: 'keyType',
68+
kind: 'kind',
69+
label: 'label',
70+
lang: 'lang',
71+
list: 'list',
72+
loop: 'loop',
73+
low: 'low',
74+
manifest: 'manifest',
75+
marginheight: 'marginHeight',
76+
marginwidth: 'marginWidth',
77+
max: 'max',
78+
maxlength: 'maxLength',
79+
media: 'media',
80+
mediagroup: 'mediaGroup',
81+
method: 'method',
82+
min: 'min',
83+
minlength: 'minLength',
84+
multiple: 'multiple',
85+
muted: 'muted',
86+
name: 'name',
87+
nonce: 'nonce',
88+
novalidate: 'noValidate',
89+
open: 'open',
90+
optimum: 'optimum',
91+
pattern: 'pattern',
92+
placeholder: 'placeholder',
93+
poster: 'poster',
94+
preload: 'preload',
95+
radiogroup: 'radioGroup',
96+
readonly: 'readOnly',
97+
rel: 'rel',
98+
required: 'required',
99+
reversed: 'reversed',
100+
role: 'role',
101+
rows: 'rows',
102+
rowspan: 'rowSpan',
103+
sandbox: 'sandbox',
104+
scope: 'scope',
105+
scoped: 'scoped',
106+
scrolling: 'scrolling',
107+
seamless: 'seamless',
108+
selected: 'selected',
109+
shape: 'shape',
110+
size: 'size',
111+
sizes: 'sizes',
112+
span: 'span',
113+
spellcheck: 'spellCheck',
114+
src: 'src',
115+
srcdoc: 'srcDoc',
116+
srclang: 'srcLang',
117+
srcset: 'srcSet',
118+
start: 'start',
119+
step: 'step',
120+
style: 'style',
121+
summary: 'summary',
122+
tabindex: 'tabIndex',
123+
target: 'target',
124+
title: 'title',
125+
type: 'type',
126+
usemap: 'useMap',
127+
value: 'value',
128+
width: 'width',
129+
wmode: 'wmode',
130+
wrap: 'wrap',
131+
/**
132+
* RDFa Properties
133+
*/
134+
about: 'about',
135+
datatype: 'datatype',
136+
inlist: 'inlist',
137+
prefix: 'prefix',
138+
property: 'property',
139+
resource: 'resource',
140+
typeof: 'typeof',
141+
vocab: 'vocab',
142+
/**
143+
* Non-standard Properties
144+
*/
145+
autocapitalize: 'autoCapitalize',
146+
autocorrect: 'autoCorrect',
147+
autosave: 'autoSave',
148+
color: 'color',
149+
itemprop: 'itemProp',
150+
itemscope: 'itemScope',
151+
itemtype: 'itemType',
152+
itemid: 'itemID',
153+
itemref: 'itemRef',
154+
results: 'results',
155+
security: 'security',
156+
unselectable: 'unselectable',
157+
autofocus: 'autoFocus'
158+
};
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
const voidElements = [
1+
/**
2+
* List of void elements
3+
* These elements are not allowed to have children
4+
* @type {Array}
5+
*/
6+
export default [
27
'area',
38
'base',
49
'br',
@@ -16,9 +21,3 @@ const voidElements = [
1621
'track',
1722
'wbr'
1823
];
19-
20-
export default function isVoidElement(element) {
21-
22-
return voidElements.indexOf(element) >= 0;
23-
24-
}

src/elementTypes/TagElementType.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import ProcessNodes from '../utils/ProcessNodes';
33
import GeneratePropsFromAttributes from '../utils/GeneratePropsFromAttributes';
44
import TransformTagName from '../utils/TransformTagName';
5-
import isVoidElement from '../utils/isVoidElement';
5+
import VoidElements from '../dom/elements/VoidElements';
66

77
/**
88
* Converts any element (excluding style - see StyleElementType - and script) to a react element.
@@ -21,7 +21,7 @@ export default function TagElementType(node, key) {
2121

2222
// If the node is not a void element and has children then process them
2323
let children = null;
24-
if (!isVoidElement(tagName)) {
24+
if (VoidElements.indexOf(tagName) === -1) {
2525
children = ProcessNodes(node.children);
2626
}
2727

0 commit comments

Comments
 (0)