> ## Documentation Index
> Fetch the complete documentation index at: https://primer.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Card inputs

> Card number, expiry date, CVV and cardholder name inputs, and the PrimerTextInput they are built on.

> [!WARNING]
>
> Primer Checkout React Native SDK is currently in **beta** (v3.0.0-beta.1).
> The API is subject to change before the stable release.

The four card inputs each render one card field that is already wired to the card form: `PrimerCardNumberInput`, `PrimerExpiryDateInput`, `PrimerCVVInput` and `PrimerCardholderNameInput`. Arrange them yourself when the fixed layout of [`PrimerCardForm`](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/card-form/primer-card-form) doesn't fit. [`PrimerTextInput`](#primertextinput) is the styled text input they are built on. Use it for other fields so they look the same.

The card inputs must be inside `PrimerCheckoutProvider` and [`PrimerCardFormProvider`](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/card-form/primer-card-form#primercardformprovider). Without `PrimerCardFormProvider` they throw.

## Usage

```tsx theme={"dark"}
import { useRef } from 'react';
import { View } from 'react-native';
import {
  PrimerCardholderNameInput,
  PrimerCardNumberInput,
  PrimerCVVInput,
  PrimerExpiryDateInput,
  usePrimerCardForm,
} from '@primer-io/react-native';
import type { PrimerTextInputRef } from '@primer-io/react-native';

function CardFields() {
  const cardForm = usePrimerCardForm();
  const expiryRef = useRef<PrimerTextInputRef>(null);

  return (
    <View style={{ gap: 12 }}>
      <PrimerCardNumberInput returnKeyType="next" onSubmitEditing={() => expiryRef.current?.focus()} />
      <View style={{ flexDirection: 'row', gap: 12 }}>
        <PrimerExpiryDateInput ref={expiryRef} style={{ flex: 1 }} />
        <PrimerCVVInput label={cardForm.descriptor.cvvLabel} style={{ flex: 1 }} />
      </View>
      {cardForm.isCardholderNameVisible && <PrimerCardholderNameInput />}
    </View>
  );
}
```

* Render `PrimerCardholderNameInput` only when `usePrimerCardForm().isCardholderNameVisible` is `true`, as `PrimerCardForm` does.
* `PrimerCVVInput` is labelled `CVV` by default. Pass `descriptor.cvvLabel` to follow the detected network, as `PrimerCardForm` does.
* The card form must be active before it validates or pays. See [`PrimerCardForm`](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/card-form/primer-card-form#usage).

## Card input props

All four card inputs take the same props, exported as `PrimerCardInputProps`. The aliases `PrimerCardNumberInputProps`, `PrimerExpiryDateInputProps`, `PrimerCVVInputProps` and `PrimerCardholderNameInputProps` are the same type.

| Prop | Type | Default | Description |
| - | - | - | - |
| `theme` | `PrimerTextInputTheme` | — | Style overrides for this input. See [`PrimerTextInputTheme`](#primertextinputtheme). |
| `editable` | `boolean` | `true` | Whether the field accepts input. |
| `label` | `string` | Per input, see below | Text above the field. |
| `showLabel` | `boolean` | `true` | Whether to show the label. |
| `placeholder` | `string` | Per input, see below | Text shown while the field is empty. |
| `returnKeyType` | `TextInputProps['returnKeyType']` | — | The return key of the keyboard. |
| `onSubmitEditing` | `TextInputProps['onSubmitEditing']` | — | Called when the shopper presses the return key. |
| `style` | `StyleProp<ViewStyle>` | — | Style for the outer container. |
| `inputStyle` | `StyleProp<TextStyle>` | — | Style for the text field. |
| `labelStyle` | `StyleProp<TextStyle>` | — | Style for the label. |
| `testID` | `string` | — | Test ID of the container. The text field gets `<testID>-input` and the error text `<testID>-error`. The icons get `<testID>-network-icon`, `<testID>-network-abbreviation` or `<testID>-network-selector` on the card number, `<testID>-calendar-icon` on the expiry date and `<testID>-hint-icon` on the CVV. |

The default label and placeholder follow the device language. See [`usePrimerLocalization`](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/common/use-primer-localization).

The card inputs set their value, change handler, error message and focus handlers themselves from [`usePrimerCardForm`](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/card-form/use-primer-card-form). To control a field yourself, build it with `PrimerTextInput` and the hook's update functions, as in [Your own field](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/card-form/use-primer-card-form.md#your-own-field).

Each card input forwards a ref of type `PrimerTextInputRef`:

| Method | Description |
| - | - |
| `focus()` | Focuses the field. |
| `blur()` | Removes focus from the field. |
| `setCaret(start: number, end?: number)` | Moves the cursor, or selects from `start` to `end`. |

Each card input shows its field's message from `usePrimerCardForm().errors` below the field, with the error border. See [When errors show](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/card-form/use-primer-card-form.md#when-errors-show).

## PrimerCardNumberInput

| Aspect | Detail |
| - | - |
| Default label | `Card Number` |
| Default placeholder | `1234 1234 1234 1234` |
| Keyboard | `number-pad` |
| Max length | `usePrimerCardForm().cardNumberMaxLength`: the network's longest card number plus spaces |
| Autofill | `autoComplete="cc-number"`, `textContentType="creditCardNumber"` |
| Formatting | Inserts spaces by the detected network's gap pattern. Deleting a space also deletes the digit before it. |
| Trailing content | The co-badged network selector when the card has two or more allowed networks. Otherwise the detected network's icon, a two-letter abbreviation when there is no icon, or a generic card image. |

The co-badged selector is [`PrimerCardNetworkSelector`](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/card-form/card-networks#primercardnetworkselector). Don't add another one next to this input.

## PrimerExpiryDateInput

| Aspect | Detail |
| - | - |
| Default label | `Expiry Date` |
| Default placeholder | `MM/YY` |
| Keyboard | `number-pad` |
| Max length | 5 characters |
| Autofill | `autoComplete="cc-exp"`, `textContentType="creditCardExpiration"` |
| Formatting | Inserts `/` after the month. Deleting the `/` also deletes the digit before it. |
| Trailing content | A calendar icon in the `iconPrimary` color. |

## PrimerCVVInput

| Aspect | Detail |
| - | - |
| Default label | `CVV` |
| Default placeholder | `123` |
| Keyboard | `number-pad` |
| Max length | The detected network's CVV length: 3 or 4 |
| Masking | The entry is hidden (`secureTextEntry`). |
| Autofill | `autoComplete="cc-csc"`, `textContentType="creditCardSecurityCode"` |
| Trailing content | A security code hint icon in the `iconPrimary` color. |

## PrimerCardholderNameInput

| Aspect | Detail |
| - | - |
| Default label | `Name on card` |
| Default placeholder | `Full name` |
| Capitalization | Each word |
| Autofill | `autoComplete="name"`, `textContentType="name"` |
| Visibility | Render it only when `usePrimerCardForm().isCardholderNameVisible` is `true`. |

## PrimerTextInput

`PrimerTextInput` is a controlled text input with the label, border, focus and error styles of the card inputs. It doesn't read the card form, so you can use it for any field. It also works outside `PrimerCheckoutProvider`, where it uses the default tokens for the device's light or dark mode.

```tsx theme={"dark"}
import { useState } from 'react';
import { PrimerTextInput } from '@primer-io/react-native';

function EmailField({ error }: { error?: string }) {
  const [email, setEmail] = useState('');

  return (
    <PrimerTextInput
      label="Email"
      value={email}
      onChangeText={setEmail}
      keyboardType="email-address"
      autoComplete="email"
      error={error}
    />
  );
}
```

### Props

The props type is exported as `PrimerTextInputProps`.

| Prop | Type | Default | Description |
| - | - | - | - |
| `value` | `string` | Required | The text in the field. |
| `onChangeText` | `(text: string) => void` | Required | Called with the new text on every change. |
| `onFocus` | `() => void` | — | Called when the field gets focus. |
| `onBlur` | `() => void` | — | Called when the field loses focus. |
| `editable` | `boolean` | `true` | Whether the field accepts input. A disabled field uses the disabled colors. |
| `keyboardType` | `KeyboardTypeOptions` | — | The keyboard to show. |
| `maxLength` | `number` | — | The maximum number of characters. |
| `secureTextEntry` | `boolean` | `false` | Hides the entered text. |
| `autoComplete` | `TextInputProps['autoComplete']` | — | Autofill hint. |
| `textContentType` | `TextInputProps['textContentType']` | — | Autofill hint on iOS. |
| `autoCapitalize` | `TextInputProps['autoCapitalize']` | `'none'` | Automatic capitalization. |
| `label` | `string` | — | Text above the field. |
| `showLabel` | `boolean` | `true` | Whether to show the label. The label shows only when `label` is set. |
| `placeholder` | `string` | — | Text shown while the field is empty. |
| `error` | `string` | — | Error message below the field. While it is set, the border uses the error color, also when the field has focus. Pass `undefined` to clear it. |
| `leadingContent` | `ReactNode` | — | Content inside the field, before the text. |
| `trailingContent` | `ReactNode` | — | Content inside the field, after the text. |
| `onSelectionChange` | `TextInputProps['onSelectionChange']` | — | Called when the cursor or selection moves. |
| `selectionColor` | `string` | The theme's `primaryColor` | Color of the cursor and selection. |
| `returnKeyType` | `TextInputProps['returnKeyType']` | — | The return key of the keyboard. The keyboard closes on return unless it is `'next'`. |
| `onSubmitEditing` | `TextInputProps['onSubmitEditing']` | — | Called when the shopper presses the return key. |
| `theme` | `PrimerTextInputTheme` | — | Style overrides for this input. See [`PrimerTextInputTheme`](#primertextinputtheme). |
| `style` | `StyleProp<ViewStyle>` | — | Style for the outer container. |
| `inputStyle` | `StyleProp<TextStyle>` | — | Style for the text field. |
| `labelStyle` | `StyleProp<TextStyle>` | — | Style for the label. |
| `errorStyle` | `StyleProp<TextStyle>` | — | Style for the error text. |
| `accessibilityLabel` | `string` | `label` | Label read by screen readers. |
| `testID` | `string` | — | Test ID of the container. The text field gets `<testID>-input` and the error text `<testID>-error`. |

`PrimerTextInput` forwards a ref of type `PrimerTextInputRef` with `focus()`, `blur()` and `setCaret(start, end?)`, as described under [Card input props](#card-input-props).

### States and accessibility

* The border color follows the state. A disabled field uses the disabled color. Otherwise an error wins over focus, and focus wins over the resting color.
* A field with an error is marked as invalid. Screen readers read the error together with the label when the field gets focus.
* Screen readers announce a new error.

## PrimerTextInputTheme

Pass a `PrimerTextInputTheme` to the `theme` prop of `PrimerTextInput` or of a card input to style that one input. Every key is optional. A key you leave out falls back to a [design token](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/theming/primer-theme-override.md) of the active light or dark theme. `CardInputTheme` is an alias of the same type.

| Prop | Type | Default | Description |
| - | - | - | - |
| `primaryColor` | `string` | `colors.borderOutlinedFocus` | Border color while focused, and the default cursor and selection color. |
| `textColor` | `string` | `colors.textOutlinedDefault` | Text color. |
| `labelColor` | `string` | `colors.textPrimary` | Label color. |
| `placeholderColor` | `string` | `colors.textPlaceholder` | Placeholder color. |
| `backgroundColor` | `string` | `colors.backgroundOutlinedDefault` | Field background. |
| `disabledBackgroundColor` | `string` | `colors.backgroundOutlinedDisabled` | Field background when `editable` is `false`. |
| `borderColor` | `string` | `colors.borderOutlinedDefault` | Border color at rest. |
| `disabledBorderColor` | `string` | `colors.borderOutlinedDisabled` | Border color when `editable` is `false`. |
| `errorColor` | `string` | `colors.borderOutlinedError` | Border color while there is an error. |
| `errorTextColor` | `string` | `colors.textNegative` | Color of the error text. |
| `borderWidth` | `number` | `widths.default` | Border width at rest. |
| `focusedBorderWidth` | `number` | `widths.focus` | Border width while focused. Never thinner than `borderWidth`. |
| `errorBorderWidth` | `number` | `widths.error` | Border width while there is an error. Never thinner than `borderWidth`. |
| `borderRadius` | `number` | `radii.small` | Corner radius of the field. |
| `fieldHeight` | `number` | `2 × spacing.medium + typography.bodyLarge.lineHeight`, at least 44 | Minimum height of the field: 44 with the default tokens. A value you set is used as given. |
| `fontFamily` | `string` | `typography.bodyLarge.fontFamily` | Font of the text. Also used for the label, and for the error text when `errorFontFamily` is not set. |
| `fontSize` | `number` | `typography.bodyLarge.fontSize` | Text size. |
| `fontWeight` | `TextStyle['fontWeight']` | `typography.bodyLarge.fontWeight` | Text weight. |
| `letterSpacing` | `number` | `typography.bodyLarge.letterSpacing` | Text letter spacing. |
| `lineHeight` | `number` | `typography.bodyLarge.lineHeight` | Text line height. When you set `fontSize` but not `lineHeight`, it is `fontSize × 1.25`, rounded. |
| `labelFontSize` | `number` | `typography.bodySmall.fontSize` | Label size. Also used for the error text when `errorFontSize` is not set. |
| `labelFontWeight` | `TextStyle['fontWeight']` | `typography.bodySmall.fontWeight` | Label weight. |
| `labelLetterSpacing` | `number` | `typography.bodySmall.letterSpacing` | Label letter spacing. |
| `labelLineHeight` | `number` | `typography.bodySmall.lineHeight` | Label line height. Scales with `labelFontSize` when only that is set. |
| `errorFontFamily` | `string` | `fontFamily`, then `typography.error.fontFamily` | Font of the error text. |
| `errorFontSize` | `number` | `labelFontSize`, then `typography.error.fontSize` | Size of the error text. |
| `errorFontWeight` | `TextStyle['fontWeight']` | `typography.error.fontWeight` | Weight of the error text. |
| `errorLetterSpacing` | `number` | `typography.error.letterSpacing` | Letter spacing of the error text. |
| `errorLineHeight` | `number` | `typography.error.lineHeight` | Line height of the error text. Scales with `errorFontSize` or `labelFontSize` when one of them is set. |

* The label uses `fontFamily` when you set it, otherwise `typography.bodySmall.fontFamily`.
* The text and label of a disabled field use `colors.textDisabled`.

```tsx theme={"dark"}
import { PrimerCardNumberInput } from '@primer-io/react-native';
import type { PrimerTextInputTheme } from '@primer-io/react-native';

const inputTheme: PrimerTextInputTheme = {
  borderRadius: 12,
  backgroundColor: '#F5F5F7',
};

function CardNumberField() {
  return <PrimerCardNumberInput theme={inputTheme} />;
}
```

> [!TIP]
>
> To restyle every input and the rest of the UI at once, set tokens in the `theme` prop of `PrimerCheckoutProvider`. Use `PrimerTextInputTheme` only for changes to single inputs.

## See also

> [card] [PrimerCardForm](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/card-form/primer-card-form.md)
>
> The four card inputs in a fixed layout.

> [card] [usePrimerCardForm](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/card-form/use-primer-card-form.md)
>
> Field values, update functions, validation and `submit()`.

> [card] [Card networks](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/card-form/card-networks.md)
>
> The co-badged network selector and network icons.

> [card] [PrimerThemeOverride](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/theming/primer-theme-override.md)
>
> Design tokens for the whole checkout UI.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.