## Import

```jsx
import { CartInput } from "@cfa/react-core";
```

## Live Editor

```jsx
function CartInputExample() {
  const [quantity, setQuantity] = React.useState(1);
  return <CartInput label="Quantity" value={quantity} onChange={setQuantity} />;
}
```

## Guidelines

### When to use

- CartInput is for cart and checkout line-item quantities, with increment, decrement, and optional remove.

### Do

- Let people type when they need a larger quantity.
- Include remove when dropping the line item from the cart.
- Always provide a visible label in sentence case. Placeholder text is not a label. Use placeholders only for optional format hints, never as the only label.
- Enforce min and max on stepper actions. Still allow typed values, then validate when people leave the field or submit the form, not on every keystroke.

### Avoid

- Decrementing to zero and leaving an empty row.
- Using CartInput for general numeric entry. Use NumberInput.

## Examples

### Size

Control the size of the input using the `size` prop. Available sizes are `sm`, `md` (default), and `lg`.

```jsx
function CartInputSizes() {
  const [smQty, setSmQty] = React.useState(1);
  const [mdQty, setMdQty] = React.useState(1);
  const [lgQty, setLgQty] = React.useState(1);
  return (
    <div style={{ display: "flex", flexDirection: "column", gap: 24 }}>
      <CartInput label="Small" size="sm" value={smQty} onChange={setSmQty} />
      <CartInput label="Medium" size="md" value={mdQty} onChange={setMdQty} />
      <CartInput label="Large" size="lg" value={lgQty} onChange={setLgQty} />
    </div>
  );
}
```

### Description

Use the `description` prop to provide additional context below the input. When the field is invalid, the error message appears above the description.

```jsx
function CartInputWithDescription() {
  const [quantity, setQuantity] = React.useState(1);
  return (
    <CartInput
      label="Quantity"
      description="Select the number of items you want to add to your cart."
      value={quantity}
      onChange={setQuantity}
    />
  );
}
```

### Disabled

Use the `isDisabled` prop to prevent interaction with the input.

```jsx
function CartInputDisabled() {
  return <CartInput label="Quantity" value={1} isDisabled />;
}
```

### Validation

Use `isInvalid` with `errorMessage` for realtime validation. For native form validation on submit, pass `errorMessage` as a function and set `validationBehavior="native"`.

```jsx
function CartInputValidation() {
  const [quantity, setQuantity] = React.useState(0);
  return (
    <CartInput
      label="Quantity"
      value={quantity}
      onChange={setQuantity}
      isInvalid={quantity < 1}
      errorMessage="Quantity must be at least 1."
    />
  );
}
```

## Props

### CartInput

