# Price Input

> Collects an amount with a visible currency code, configurable decimal precision, and native validation.

- Kind: ui · Category: Forms · Interactivity: native
- Install: `npx shadcn@latest add @haze/price-input`
- File: `src/components/haze/ui/price-input.astro`
- npm dependencies: none
- Registry dependencies: @haze/input, @haze/utils
- Docs page: https://hazeui.com/ui/price-input

## Use when
- A form collects prices, limits, or budgets in a known currency.
- Minimum, maximum, and decimal place rules should work during submission.

## Avoid when
- Users need to compare or convert several currencies.

## Alternatives
- [input](https://hazeui.com/ui/input.md)
- [quantity-stepper](https://hazeui.com/ui/quantity-stepper.md)
- [input-group](https://hazeui.com/ui/input-group.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| id | `string` |  | yes | Unique field ID. |
| name | `string` | id | no | Submitted field name. |
| label | `string` | Budget | no | Visible field label. |
| currency | `string` | USD | no | Display currency code. |
| value | `number \| string` |  | no | Initial amount. |
| min | `number` | 0 | no | Lowest allowed amount. |
| max | `number` |  | no | Highest allowed amount. |
| fractionDigits | `0 \| 1 \| 2 \| 3` | 2 | no | Decimal precision for native step validation. |
| required | `boolean` |  | no | Requires an amount. |
| class | `string` |  | no | Classes for the field wrapper. |

## Accessibility
- The label includes the currency for screen readers.
- The input submits the numeric amount in native form data.
- Key Tab: Focus the amount input.
- Key ↑ / ↓: Increment or decrement by one valid step.

## Agent prompts

### Install and use

Install the Haze UI component "Price Input" with `npx shadcn@latest add @haze/price-input`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "https://hazeui.com/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import PriceInput from "@/components/haze/ui/price-input.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: https://hazeui.com/ui/price-input.md

### Customize with real content

Adapt the Haze price-input ui for our product. Replace the demo values of these props with our real content: id, name, label, currency, value, min, max, fractionDigits, required, class. Keep the layout, the heading level rules and these accessibility details: The label includes the currency for screen readers. The input submits the numeric amount in native form data. Do not add raw color classes; use the Haze tokens.

### Choose the right block

Before using price-input, check it fits: use it when a form collects prices, limits, or budgets in a known currency.; minimum, maximum, and decimal place rules should work during submission.. Avoid it when users need to compare or convert several currencies.. Alternatives: @haze/input, @haze/quantity-stepper, @haze/input-group.

## Example requests that should lead here
- Collect a monthly budget in euros with two decimal places.
- Add a required price field with a maximum amount.

## Source

```astro
---
import { cn } from "../../../lib/haze/utils";
import Input from "./input.astro";

interface Props {
  id: string;
  name?: string;
  label?: string;
  currency?: string;
  value?: number | string;
  min?: number;
  max?: number;
  fractionDigits?: 0 | 1 | 2 | 3;
  required?: boolean;
  class?: string;
  [key: string]: unknown;
}

const { id, name = id, label = "Budget", currency = "USD", value, min = 0, max,
  fractionDigits = 2, required, class: className, ...rest } = Astro.props;
---

<div class={cn("grid min-w-0 gap-2", className)}>
  <label for={id} class="text-[0.8125rem]/5 font-medium">{label} <span class="sr-only">in {currency}</span></label>
  <div class="relative flex min-w-0">
    <Input {...rest} id={id} name={name} type="number" inputmode="decimal" value={value} min={min} max={max} step={10 ** -fractionDigits}
      placeholder={fractionDigits ? `0.${"0".repeat(fractionDigits)}` : "0"} required={required} class="tabular-nums [padding-inline-end:4.1rem] [&::-webkit-inner-spin-button]:appearance-none" />
    <span aria-hidden="true" class="pointer-events-none absolute inset-y-px end-px flex w-14 items-center justify-center rounded-e-lg border-s border-border bg-muted px-1 font-mono text-[0.75rem]/4 font-medium text-muted-foreground">{currency}</span>
  </div>
</div>
```
