Skip to content
All blocks

[29] Forms

Field Add-Ons

A search field with a shortcut, an address prefix, a price with its unit, a percent field and a key with a show button.

1280px

Copy the code

One file with one component and its sample data. It needs @vaneui/ui and its stylesheet, set up as in the installation guide. It passes an onSubmit handler, so in the Next.js App Router add "use client" at the top of its file.

field-addons.tsx

import { useState } from "react";
import { Button, Card, Col, Container, Field, Grid2, IconButton, Input, Kbd, PageTitle, Row, Section } from "@vaneui/ui";
function SearchIcon() {
return (
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" aria-hidden="true">
<circle cx="11" cy="11" r="7" /><path d="m20 20-4-4" />
</svg>
);
}
function MailIcon() {
return (
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
<rect x="3" y="5" width="18" height="14" rx="2" /><path d="m3 7 9 6 9-6" />
</svg>
);
}
function EyeIcon({ off }: { off: boolean }) {
return (
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
<path d="M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7S2 12 2 12z" /><circle cx="12" cy="12" r="3" />
{off && <path d="M4 4l16 16" />}
</svg>
);
}
export function FieldAddons() {
const [showKey, setShowKey] = useState(false);
return (
<Section>
<Container itemsStretch>
<Col lg className="max-w-3xl">
<Row justifyBetween mobileStack itemsStretch>
<PageTitle>Store settings</PageTitle>
<Input type="search" aria-label="Search settings" placeholder="Search settings" startSection={<SearchIcon />}
endSection={<Kbd>⌘K</Kbd>} className="w-64" mobileWFull />
</Row>
<Card tag="form" onSubmit={(e) => e.preventDefault()}>
<Grid2>
<Field type="text" label="Store address" name="slug" startSection="shop.acme.com/" placeholder="your-store" />
<Field type="email" label="Support email" name="support" startSection={<MailIcon />} placeholder="help@company.com" />
<Field type="number" label="Price" name="price" startSection="$" endSection="per month" placeholder="12" min={0} />
<Field type="number" label="Sales tax" name="tax" endSection="%" placeholder="20" min={0} max={100} />
</Grid2>
<Field type={showKey ? "text" : "password"} label="API key" name="apiKey" defaultValue="sk_live_51Hx9a2Kq4"
description="Keep it secret: it gives full access to your store."
endSection={
<IconButton type="button" ghost secondary aria-label="Show the key" aria-pressed={showKey}
onClick={() => setShowKey((s) => !s)}>
<EyeIcon off={showKey} />
</IconButton>
} />
<Row justifyEnd>
<Button type="submit" filled mobileWFull>Save settings</Button>
</Row>
</Card>
</Col>
</Container>
</Section>
);
}

How it adapts

  • 768px and up: the search sits beside the page title and the fields go two to a row.
  • Below 768px: the search fills the width under the title, and each field takes a row.
  • Each field reserves the measured width of its prefix or suffix, so typed text never runs under it.

How these props work is in responsive page sections without breakpoint classes.

Adapt it with your coding agent

Add the VaneUI MCP server, and your agent reads the component docs and prop tables while it changes the block: the copy, the sample data or the layout.

$ claude mcp add vaneui -- npx -y @vaneui/mcp

Setup for other editors is in the AI assistants guide.