Skip to content

Commit

Permalink
Only set node.value if it's equal to initialValue
Browse files Browse the repository at this point in the history
In IE11 textContent is populated when the placeholder attribute is set.
Without this check, we end up setting node.value equal to the
placeholder text, causing the textarea to actually render with the text
inside.

This check makes sure that textContent is equal to our expected
initialValue, which should be the case when using defaultValue.
  • Loading branch information
Brandon Dail committed Oct 19, 2016
1 parent 18d418a commit 07998a5
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/renderers/dom/client/wrappers/ReactDOMTextarea.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,15 @@ var ReactDOMTextarea = {
// This is in postMount because we need access to the DOM node, which is not
// available until after the component has mounted.
var node = ReactDOMComponentTree.getNodeFromInstance(inst);

// Warning: node.value may be the empty string at this point (IE11) if placeholder is set.
node.value = node.textContent; // Detach value from defaultValue
var textContent = node.textContent;

// Only set node.value if textContent is equal to the expected
// initial value. In IE10/IE11 ther eis a bug where the placeholder attribute
// will populate textContent as well.
// https://developer.microsoft.com/microsoft-edge/platform/issues/101525/
if (textContent === inst._wrapperState.initialValue) {
node.value = textContent;
}
},
};

Expand Down

0 comments on commit 07998a5

Please sign in to comment.