mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-02 03:58:07 +08:00
fix: input-number 值为0时静态展示问题
This commit is contained in:
parent
db4ef97b82
commit
ddde514cc3
@ -10,7 +10,7 @@
|
|||||||
* 7. 边框模式:无边框 & 半边框
|
* 7. 边框模式:无边框 & 半边框
|
||||||
* 8. 大数模式
|
* 8. 大数模式
|
||||||
*/
|
*/
|
||||||
|
import React = require('react');
|
||||||
import {render, fireEvent, waitFor} from '@testing-library/react';
|
import {render, fireEvent, waitFor} from '@testing-library/react';
|
||||||
import '../../../src';
|
import '../../../src';
|
||||||
import {render as amisRender} from '../../../src';
|
import {render as amisRender} from '../../../src';
|
||||||
@ -273,3 +273,15 @@ test('Renderer:number with big value', async () => {
|
|||||||
|
|
||||||
expect(container).toMatchSnapshot();
|
expect(container).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Renderer:number with static', async () => {
|
||||||
|
const {input: stringValInput} = await setup({
|
||||||
|
value: '123'
|
||||||
|
});
|
||||||
|
const {input: numberValInput} = await setup({
|
||||||
|
value: 123
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(stringValInput.value).toEqual('123');
|
||||||
|
expect(numberValInput.value).toEqual('123');
|
||||||
|
});
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import {Renderer, RendererProps, stripNumber} from 'amis-core';
|
import {Renderer, RendererProps, numberFormatter, stripNumber} from 'amis-core';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import {BaseSchema} from '../Schema';
|
import {BaseSchema} from '../Schema';
|
||||||
|
import isNumber from 'lodash/isNumber';
|
||||||
import {getPropValue, Option, PlainObject, normalizeOptions} from 'amis-core';
|
import {getPropValue, Option, PlainObject, normalizeOptions} from 'amis-core';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -89,7 +90,7 @@ export class NumberField extends React.Component<NumberProps> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value) {
|
if (typeof value === 'number' || typeof value === 'string') {
|
||||||
// 设置了精度,但是原始数据是字符串,需要转成 float 之后再处理
|
// 设置了精度,但是原始数据是字符串,需要转成 float 之后再处理
|
||||||
if (typeof value === 'string' && precision) {
|
if (typeof value === 'string' && precision) {
|
||||||
value = stripNumber(parseFloat(value));
|
value = stripNumber(parseFloat(value));
|
||||||
@ -114,9 +115,7 @@ export class NumberField extends React.Component<NumberProps> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (kilobitSeparator) {
|
if (kilobitSeparator) {
|
||||||
let parts = String(value).split('.');
|
value = numberFormatter(value, precision);
|
||||||
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
||||||
value = parts.join('.');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
viewValue = <span>{value}</span>;
|
viewValue = <span>{value}</span>;
|
||||||
|
Loading…
Reference in New Issue
Block a user