shadcn/ui
AddressInput styled with your shadcn/ui theme, as a component you copy into components/ui and own.
The same headless AddressInput as everywhere else, styled the way shadcn/ui styles its own inputs and comboboxes. It uses your theme's tokens (bg-popover, text-muted-foreground, ring-ring, border-input…), so it follows your colours, radius and dark mode.
Install the block
-
Install the package and the icons.
lucide-reactis already there in most shadcn/ui projects.npm i @dk-address/react lucide-react -
Copy the Code tab into
components/ui/address-input.tsx. It importscnfrom@/lib/utils, which shadcn/ui sets up for you.
Use the parts
import { MapPinIcon } from "lucide-react";
import {
AddressInput,
AddressInputClear,
AddressInputContent,
AddressInputControl,
AddressInputEmpty,
AddressInputHint,
AddressInputInput,
AddressInputLabel,
AddressInputList,
AddressInputStatus,
} from "@/components/ui/address-input";
export function DeliveryAddress() {
return (
<AddressInput onSelect={(selection) => console.log(selection.details)}>
<AddressInputLabel>Delivery address</AddressInputLabel>
<AddressInputControl>
<MapPinIcon />
<AddressInputInput placeholder="Vesterbrogade 28, st. 1" />
<AddressInputClear />
</AddressInputControl>
<AddressInputHint />
<AddressInputContent>
<AddressInputStatus />
<AddressInputEmpty />
<AddressInputList />
</AddressInputContent>
</AddressInput>
);
}What each part wraps
| Part | Wraps | Styled like |
|---|---|---|
AddressInput | AddressInput | (renders nothing) |
AddressInputLabel | .Label | Label |
AddressInputControl | .Control | Input: border, focus ring, aria-invalid state; icons inside are muted and sized |
AddressInputInput | .Input | The text inside Input |
AddressInputClear | .Clear | A muted icon button; shows an X unless given children |
AddressInputHint | useAddressInput() | Muted helper text: what to type into the gap |
AddressInputContent | .Popup | PopoverContent, as wide as the control, animated in and out |
AddressInputStatus | .Status | Screen-reader-only search status |
AddressInputEmpty | .Empty | CommandEmpty |
AddressInputList | .List | Renders an AddressInputItem per suggestion unless given children |
AddressInputItem | .Item | CommandItem, with an icon per suggestion type |
Every part merges your className over its own with cn, so className="h-10" replaces the default height instead of fighting it. The AddressInput reference lists each part's props and state.
Validate it in a form
Mark the field invalid with aria-invalid on AddressInputInput; the control turns red like shadcn/ui's Input. To submit the address id and require a real pick, see Styling AddressInput → Wire it into forms.