Skip to content

Commit 0126cca

Browse files
committed
Unified NumField behavior (fixes #856).
1 parent be843c7 commit 0126cca

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## Next:
2+
3+
- **Fixed:** Unified `NumField` behavior across themes. [\#856](https://github.com/vazco/uniforms/issues/856)
4+
15
## [v3.0.0](https://github.com/vazco/uniforms/tree/v3.0.0) (2021-01-14)
26

37
## [v3.0.0-rc.8](https://github.com/vazco/uniforms/tree/v3.0.0-rc.8) (2020-12-05)

packages/uniforms-antd/src/NumField.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import { FieldProps, connectField, filterDOMProps } from 'uniforms';
44

55
import wrapField from './wrapField';
66

7-
const noneIfNaN = (x: number) => (isNaN(x) ? undefined : x);
8-
97
export type NumFieldProps = FieldProps<
108
number,
119
// FIXME: Why `onReset` fails with `wrapField`?
@@ -21,7 +19,11 @@ function Num(props: NumFieldProps) {
2119
max={props.max}
2220
min={props.min}
2321
name={props.name}
24-
onChange={value => props.onChange(noneIfNaN(value as number))}
22+
onChange={event => {
23+
const parse = props.decimal ? parseFloat : parseInt;
24+
const value = parse('' + event);
25+
props.onChange(isNaN(value) ? undefined : value);
26+
}}
2527
placeholder={props.placeholder}
2628
ref={props.inputRef}
2729
step={props.step || (props.decimal ? 0.01 : 1)}

0 commit comments

Comments
 (0)