From 5cb4a620e7997d448f3eac73b9ccedd8b5e79237 Mon Sep 17 00:00:00 2001 From: Ben Alpert Date: Thu, 7 Apr 2016 19:02:43 -0700 Subject: [PATCH] Set value using attribute only on initial option render Tested that you can now type in the middle of a controlled input in Chrome which previously jumped your cursor to the end. Fixes #6445. --- .../dom/client/wrappers/ReactDOMOption.js | 10 ++++++ .../wrappers/__tests__/ReactDOMOption-test.js | 11 ++++++ .../dom/shared/DOMPropertyOperations.js | 4 +-- src/renderers/dom/shared/ReactDOMComponent.js | 10 ++++++ .../__tests__/ReactDOMComponent-test.js | 34 +++++-------------- 5 files changed, 40 insertions(+), 29 deletions(-) diff --git a/src/renderers/dom/client/wrappers/ReactDOMOption.js b/src/renderers/dom/client/wrappers/ReactDOMOption.js index 917ed0ee4a167..18f9bc631ebfd 100644 --- a/src/renderers/dom/client/wrappers/ReactDOMOption.js +++ b/src/renderers/dom/client/wrappers/ReactDOMOption.js @@ -12,6 +12,7 @@ 'use strict'; var ReactChildren = require('ReactChildren'); +var ReactDOMComponentTree = require('ReactDOMComponentTree'); var ReactDOMSelect = require('ReactDOMSelect'); var warning = require('warning'); @@ -57,6 +58,15 @@ var ReactDOMOption = { inst._wrapperState = {selected: selected}; }, + postMountWrapper: function(inst) { + // value="" should make a value attribute (#6219) + var props = inst._currentElement.props; + if (props.value != null) { + var node = ReactDOMComponentTree.getNodeFromInstance(inst); + node.setAttribute('value', props.value); + } + }, + getNativeProps: function(inst, props) { var nativeProps = Object.assign({selected: undefined, children: undefined}, props); diff --git a/src/renderers/dom/client/wrappers/__tests__/ReactDOMOption-test.js b/src/renderers/dom/client/wrappers/__tests__/ReactDOMOption-test.js index 0d52d83df373b..4b78000f264c0 100644 --- a/src/renderers/dom/client/wrappers/__tests__/ReactDOMOption-test.js +++ b/src/renderers/dom/client/wrappers/__tests__/ReactDOMOption-test.js @@ -71,4 +71,15 @@ describe('ReactDOMOption', function() { var node = ReactDOM.findDOMNode(stub); expect(node.innerHTML).toBe('foobar'); }); + + it('should set attribute for empty value', function() { + var container = document.createElement('div'); + var option = ReactDOM.render(