License Plate
Dutch license plate (kenteken) input with sidecode validation and formatting.
Enter a Dutch license plate, e.g. GB001B.
import { Field, FieldDescription, FieldLabel } from "@/components/ui/field"
import { LicensePlate } from "@/components/ui/license-plate"
export function LicensePlateDemo() {
return (
<Field className="w-auto">
<FieldLabel htmlFor="license-plate-demo">License plate</FieldLabel>
<LicensePlate id="license-plate-demo" />
<FieldDescription>Enter a Dutch license plate, e.g. GB001B.</FieldDescription>
</Field>
)
}Installation
Install with the shadcn CLI. An AI assistant with the shadcn MCP server configured can also install components automatically when you ask for them (see Getting Started).
npx shadcn@latest add @rdc-ui/license-plateBesides the component, the CLI adds src/css/rdc-ui/components/license-plate.css and imports it in your Tailwind CSS file. It only declares the Kenteken font face; browsers download the font when a license plate is actually rendered.
Usage
import { LicensePlate } from "@/components/ui/license-plate"
export function VehicleForm() {
return <LicensePlate onValidated={({ isValid, formattedValue }) => console.log(isValid, formattedValue)} />
}Input is normalized to uppercase letters and digits (max. 6). While focused the raw value is shown; on blur a valid plate is displayed with dashes. Typing a valid plate blurs the input automatically.
Sizes
Use size: 2xs (16px), xs (24px), sm (32px), default (40px), lg (48px), xl (56px) or 2xl (80px). Font, flag, border and width scale with it. Other heights are not supported: a height class on className is ignored, because in-between heights render the font with jagged edges.
import { LicensePlate } from "@/components/ui/license-plate"
export function LicensePlateSizesDemo() {
return (
<div className="flex flex-col items-start gap-4">
<LicensePlate size="2xs" readOnly defaultValue="GB001B" />
<LicensePlate size="xs" readOnly defaultValue="GB001B" />
<LicensePlate size="sm" readOnly defaultValue="GB001B" />
<LicensePlate readOnly defaultValue="GB001B" />
<LicensePlate size="lg" readOnly defaultValue="GB001B" />
<LicensePlate size="xl" readOnly defaultValue="GB001B" />
<LicensePlate size="2xl" readOnly defaultValue="GB001B" />
</div>
)
}Width follows the plate ratio, also inside a Field; use className="w-full max-w-none" to stretch it instead.
Read only
import { LicensePlate } from "@/components/ui/license-plate"
export function LicensePlateReadOnlyDemo() {
return <LicensePlate readOnly defaultValue="GB001B" />
}Validation
onValidated fires when 6 characters are entered (valid or not), when a valid plate is changed into an incomplete one (isValid: false), and for an initial or externally changed value. Entering 6 characters that match no sidecode sets aria-invalid.
- value
- -
- isValid
- -
- formattedValue
- -
import { useState } from "react"
import { LicensePlate, type LicensePlateValidatedEvent } from "@/components/ui/license-plate"
export function LicensePlateValidationDemo() {
const [value, setValue] = useState("")
const [result, setResult] = useState<LicensePlateValidatedEvent>()
return (
<div className="flex flex-col items-center gap-4">
<LicensePlate value={value} onValueChange={setValue} onValidated={setResult} />
<dl className="grid grid-cols-[auto_auto] gap-x-4 gap-y-1 text-sm">
<dt className="text-muted-foreground">value</dt>
<dd className="font-mono">{value || "-"}</dd>
<dt className="text-muted-foreground">isValid</dt>
<dd className="font-mono">{result ? String(result.isValid) : "-"}</dd>
<dt className="text-muted-foreground">formattedValue</dt>
<dd className="font-mono">{result?.formattedValue ?? "-"}</dd>
</dl>
</div>
)
}Use formatLicensePlate to format or validate outside the component:
import { formatLicensePlate } from "@/components/ui/license-plate"
formatLicensePlate("gb001b") // "GB-001-B"
formatLicensePlate("ABCDEF") // undefinedAPI
Accepts all Base UI Input props, except className, which is applied to the root.
| Prop | Type | Default |
|---|---|---|
size | "2xs" | "xs" | "sm" | "default" | "lg" | "xl" | "2xl" | "default" |
value | string | - |
defaultValue | string | - |
onValueChange | (value: string) => void | - |
onValidated | (event: { isValid: boolean; value?: string; formattedValue?: string }) => void | - |
placeholder | string | "GBB-01-B" |
readOnly | boolean | false |
Last updated on