Skip to content

Copy Field

Beta
Get Ritla UI

A value people need to copy exactly, such as an IBAN, a reference or a promo code, with a button that confirms the copy.

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 copy-field

    Also works with shadcn: npx shadcn@latest add @ritla/copy-field

  2. Dependencies it brings

    @phosphor-icons/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

copy-field.tsx
import { CopyField } from "@/components/ui/copy-field";<CopyField label="IBAN" value="JO94CBJO0010000000000131000" />

API reference

CopyField

PropTypeDefaultDescription
valuestringNoneThe value exactly as copied.
displayReactNodeNoneHow it is shown, if not as copied, such as an IBAN in groups of four.
variant"field" | "inline""field"Figma's Style.
label / aria-labelReactNode / stringNoneFigma's Show label, or a name for screen readers when it is off.
showButtonLabelbooleantrueFigma's Show button label.
onCopy(value) => voidNoneAfter a successful copy.

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
TabEnterReaches the button and copies.

ARIA

  • Copied is announced in a polite live region, and nothing is announced when the copy fails.
  • The button is described by the value it copies.

Arabic and RTL notes

Mirrors

  • The label and button follow the page: the button ends the row, on the left.

Does not mirror

  • The value is Latin and left to right, even in Arabic.
Numerals
The value's digits are as given; never converted, because they are copied.
Arabic typography
body-16 for the value, body-14 Medium for the label and button.
Mixed-direction text
The value sits in a <bdi dir="ltr"> so an IBAN never reorders, while its block keeps the page direction so it starts at the page's start.