feat: update rc-input-number to 4.4.0

pull/666/head
wangxueliang 2019-03-01 20:46:26 +08:00
parent 1e1b869166
commit 21eed858fa
2 changed files with 18 additions and 15 deletions

View File

@ -1,11 +1,11 @@
<script> <script>
import CombinationKeyFormat from '../vc-input-number/demo/combination-key-format'; import CombinationKeyFormat from './combination-key-format.jsx';
import Custom from '../vc-input-number/demo/custom'; import Custom from './custom.jsx';
import Decimal from '../vc-input-number/demo/decimal'; import Decimal from './decimal.jsx';
import Formatter from '../vc-input-number/demo/formatter'; import Formatter from './formatter.jsx';
import SimpleUseTouch from '../vc-input-number/demo/simple-use-touch'; import SimpleUseTouch from './simple-use-touch.jsx';
import Simple from '../vc-input-number/demo/simple'; import Simple from './simple.jsx';
import SimpleStep from '../vc-input-number/demo/simple-step'; import SmallStep from './small-step.jsx';
export default { export default {
render () { render () {
@ -17,7 +17,7 @@ export default {
<Formatter/> <Formatter/>
<SimpleUseTouch/> <SimpleUseTouch/>
<Simple/> <Simple/>
<SimpleStep/> <SmallStep/>
</div> </div>
); );
}, },

View File

@ -1,4 +1,4 @@
// based on rc-input-number 4.3.8 // based on rc-input-number 4.4.0
import PropTypes from '../../_util/vue-types'; import PropTypes from '../../_util/vue-types';
import BaseMixin from '../../_util/BaseMixin'; import BaseMixin from '../../_util/BaseMixin';
import { initDefaultProps, hasProp, getOptionProps } from '../../_util/props-util'; import { initDefaultProps, hasProp, getOptionProps } from '../../_util/props-util';
@ -32,6 +32,9 @@ const DELAY = 600;
* The reason this is used, instead of Infinity is because numbers above the MSI are unstable * The reason this is used, instead of Infinity is because numbers above the MSI are unstable
*/ */
const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || Math.pow(2, 53) - 1; const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || Math.pow(2, 53) - 1;
const isValidProps = value => value !== undefined && value !== null;
const inputNumberProps = { const inputNumberProps = {
value: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), value: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
defaultValue: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), defaultValue: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
@ -290,7 +293,7 @@ export default {
// https://github.com/ant-design/ant-design/issues/8196 // https://github.com/ant-design/ant-design/issues/8196
let value = e.target.value.trim().replace(/。/g, '.'); let value = e.target.value.trim().replace(/。/g, '.');
if (this.decimalSeparator !== undefined) { if (isValidProps(this.decimalSeparator)) {
value = value.replace(this.decimalSeparator, '.'); value = value.replace(this.decimalSeparator, '.');
} }
@ -312,7 +315,7 @@ export default {
}, },
setValue(v, callback) { setValue(v, callback) {
// trigger onChange // trigger onChange
const newValue = this.isNotCompleteNumber(parseFloat(v, 10)) ? undefined : parseFloat(v, 10); const newValue = this.isNotCompleteNumber(parseFloat(v, 10)) ? null : parseFloat(v, 10);
const changed = newValue !== this.sValue || `${newValue}` !== `${this.inputValue}`; // https://github.com/ant-design/ant-design/issues/7363 const changed = newValue !== this.sValue || `${newValue}` !== `${this.inputValue}`; // https://github.com/ant-design/ant-design/issues/7363
if (!hasProp(this, 'value')) { if (!hasProp(this, 'value')) {
this.setState( this.setState(
@ -336,7 +339,7 @@ export default {
} }
}, },
getPrecision(value) { getPrecision(value) {
if (hasProp(this, 'precision')) { if (isValidProps(this.precision)) {
return this.precision; return this.precision;
} }
const valueString = value.toString(); const valueString = value.toString();
@ -355,7 +358,7 @@ export default {
// if this.props.precision is undefined // if this.props.precision is undefined
// https://github.com/react-component/input-number/issues/39 // https://github.com/react-component/input-number/issues/39
getMaxPrecision(currentValue, ratio = 1) { getMaxPrecision(currentValue, ratio = 1) {
if (hasProp(this, 'precision')) { if (isValidProps(this.precision)) {
return this.precision; return this.precision;
} }
const { step } = this; const { step } = this;
@ -492,7 +495,7 @@ export default {
if (this.isNotCompleteNumber(num)) { if (this.isNotCompleteNumber(num)) {
return num; return num;
} }
if (hasProp(this, 'precision')) { if (isValidProps(this.precision)) {
return Number(Number(num).toFixed(this.precision)); return Number(Number(num).toFixed(this.precision));
} }
return Number(num); return Number(num);
@ -657,7 +660,7 @@ export default {
}; };
} }
let inputDisplayValueFormat = this.formatWrapper(inputDisplayValue); let inputDisplayValueFormat = this.formatWrapper(inputDisplayValue);
if (this.decimalSeparator !== undefined) { if (isValidProps(this.decimalSeparator)) {
inputDisplayValueFormat = inputDisplayValueFormat inputDisplayValueFormat = inputDisplayValueFormat
.toString() .toString()
.replace('.', this.decimalSeparator); .replace('.', this.decimalSeparator);