onNumber.ts 664 B

12345678910111213141516
  1. /**
  2. * Wraps an Ant Design InputNumber change handler with the shared
  3. * cleared-field semantic: null and undefined change events (a cleared or
  4. * unparsable field) are ignored, leaving the stored value in place — the
  5. * input snaps back on blur — while real numbers pass through unchanged.
  6. * Number-only by design: not for `stringMode` inputs, whose whole point is
  7. * to avoid the IEEE-754 round trip this signature would force.
  8. */
  9. export function onNumber(
  10. apply: (value: number) => void,
  11. ): (value: number | null | undefined) => void {
  12. return (value) => {
  13. if (typeof value !== 'number' || !Number.isFinite(value)) return;
  14. apply(value);
  15. };
  16. }