Skip to content

Commit ae4a28e

Browse files
authored
Merge pull request #77 from samirbr/master
Fixes "Cannot assign to read only property 'target' of object" error.
2 parents 929553f + 8b9f31f commit ae4a28e

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

lib/react-contenteditable.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,13 @@ var ContentEditable = function (_React$Component) {
9696
if (!this.htmlEl) return;
9797
var html = this.htmlEl.innerHTML;
9898
if (this.props.onChange && html !== this.lastHtml) {
99-
evt.target = { value: html };
99+
// Clone event with Object.assign to avoid
100+
// "Cannot assign to read only property 'target' of object"
101+
var evt = Object.assign({}, evt, {
102+
target: {
103+
value: html
104+
}
105+
});
100106
this.props.onChange(evt);
101107
}
102108
this.lastHtml = html;
@@ -107,4 +113,4 @@ var ContentEditable = function (_React$Component) {
107113
}(_react2.default.Component);
108114

109115
exports.default = ContentEditable;
110-
module.exports = exports['default'];
116+
module.exports = exports['default'];

src/react-contenteditable.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,13 @@ export default class ContentEditable extends React.Component {
5656
if (!this.htmlEl) return;
5757
var html = this.htmlEl.innerHTML;
5858
if (this.props.onChange && html !== this.lastHtml) {
59-
evt.target = { value: html };
59+
// Clone event with Object.assign to avoid
60+
// "Cannot assign to read only property 'target' of object"
61+
var evt = Object.assign({}, evt, {
62+
target: {
63+
value: html
64+
}
65+
});
6066
this.props.onChange(evt);
6167
}
6268
this.lastHtml = html;

0 commit comments

Comments
 (0)