Skip to Content
Cristal

Forms

Payment card

Card number grouped while typing, then expiry date and security code.

<cr-card-input>CrCardInput

Example

Digits are grouped by four while typing (4-6-5 for American Express), without making the cursor jump. As soon as the number is complete, the "Expiry" (MM/YY) and "CVC" fields slide in from the right.

With preview, a card drawn at real size fills in at the same time: embossed digits arriving one by one, chip and contactless symbol, network recognized from the first digits (the card then takes its colors: midnight blue for Visa, graphite for Mastercard, teal for American Express, otherwise the theme color), expiry date, and the card flips to the magnetic stripe and security code when focus moves there.

With holder, a "Cardholder" field is added (autocomplete="cc-name", submitted as name-holder) and the name is written on the card.

import { CrCardInput } from '@cristal-ui/react';

export default function CardInputBasic() {
  return <CrCardInput label="Credit card" name="card" hint="Test card: 4242 4242 4242 4242" preview holder required />;
}

Typing on the card

With variant="card", everything is typed directly on the card: the number in the center, the date next to "Valid thru", the holder at the bottom (with holder), and the card flips over to type the security code on the signature panel. These are real fields, each with its visible label; the white text stays readable on every card color.

import { CrCardInput } from '@cristal-ui/react';

export default function CardInputEditor() {
  return <CrCardInput label="Credit card" name="card" variant="card" holder hint="Test card: 4242 4242 4242 4242" required />;
}

Form and validation

  • The form receives name (the number without spaces), name-expiry and name-cvc, plus name-holder with holder. onCrInput gives the three values on every keystroke.
  • The number is checked with the Luhn checksum, which catches most typos; the date must not be in the past; the security code has 3 or 4 digits. The error message is shown below the label, and only the affected field gets a red border.

error-animation animates the error when it appears and on every rejected submit (zigzag, badge, echo…): see Animated error.

Accessibility

  • Each field has its visible label and the browser autofill hint (cc-number, cc-exp, cc-csc, cc-name); the numeric keyboard opens on mobile.
  • Focus never jumps from one field to another on its own.
  • The drawn card repeats what is already typed: it is hidden from screen readers (aria-hidden). With reduced motion, it flips without animation.

API

Properties

PropertyTypeDefaultDescription
disabledbooleanfalseDésactive les champs.
errorstring—Message d'erreur ; remplace le message automatique.
errorAnimation"drop" | "echo" | "jitter" | "none" | "pop" | "wobble" | "zigzag"'none'Animation de l'erreur quand elle apparaît et à chaque envoi refusé : none (par défaut), zigzag, pop, drop, echo, jitter ou wobble.
hintstring—Texte d'aide, lu par les lecteurs d'écran.
holderbooleanfalseAjoute le champ « Titulaire » (nom inscrit sur la carte), envoyé sous name-holder.
label (obligatoire)string—Libellé affiché au-dessus du numéro.
namestring—Nom envoyé avec le formulaire (name, name-expiry, name-cvc).
previewbooleanfalseAffiche une carte dessinée qui se remplit pendant la frappe et se retourne pour le cryptogramme.
requiredbooleanfalseRend la saisie obligatoire.
variant"card" | "fields"'fields'fields : champs classiques ; card : tout se saisit directement sur la carte dessinée.

Events

Reactevent.detailDescription
onCrInputCardValueÉmis à chaque frappe ; detail : numéro (chiffres), date d'expiration et cryptogramme.

CSS parts

To style it from outside: cr-card-input::part(name) { … }

PartDescription
controlLe champ du numéro.
labelLe libellé.

On this page