diff --git a/src/htmltojsx.js b/src/htmltojsx.js
index 62211e8..d3f4f58 100644
--- a/src/htmltojsx.js
+++ b/src/htmltojsx.js
@@ -22,11 +22,19 @@ var NODE_TYPE = {
TEXT: 3,
COMMENT: 8
};
+
var ATTRIBUTE_MAPPING = {
'for': 'htmlFor',
'class': 'className'
};
+var ELEMENT_ATTRIBUTE_MAPPING = {
+ 'input': {
+ 'checked': 'defaultChecked',
+ 'value': 'defaultValue'
+ }
+};
+
/**
* Repeats a string a certain number of times.
* Also: the future is bright and consists of native string repetition:
@@ -391,7 +399,12 @@ HTMLtoJSX.prototype = {
case 'style':
return this._getStyleAttribute(attribute.value);
default:
- var name = ATTRIBUTE_MAPPING[attribute.name] || attribute.name;
+ var tagName = node.tagName.toLowerCase();
+ var name =
+ (ELEMENT_ATTRIBUTE_MAPPING[tagName] &&
+ ELEMENT_ATTRIBUTE_MAPPING[tagName][attribute.name]) ||
+ ATTRIBUTE_MAPPING[attribute.name] ||
+ attribute.name;
var result = name;
// Numeric values should be output as {123} not "123"
diff --git a/test/htmltojsx-test.js b/test/htmltojsx-test.js
index 8fb7301..5f71ac4 100644
--- a/test/htmltojsx-test.js
+++ b/test/htmltojsx-test.js
@@ -81,6 +81,24 @@ describe('htmltojsx', function() {
].join('\n'));
});
+ it('should set "value" to "defaultValue" to allow input editing', function() {
+ var converter = new HTMLtoJSX({ createClass: false });
+ expect(converter.convert('').trim())
+ .toBe('');
+ });
+
+ it('should not set "value" to "defaultValue" for non- elements', function() {
+ var converter = new HTMLtoJSX({ createClass: false });
+ expect(converter.convert('').trim())
+ .toBe('');
+ });
+
+ it('should set "checked" to "defaultChecked" to allow box checking', function() {
+ var converter = new HTMLtoJSX({ createClass: false });
+ expect(converter.convert('').trim())
+ .toBe('');
+ });
+
describe('Attribute transformations', function() {
it('should convert basic "style" attributes', function() {
var converter = new HTMLtoJSX({ createClass: false });