Skip to content

Card Details

Get Ritla UI

Card number, expiry and security code as one group, formatted as you type and filled by browsers and wallets.

Ritla scan of this preview: 40 of 41 checks3 breakpointsScanned Known misread of our own scanner: R023

Open in Figma

Preview

Mirrored is the same English content laid out right to left: it separates a mirroring bug from a translation one.

PreviewCode
EnglishMirroredArabic
LTR →

Installation

  1. Add the component

    npx ritla add card-details

    Also works with shadcn: npx shadcn@latest add @ritla/card-details

  2. Dependencies it brings

    @base-ui/react

  3. Or copy by hand

    Installing by hand copies the component's source into your project. The source comes with a Ritla UI license, so the CLI is the short way to the same files.

Usage

card-details.tsx
import { CardDetails } from "@/components/ui/card-details";<CardDetails label="Card details" onValueChange={(card, { brand, complete }) => setCard(card)} />

Examples

Errors and disabled

errorPart marks the part in error (number, expiry or cvc), with the message under the group.

EnglishMirroredArabic
LTR →

API reference

CardDetails

PropTypeDefaultDescription
labelReactNodeNoneFigma's Label.
value / defaultValue{ number, expiry, cvc }NoneThe values (number without spaces, expiry MM/YY).
onValueChange(card, { brand, complete }) => voidNoneOn every change: the network (visa, mastercard…) and whether all three are complete, Luhn-checked.
error / errorPartReactNode / "number" | "expiry" | "cvc"NoneFigma's State = Error and Field. Without errorPart all three are marked.
partLabels{ number?, expiry?, cvc? }NoneScreen reader names of the parts. Default: in the page language.
names{ number?, expiry?, cvc? }cc-number, cc-exp, cc-cscForm field names.
required / helperText / disabled…NoneAs on Input Field.

cardBrand / isValidCardNumber

PropTypeDefaultDescription
cardBrand(number)CardBrandNoneThe network from the first digits. mada cards are co-branded Visa or Mastercard and read as those.
isValidCardNumber(number)booleanNoneLuhn check and length.

Accessibility

Keyboard

Keys are written for left-to-right. In right-to-left the arrow keys swap: the one pointing toward the reading direction moves forward.

KeyAction
TabNumber, then expiry, then security code.

ARIA

  • The group is role="group" named by the label; each part has its own name (“Card number”, “Expiry date (MM/YY)”, “Security code (CVC)”) in the page language.
  • autocomplete cc-number, cc-exp and cc-csc for browser and wallet fill, and inputmode="numeric".
  • The part in error has aria-invalid; the message is linked to every part.

Arabic and RTL notes

Mirrors

  • The label and helper text sit at the inline start (the right).

Does not mirror

  • The group is left to right, as the card is printed: number on top, expiry left and security code right, in Arabic too.
Numerals
Typed Arabic-Indic and Persian digits are stored as Western digits (0123456789) and show in them, as on the card.
Arabic typography
label-16, like every field.

Checks it passes

The Ritla checks this component satisfies by construction. Used as documented, it does not bring these defects onto your page.

  • R050Arabic text falling back past the declared font family (measured, declared, or a webfont that failed to load)
  • R051letter-spacing applied to Arabic text (breaks the connected script)
  • R020Forced-LTR container, or a bidi override, over Arabic content
  • R042Clipped text: content wider than its box with overflow hidden and no ellipsis
  • R043Fixed-pixel-width container whose Arabic text exceeds the space