From ed7fa0ed225522009e5560dac08fcff356e2098f Mon Sep 17 00:00:00 2001 From: Josh Duck Date: Sat, 14 Sep 2013 05:59:25 -0700 Subject: [PATCH] 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. --- src/core/ReactInputSelection.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/core/ReactInputSelection.js b/src/core/ReactInputSelection.js index a2e55fd8a1..7ee469e50e 100644 --- a/src/core/ReactInputSelection.js +++ b/src/core/ReactInputSelection.js @@ -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 }; } },