Make SelectEventPlugin not throw for range inputs
Accessing .selectionStart on a non-text input will throw (see http://www.w3.org/TR/2009/WD-html5-20090423/editing.html#textFieldSelection), so check that the input has selection capabilities before accessing the property. Fixes #437.
Ben Alpert committed
Oct 20, 2013 at 14:36 UTC
893fba8373b648fa0a1370bcd3071250136dfad4
1 file changed
+3
-1
src/eventPlugins/SelectEventPlugin.js
+3
-1
@@ -22,6 +22,7 @@ var EventConstants = require('EventConstants');
22
var EventPluginHub = require('EventPluginHub');
23
var EventPropagators = require('EventPropagators');
24
var ExecutionEnvironment = require('ExecutionEnvironment');
25
+var ReactInputSelection = require('ReactInputSelection');
26
var SyntheticEvent = require('SyntheticEvent');
27
28
var getActiveElement = require('getActiveElement');
@@ -65,7 +66,8 @@ var mouseDown = false;
66
* @param {object}
67
*/
68
function getSelection(node) {
68
- if ('selectionStart' in node) {
69
+ if ('selectionStart' in node &&
70
+ ReactInputSelection.hasSelectionCapabilities(node)) {
71
return {
72
start: node.selectionStart,
73
end: node.selectionEnd