Card Details
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
Preview
Mirrored is the same English content laid out right to left: it separates a mirroring bug from a translation one.
Installation
Add the component
npx ritla add card-detailsAlso works with shadcn:
npx shadcn@latest add @ritla/card-detailsDependencies it brings
@base-ui/reactOr 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
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.
API reference
CardDetails
| Prop | Type | Default | Description |
|---|---|---|---|
label | ReactNode | None | Figma's Label. |
value / defaultValue | { number, expiry, cvc } | None | The values (number without spaces, expiry MM/YY). |
onValueChange | (card, { brand, complete }) => void | None | On every change: the network (visa, mastercard…) and whether all three are complete, Luhn-checked. |
error / errorPart | ReactNode / "number" | "expiry" | "cvc" | None | Figma's State = Error and Field. Without errorPart all three are marked. |
partLabels | { number?, expiry?, cvc? } | None | Screen reader names of the parts. Default: in the page language. |
names | { number?, expiry?, cvc? } | cc-number, cc-exp, cc-csc | Form field names. |
required / helperText / disabled | … | None | As on Input Field. |
cardBrand / isValidCardNumber
| Prop | Type | Default | Description |
|---|---|---|---|
cardBrand(number) | CardBrand | None | The network from the first digits. mada cards are co-branded Visa or Mastercard and read as those. |
isValidCardNumber(number) | boolean | None | Luhn 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.
| Key | Action |
|---|---|
| Tab | Number, 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. autocompletecc-number, cc-exp and cc-csc for browser and wallet fill, andinputmode="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.
- Arabic text falling back past the declared font family (measured, declared, or a webfont that failed to load)
- letter-spacing applied to Arabic text (breaks the connected script)
- Forced-LTR container, or a bidi override, over Arabic content
- Clipped text: content wider than its box with overflow hidden and no ellipsis
- Fixed-pixel-width container whose Arabic text exceeds the space