Stop ReactInputSelection breaking in IE8

In the IE code path the method assumed that the input.value property
was non-null. A quick fix is to use either value or innerText; which means
the same code can be shared for textarea and contentEditable components.

The code is slightly buggy because the range.parentElement() !== input check
will fail for contentEditable components when the focus within a deep DOM tree.
This commit is contained in:
Josh Duck
2013-09-14 05:59:25 -07:00
committed by Paul O’Shannessy
parent 3e4302e6ae
commit ed7fa0ed22
+8 -4
View File
@@ -18,6 +18,8 @@
"use strict";
var getTextContentAccessor = require('getTextContentAccessor');
// It is not safe to read the document.activeElement property in IE if there's
// nothing focused.
function getActiveElement() {
@@ -80,8 +82,9 @@ var ReactInputSelection = {
},
/**
* @getSelection: Gets the selection bounds of a textarea or input.
* -@input: Look up selection bounds of this input or textarea
* @getSelection: Gets the selection bounds of a focused textarea, input or
* contentEditable node.
* -@input: Look up selection bounds of this input
* -@return {start: selectionStart, end: selectionEnd}
*/
getSelection: function(input) {
@@ -114,7 +117,8 @@ var ReactInputSelection = {
return {start: 0, end: 0};
}
var length = input.value.length;
var value = input.value || input[getTextContentAccessor()];
var length = value.length;
if (input.nodeName === 'INPUT') {
return {
@@ -129,7 +133,7 @@ var ReactInputSelection = {
range2.setEndPoint('StartToStart', range);
return {
start: length - range2.text.length,
end: end
end: end
};
}
},