# Numeric Input

A semantic numeric field backed by react-number-format.

A semantic numeric field backed by react-number-format.

```tsx
import { Field, NumericInput } from "@zentara-co/zenos-ui";

function NumericInputPreviewExample() {
  return (
    <Field.Root className="w-full max-w-sm">
      <Field.Label>Amount</Field.Label>
      <NumericInput defaultValue={1234.5} prefix="$" thousandSeparator="," decimalScale={2} />
    </Field.Root>
  );
}
```

```tsx
import { NumericInput } from "@zentara-co/zenos-ui";
```

## Sizes

NumericInput uses the shared Zenos `sm`, `md`, and `lg` control scale from Input.

```tsx
import { NumericInput, Stack } from "@zentara-co/zenos-ui";

function NumericInputSizesExample() {
  return (
    <Stack gap="3" className="w-full max-w-sm">
      <NumericInput size="sm" defaultValue={1200} thousandSeparator="," prefix="$" />
      <NumericInput size="md" defaultValue={2500} thousandSeparator="," prefix="$" />
      <NumericInput size="lg" defaultValue={5000} thousandSeparator="," prefix="$" />
    </Stack>
  );
}
```

## Variants

Surfaces match Input: `default` (standard), `filled` (subtle), and `none` (borderless).

```tsx
import { NumericInput, Stack } from "@zentara-co/zenos-ui";

type CatalogVariantProps = { limit?: number };

const limited = <T,>(items: readonly T[], limit?: number) =>
  limit === undefined ? items : items.slice(0, limit);

const formControlSurfaceVariants = ["default", "filled", "none"] as const;

function NumericInputVariantsExample({ limit }: CatalogVariantProps = {}) {
  if (limit !== undefined) {
    return (
      <Stack gap="3" className="w-full max-w-sm">
        {limited(formControlSurfaceVariants, limit).map((variant) => (
          <NumericInput
            key={variant}
            variant={variant}
            defaultValue={1234}
            thousandSeparator=","
            prefix="$"
          />
        ))}
      </Stack>
    );
  }

  return (
    <Stack gap="3" className="w-full max-w-sm">
      {formControlSurfaceVariants.map((variant) => (
        <NumericInput
          key={variant}
          variant={variant}
          defaultValue={1234}
          thousandSeparator=","
          prefix="$"
        />
      ))}
    </Stack>
  );
}
```

## States

Hover, focus, invalid, and disabled treatments are inherited from Input. Invalid matches Input. Use `Field.Root invalid` to connect error text.

```tsx
import { NumericInput, Stack } from "@zentara-co/zenos-ui";

function NumericInputStatesExample() {
  return (
    <Stack gap="3" className="w-full max-w-sm">
      <NumericInput placeholder="0" prefix="$" thousandSeparator="," />
      <NumericInput defaultValue={2500} prefix="$" thousandSeparator="," />
      <NumericInput aria-invalid defaultValue={2500} prefix="$" thousandSeparator="," />
      <NumericInput disabled defaultValue={2500} prefix="$" thousandSeparator="," />
    </Stack>
  );
}
```

## Formatting

NumericInput accepts `react-number-format` formatting options while keeping the Zenos Input surface and semantic numeric callback.

```tsx
import { Field, Grid, NumericInput } from "@zentara-co/zenos-ui";

function NumericInputFormatsExample() {
  return (
    <Grid columns={{ base: 1, md: 3 }} gap="4" className="w-full">
      <Field.Root>
        <Field.Label>Budget</Field.Label>
        <NumericInput defaultValue={24500} prefix="$" thousandSeparator="," decimalScale={2} />
      </Field.Root>
      <Field.Root>
        <Field.Label>Discount</Field.Label>
        <NumericInput defaultValue={12.5} suffix="%" decimalScale={1} />
      </Field.Root>
      <Field.Root>
        <Field.Label>Seats</Field.Label>
        <NumericInput defaultValue={25} allowNegative={false} decimalScale={0} />
      </Field.Root>
    </Grid>
  );
}
```

## Controlled value

`onValueChange` receives a parsed `number` or `undefined` when the control is empty, so application state does not need to parse the displayed string.

```tsx
import { Field, NumericInput } from "@zentara-co/zenos-ui";
import { useState } from "react";

function NumericInputControlledExample() {
  const [amount, setAmount] = useState<number | undefined>(2500);
  return (
    <Field.Root className="w-full max-w-sm">
      <Field.Label>Monthly limit</Field.Label>
      <NumericInput
        value={amount}
        onValueChange={setAmount}
        prefix="$"
        thousandSeparator=","
        allowNegative={false}
      />
      <Field.Description>Parsed value: {amount ?? "empty"}</Field.Description>
    </Field.Root>
  );
}
```

## Variants

default, filled, none

## Sizes

sm, md, lg

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| value | number | — | Controlled parsed numeric value. |
| defaultValue | number | — | Initial uncontrolled value. |
| onValueChange | (value: number \| undefined) => void | — | Runs with the parsed number, or undefined when empty. |
| variant | default \| filled \| none | default | Surface treatment inherited from Input (`default` = standard, `filled` = subtle, `none` = borderless). |
| size | sm \| md \| lg | md | Control height inherited from Input. |
| allowNegative | boolean | — | Allows a leading minus sign. |
| decimalScale | number | — | Maximum decimal digits. |
| prefix / suffix | string | — | Displayed affixes. |

Unless narrowed above, each DOM-rendering part also accepts its underlying native or Base UI props, including className, style, aria-*, and data-*.

## Accessibility

NumericInput renders a native text input with a decimal input mode so formatted characters can coexist with numeric entry. Pair it with `Field.Label`, and include units in the visible label when a prefix or suffix alone could be ambiguous.

Source: https://zenos-ui.pages.dev/components/numeric-input/