## 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} />;
}
```

## Examples

### Color

The CartInput component supports two color variants: `primary` (default) and `secondary`.

```jsx
function CartInputColors() {
  const [primaryQty, setPrimaryQty] = React.useState(2);
  const [secondaryQty, setSecondaryQty] = React.useState(2);
  return (
    <div style={{ display: "flex", flexDirection: "column", gap: 24 }}>
      <CartInput
        label="Primary"
        color="primary"
        value={primaryQty}
        onChange={setPrimaryQty}
      />
      <CartInput
        label="Secondary"
        color="secondary"
        value={secondaryQty}
        onChange={setSecondaryQty}
      />
    </div>
  );
}
```

### Size

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

```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. The description is hidden when the field is in an invalid state.

```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 |
| :--- | :--- | :--- | :--- |
| color | `"primary" \ | "secondary"` | `primary` | - |
| decrementAriaLabel | `string` | - | A custom aria-label for the decrement button. If not provided, the localized string "Decrement" is used. |
| description | `string` | - | - |
| errorMessage | `string \ | ((validation: ValidationResult) => string)` | - | - |
| incrementAriaLabel | `string` | - | A custom aria-label for the increment button. If not provided, the localized string "Increment" is used. |
| label | `string` | - | - |
| onRemove | `() => void` | - | - |
| size | `"sm" \ | "md" \ | "lg"` | `lg` | - |
| 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. |
| defaultValue | `number` | - | The default value (uncontrolled). |
| dir | `string` | - | - |
| form | `string` | - | The \`\<form>\` element to associate the input with.&#xA;The value of this attribute must be the id of a \`\<form>\` in the same document.&#xA;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.&#xA;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. |
| isRequired | `boolean` | - | Whether user input is required on the input before form submission. |
| isWheelDisabled | `boolean` | - | Enables or disables changing the value with scroll. |
| lang | `string` | - | - |
| maxValue | `number` | - | The largest value allowed for the input. |
| minValue | `number` | `0` | The smallest 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>` | - | - |
| slot | `string` | - | A slot name for the component. Slots allow the component to receive props from a parent component.&#xA;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. |
| translate | `"yes" \ | "no"` | - | - |
| validate | `(value: number) => true \ | ValidationError` | - | A function that returns an error message if a given value is invalid.&#xA;Validation errors are displayed to the user when the form is submitted&#xA;if \`validationBehavior="native"\`. For realtime validation, use the \`isInvalid\`&#xA;prop instead. |
| validationBehavior | `"native" \ | "aria"` | `'native'` | Whether to use native HTML form validation to prevent form submission&#xA;when the value is missing or invalid, or mark the field as required&#xA;or invalid via ARIA. |
| value | `number` | - | The current value (controlled). |