| Name | Type | Default | Description |
| :--- | :--- | :--- | :--- |
| decrementAriaLabel | `string` | `"Decrease quantity"` | A custom aria-label for the decrement button. |
| description | `string` | - | Adds a description to the input. |
| errorMessage | `string \ | ((validation: ValidationResult) => string)` | - | Custom error message to display when the input is invalid. |
| incrementAriaLabel | `string` | `"Increase quantity"` | A custom aria-label for the increment button. |
| isRequired | `boolean` | `false` | Sets the input to a required state. |
| label | `string` | - | Adds label for the input. |
| minValue | `number` | `0` | The smallest value allowed for the input. |
| size | `"lg" \ | "md" \ | "sm"` | `md` | Size of the cart input controls. |
| aria-describedby | `string` | - | Identifies the element (or elements) that describes the object. |
| aria-details | `string` | - | Identifies the element (or elements) that provide a detailed, extended description for the object. |
| aria-label | `string` | - | Defines a string value that labels the current element. |
| aria-labelledby | `string` | - | Identifies the element (or elements) that labels the current element. |
| autoFocus | `boolean` | - | Whether the element should receive focus on render. |
| className | `ClassNameOrFunction<NumberFieldRenderProps>` | `'react-aria-NumberField'` | The CSS \[className]\(https\://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the element. A function may be provided to compute the class based on component state. |
| commitBehavior | `"snap" \ | "validate"` | `'snap'` | Controls the behavior of the number field when the user blurs the field after editing. 'snap' will clamp the value to the min/max values, and snap to the nearest step value. 'validate' will not clamp the value, and will validate that the value is within the min/max range and on a valid step. |
| defaultValue | `number` | - | The default value (uncontrolled). |
| dir | `string` | - | - |
| form | `string` | - | The \`\<form>\` element to associate the input with. The value of this attribute must be the id of a \`\<form>\` in the same document. See \[MDN]\(https\://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input#form). |
| formatOptions | `NumberFormatOptions` | - | Formatting options for the value displayed in the number field. This also affects what characters are allowed to be typed by the user. |
| hidden | `boolean` | - | - |
| id | `string` | - | The element's unique identifier. See \[MDN]\(https\://developer.mozilla.org/en-US/docs/Web/HTML/Global\_attributes/id). |
| inert | `boolean` | - | - |
| isDisabled | `boolean` | - | Whether the input is disabled. |
| isInvalid | `boolean` | - | Whether the input value is invalid. |
| isReadOnly | `boolean` | - | Whether the input can be selected but not changed by the user. |
| isWheelDisabled | `boolean` | - | Enables or disables changing the value with scroll. |
| lang | `string` | - | - |
| maxValue | `number` | - | The largest value allowed for the input. |
| name | `string` | - | The name of the input element, used when submitting an HTML form. See \[MDN]\(https\://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefname). |
| onAnimationEnd | `AnimationEventHandler<HTMLDivElement>` | - | - |
| onAnimationEndCapture | `AnimationEventHandler<HTMLDivElement>` | - | - |
| onAnimationIteration | `AnimationEventHandler<HTMLDivElement>` | - | - |
| onAnimationIterationCapture | `AnimationEventHandler<HTMLDivElement>` | - | - |
| onAnimationStart | `AnimationEventHandler<HTMLDivElement>` | - | - |
| onAnimationStartCapture | `AnimationEventHandler<HTMLDivElement>` | - | - |
| onAuxClick | `MouseEventHandler<HTMLDivElement>` | - | - |
| onAuxClickCapture | `MouseEventHandler<HTMLDivElement>` | - | - |
| onBeforeInput | `FormEventHandler<HTMLInputElement>` | - | Handler that is called when the input value is about to be modified. See \[MDN]\(https\://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/beforeinput\_event). |
| onBlur | `((e: FocusEvent<Element, Element>) => void)` | - | Handler that is called when the element loses focus. |
| onChange | `((value: number) => void)` | - | Handler that is called when the value changes. |
| onClick | `MouseEventHandler<HTMLDivElement>` | - | - |
| onClickCapture | `MouseEventHandler<HTMLDivElement>` | - | - |
| onCompositionEnd | `CompositionEventHandler<HTMLInputElement>` | - | Handler that is called when a text composition system completes or cancels the current text composition session. See \[MDN]\(https\://developer.mozilla.org/en-US/docs/Web/API/Element/compositionend\_event). |
| onCompositionStart | `CompositionEventHandler<HTMLInputElement>` | - | Handler that is called when a text composition system starts a new text composition session. See \[MDN]\(https\://developer.mozilla.org/en-US/docs/Web/API/Element/compositionstart\_event). |
| onCompositionUpdate | `CompositionEventHandler<HTMLInputElement>` | - | Handler that is called when a new character is received in the current text composition session. See \[MDN]\(https\://developer.mozilla.org/en-US/docs/Web/API/Element/compositionupdate\_event). |
| onContextMenu | `MouseEventHandler<HTMLDivElement>` | - | - |
| onContextMenuCapture | `MouseEventHandler<HTMLDivElement>` | - | - |
| onCopy | `ClipboardEventHandler<HTMLInputElement>` | - | Handler that is called when the user copies text. See \[MDN]\(https\://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/oncopy). |
| onCut | `ClipboardEventHandler<HTMLInputElement>` | - | Handler that is called when the user cuts text. See \[MDN]\(https\://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/oncut). |
| onDoubleClick | `MouseEventHandler<HTMLDivElement>` | - | - |
| onDoubleClickCapture | `MouseEventHandler<HTMLDivElement>` | - | - |
| onFocus | `((e: FocusEvent<Element, Element>) => void)` | - | Handler that is called when the element receives focus. |
| onFocusChange | `((isFocused: boolean) => void)` | - | Handler that is called when the element's focus status changes. |
| onGotPointerCapture | `PointerEventHandler<HTMLDivElement>` | - | - |
| onGotPointerCaptureCapture | `PointerEventHandler<HTMLDivElement>` | - | - |
| onInput | `FormEventHandler<HTMLInputElement>` | - | Handler that is called when the input value is modified. See \[MDN]\(https\://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/input\_event). |
| onKeyDown | `((e: KeyboardEvent) => void)` | - | Handler that is called when a key is pressed. |
| onKeyUp | `((e: KeyboardEvent) => void)` | - | Handler that is called when a key is released. |
| onLostPointerCapture | `PointerEventHandler<HTMLDivElement>` | - | - |
| onLostPointerCaptureCapture | `PointerEventHandler<HTMLDivElement>` | - | - |
| onMouseDown | `MouseEventHandler<HTMLDivElement>` | - | - |
| onMouseDownCapture | `MouseEventHandler<HTMLDivElement>` | - | - |
| onMouseEnter | `MouseEventHandler<HTMLDivElement>` | - | - |
| onMouseLeave | `MouseEventHandler<HTMLDivElement>` | - | - |
| onMouseMove | `MouseEventHandler<HTMLDivElement>` | - | - |
| onMouseMoveCapture | `MouseEventHandler<HTMLDivElement>` | - | - |
| onMouseOut | `MouseEventHandler<HTMLDivElement>` | - | - |
| onMouseOutCapture | `MouseEventHandler<HTMLDivElement>` | - | - |
| onMouseOver | `MouseEventHandler<HTMLDivElement>` | - | - |
| onMouseOverCapture | `MouseEventHandler<HTMLDivElement>` | - | - |
| onMouseUp | `MouseEventHandler<HTMLDivElement>` | - | - |
| onMouseUpCapture | `MouseEventHandler<HTMLDivElement>` | - | - |
| onPaste | `ClipboardEventHandler<HTMLInputElement>` | - | Handler that is called when the user pastes text. See \[MDN]\(https\://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/onpaste). |
| onPointerCancel | `PointerEventHandler<HTMLDivElement>` | - | - |
| onPointerCancelCapture | `PointerEventHandler<HTMLDivElement>` | - | - |
| onPointerDown | `PointerEventHandler<HTMLDivElement>` | - | - |
| onPointerDownCapture | `PointerEventHandler<HTMLDivElement>` | - | - |
| onPointerEnter | `PointerEventHandler<HTMLDivElement>` | - | - |
| onPointerLeave | `PointerEventHandler<HTMLDivElement>` | - | - |
| onPointerMove | `PointerEventHandler<HTMLDivElement>` | - | - |
| onPointerMoveCapture | `PointerEventHandler<HTMLDivElement>` | - | - |
| onPointerOut | `PointerEventHandler<HTMLDivElement>` | - | - |
| onPointerOutCapture | `PointerEventHandler<HTMLDivElement>` | - | - |
| onPointerOver | `PointerEventHandler<HTMLDivElement>` | - | - |
| onPointerOverCapture | `PointerEventHandler<HTMLDivElement>` | - | - |
| onPointerUp | `PointerEventHandler<HTMLDivElement>` | - | - |
| onPointerUpCapture | `PointerEventHandler<HTMLDivElement>` | - | - |
| onScroll | `UIEventHandler<HTMLDivElement>` | - | - |
| onScrollCapture | `UIEventHandler<HTMLDivElement>` | - | - |
| onSelect | `ReactEventHandler<HTMLInputElement>` | - | Handler that is called when text in the input is selected. See \[MDN]\(https\://developer.mozilla.org/en-US/docs/Web/API/Element/select\_event). |
| onTouchCancel | `TouchEventHandler<HTMLDivElement>` | - | - |
| onTouchCancelCapture | `TouchEventHandler<HTMLDivElement>` | - | - |
| onTouchEnd | `TouchEventHandler<HTMLDivElement>` | - | - |
| onTouchEndCapture | `TouchEventHandler<HTMLDivElement>` | - | - |
| onTouchMove | `TouchEventHandler<HTMLDivElement>` | - | - |
| onTouchMoveCapture | `TouchEventHandler<HTMLDivElement>` | - | - |
| onTouchStart | `TouchEventHandler<HTMLDivElement>` | - | - |
| onTouchStartCapture | `TouchEventHandler<HTMLDivElement>` | - | - |
| onTransitionCancel | `TransitionEventHandler<HTMLDivElement>` | - | - |
| onTransitionCancelCapture | `TransitionEventHandler<HTMLDivElement>` | - | - |
| onTransitionEnd | `TransitionEventHandler<HTMLDivElement>` | - | - |
| onTransitionEndCapture | `TransitionEventHandler<HTMLDivElement>` | - | - |
| onTransitionRun | `TransitionEventHandler<HTMLDivElement>` | - | - |
| onTransitionRunCapture | `TransitionEventHandler<HTMLDivElement>` | - | - |
| onTransitionStart | `TransitionEventHandler<HTMLDivElement>` | - | - |
| onTransitionStartCapture | `TransitionEventHandler<HTMLDivElement>` | - | - |
| onWheel | `WheelEventHandler<HTMLDivElement>` | - | - |
| onWheelCapture | `WheelEventHandler<HTMLDivElement>` | - | - |
| render | `DOMRenderFunction<"div", NumberFieldRenderProps>` | - | Overrides the default DOM element with a custom render function. This allows rendering existing components with built-in styles and behaviors such as router links, animation libraries, and pre-styled components.&#xA;&#xA;Requirements:&#xA;&#xA;- You must render the expected element type (e.g. if \`\<button>\` is expected, you cannot render an \`\<a>\`).&#xA;- Only a single root DOM element can be rendered (no fragments).&#xA;- You must pass through props and ref to the underlying DOM element, merging with your own prop as appropriate. |
| slot | `string \ | null` | - | A slot name for the component. Slots allow the component to receive props from a parent component. An explicit \`null\` value indicates that the local props completely override all props received from a parent. |
| step | `number` | - | The amount that the input value changes with each increment or decrement "tick". |
| style | `StyleOrFunction<NumberFieldRenderProps>` | - | The inline \[style]\(https\://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style) for the element. A function may be provided to compute the style based on component state. |
| suppressHydrationWarning | `boolean` | - | A React-only flag that suppresses the warning React normally logs when an element's server-rendered content doesn't match the client render during hydration. See \[React docs]\(https\://react.dev/reference/react-dom/client/hydrateRoot#suppressing-unavoidable-hydration-mismatch-errors). |
| translate | `"no" \ | "yes"` | - | - |
| validate | `((value: number) => true \ | ValidationError \ | null)` | - | A function that returns an error message if a given value is invalid. Validation errors are displayed to the user when the form is submitted if \`validationBehavior="native"\`. For realtime validation, use the \`isInvalid\` prop instead. |
| validationBehavior | `"aria" \ | "native"` | `'native'` | Whether to use native HTML form validation to prevent form submission when the value is missing or invalid, or mark the field as required or invalid via ARIA. |
| value | `number` | - | The current value (controlled). |