mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Merge pull request #258 from chenglou/patch-3
defaultValue of 0 now displayed
This commit is contained in:
@@ -48,7 +48,7 @@ var ReactDOMInput = ReactCompositeComponent.createClass({
|
||||
getInitialState: function() {
|
||||
return {
|
||||
checked: this.props.defaultChecked || false,
|
||||
value: this.props.defaultValue || ''
|
||||
value: this.props.defaultValue != null ? this.props.defaultValue : ''
|
||||
};
|
||||
},
|
||||
|
||||
|
||||
@@ -77,7 +77,9 @@ var ReactDOMTextarea = ReactCompositeComponent.createClass({
|
||||
);
|
||||
defaultValue = '' + children;
|
||||
}
|
||||
defaultValue = defaultValue || '';
|
||||
if (defaultValue == null) {
|
||||
defaultValue = '';
|
||||
}
|
||||
return {
|
||||
// We save the initial value so that `ReactNativeComponent` doesn't update
|
||||
// `textContent` (unnecessary since we update value).
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* Copyright 2013 Facebook, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* @jsx React.DOM
|
||||
* @emails react-core
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
/*jshint evil:true */
|
||||
|
||||
describe('ReactDOMInput', function() {
|
||||
var React;
|
||||
var ReactTestUtils;
|
||||
|
||||
var renderTextInput;
|
||||
|
||||
beforeEach(function() {
|
||||
React = require('React');
|
||||
ReactTestUtils = require('ReactTestUtils');
|
||||
|
||||
renderTextInput = function(component) {
|
||||
var stub = ReactTestUtils.renderIntoDocument(component);
|
||||
var node = stub.getDOMNode();
|
||||
return node;
|
||||
};
|
||||
});
|
||||
|
||||
it('should display `defaultValue` of number 0', function() {
|
||||
var stub = <input type="text" defaultValue={0} />;
|
||||
var node = renderTextInput(stub);
|
||||
|
||||
expect(node.value).toBe('0');
|
||||
});
|
||||
|
||||
it('should display `value` of number 0', function() {
|
||||
var stub = <input type="text" value={0} />;
|
||||
var node = renderTextInput(stub);
|
||||
|
||||
expect(node.value).toBe('0');
|
||||
});
|
||||
|
||||
});
|
||||
@@ -51,6 +51,13 @@ describe('ReactDOMTextarea', function() {
|
||||
expect(node.value).toEqual('giraffe');
|
||||
});
|
||||
|
||||
it('should display `defaultValue` of number 0', function() {
|
||||
var stub = <textarea defaultValue={0} />;
|
||||
var node = renderTextarea(stub);
|
||||
|
||||
expect(node.value).toBe('0');
|
||||
});
|
||||
|
||||
it('should allow setting `value`', function() {
|
||||
var stub = <textarea value="giraffe" />;
|
||||
var node = renderTextarea(stub);
|
||||
@@ -61,6 +68,13 @@ describe('ReactDOMTextarea', function() {
|
||||
expect(node.value).toEqual('gorilla');
|
||||
});
|
||||
|
||||
it('should display `value` of number 0', function() {
|
||||
var stub = <textarea value={0} />;
|
||||
var node = renderTextarea(stub);
|
||||
|
||||
expect(node.value).toBe('0');
|
||||
});
|
||||
|
||||
it('should treat children like `defaultValue`', function() {
|
||||
spyOn(console, 'warn');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user