html-react-parser 1.4.2 → 1.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -28,11 +28,19 @@ module.exports = function attributesToProps(attributes) {
28
28
 
29
29
  // convert HTML/SVG attribute to React prop
30
30
  attributeNameLowerCased = attributeName.toLowerCase();
31
- propName = reactProperty.possibleStandardNames[attributeNameLowerCased];
31
+ propName = getPropName(attributeNameLowerCased);
32
32
 
33
33
  if (propName) {
34
- props[propName] = attributeValue;
35
34
  propertyInfo = reactProperty.getPropertyInfo(propName);
35
+
36
+ // convert attribute to uncontrolled component prop (e.g., `value` to `defaultValue`)
37
+ // https://reactjs.org/docs/uncontrolled-components.html
38
+ if (propName === 'checked' || propName === 'value') {
39
+ propName = getPropName('default' + attributeNameLowerCased);
40
+ }
41
+
42
+ props[propName] = attributeValue;
43
+
36
44
  switch (propertyInfo && propertyInfo.type) {
37
45
  case reactProperty.BOOLEAN:
38
46
  props[propName] = true;
@@ -57,3 +65,13 @@ module.exports = function attributesToProps(attributes) {
57
65
 
58
66
  return props;
59
67
  };
68
+
69
+ /**
70
+ * Gets prop name from lowercased attribute name.
71
+ *
72
+ * @param {string} attributeName - Lowercased attribute name.
73
+ * @return {string}
74
+ */
75
+ function getPropName(attributeName) {
76
+ return reactProperty.possibleStandardNames[attributeName];
77
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "html-react-parser",
3
- "version": "1.4.2",
3
+ "version": "1.4.3",
4
4
  "description": "HTML to React parser.",
5
5
  "author": "Mark <mark@remarkablemark.org>",
6
6
  "main": "index.js",
@@ -52,21 +52,21 @@
52
52
  "@typescript-eslint/parser": "5.6.0",
53
53
  "benchmark": "2.1.4",
54
54
  "dtslint": "4.2.1",
55
- "eslint": "8.4.0",
55
+ "eslint": "8.4.1",
56
56
  "eslint-plugin-prettier": "4.0.0",
57
57
  "husky": "7.0.4",
58
- "jest": "27.4.3",
58
+ "jest": "27.4.4",
59
59
  "lint-staged": "12.1.2",
60
60
  "pinst": "2.1.6",
61
- "preact": "10.6.2",
61
+ "preact": "10.6.4",
62
62
  "prettier": "2.5.1",
63
63
  "react": "17.0.2",
64
64
  "react-dom": "17.0.2",
65
65
  "rimraf": "3.0.2",
66
- "rollup": "2.60.2",
66
+ "rollup": "2.61.1",
67
67
  "rollup-plugin-terser": "7.0.2",
68
68
  "size-limit": "7.0.4",
69
- "typescript": "4.5.2"
69
+ "typescript": "4.5.3"
70
70
  },
71
71
  "peerDependencies": {
72
72
  "react": "0.14 || 15 || 16 || 17"