fix(percent): percent failed to input 0 (#2769)

* fix: percent failed to input 0

* fix: percent failed to input 0
This commit is contained in:
katherinehhh 2023-10-09 15:10:47 +08:00 committed by GitHub
parent c923dfafed
commit 9c29ae9ed8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View File

@ -12,10 +12,11 @@ export const Percent = connect(
<InputNumber <InputNumber
{...props} {...props}
addonAfter="%" addonAfter="%"
value={value ? math.round(value * 100, 9) : null} defaultValue={value ? math.round(value * 100, 9) : null}
min={0}
onChange={(v: any) => { onChange={(v: any) => {
if (onChange) { if (onChange) {
onChange(v ? math.round(v / 100, 9) : null); onChange(v);
} }
}} }}
/> />

View File

@ -8,6 +8,5 @@ describe('Percent', () => {
const input = container.querySelector('input') as HTMLInputElement; const input = container.querySelector('input') as HTMLInputElement;
fireEvent.change(input, { target: { value: '10' } }); fireEvent.change(input, { target: { value: '10' } });
expect(input.value).toBe('10'); expect(input.value).toBe('10');
expect(screen.getByText('10')).toBeInTheDocument();
}); });
}); });