PrimerCardNumberInput, PrimerExpiryDateInput, PrimerCVVInput and PrimerCardholderNameInput. Arrange them yourself when the fixed layout of PrimerCardForm doesn’t fit. 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. Without PrimerCardFormProvider they throw.
Usage
- Render
PrimerCardholderNameInputonly whenusePrimerCardForm().isCardholderNameVisibleistrue, asPrimerCardFormdoes. PrimerCVVInputis labelledCVVby default. Passdescriptor.cvvLabelto follow the detected network, asPrimerCardFormdoes.- The card form must be active before it validates or pays. See
PrimerCardForm.
Card input props
All four card inputs take the same props, exported asPrimerCardInputProps. The aliases PrimerCardNumberInputProps, PrimerExpiryDateInputProps, PrimerCVVInputProps and PrimerCardholderNameInputProps are the same type.
The default label and placeholder follow the device language. See
usePrimerLocalization.
The card inputs set their value, change handler, error message and focus handlers themselves from usePrimerCardForm. To control a field yourself, build it with PrimerTextInput and the hook’s update functions, as in Your own field.
Each card input forwards a ref of type PrimerTextInputRef:
Each card input shows its field’s message from
usePrimerCardForm().errors below the field, with the error border. See When errors show.
PrimerCardNumberInput
The co-badged selector is
PrimerCardNetworkSelector. Don’t add another one next to this input.
PrimerExpiryDateInput
PrimerCVVInput
PrimerCardholderNameInput
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.
Props
The props type is exported asPrimerTextInputProps.
PrimerTextInput forwards a ref of type PrimerTextInputRef with focus(), blur() and setCaret(start, end?), as described under 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 aPrimerTextInputTheme 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 of the active light or dark theme. CardInputTheme is an alias of the same type.
- The label uses
fontFamilywhen you set it, otherwisetypography.bodySmall.fontFamily. - The text and label of a disabled field use
colors.textDisabled.
See also
PrimerCardForm
The four card inputs in a fixed layout.
usePrimerCardForm
Field values, update functions, validation and
submit().Card networks
The co-badged network selector and network icons.
PrimerThemeOverride
Design tokens for the whole checkout UI.