Components
Joined field
A control and an input that share one border, such as a currency and an amount.
Your base salary, before bonus and equity.
'use client'
import { Field, FieldControl, FieldLabel, FieldMessage } from '@dex/shared/components/field'
import {
InputGroup,
InputGroupInput,
joinedLeadingClasses,
} from '@dex/shared/components/input-group'
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from '@dex/shared/components/select'
import { cn } from '@dex/shared/utils/cn'
const CURRENCIES = { GBP: 'GBP (£)', EUR: 'EUR (€)', USD: 'USD ($)' }
export function JoinedFieldDefault() {
return (
<Field className="max-w-sm">
<FieldLabel>Minimum base salary</FieldLabel>
<InputGroup>
<Select items={CURRENCIES} defaultValue="GBP">
<SelectTrigger aria-label="Currency" className={cn(joinedLeadingClasses, 'w-28')}>
<SelectValue />
</SelectTrigger>
<SelectContent>
{Object.entries(CURRENCIES).map(([code, label]) => (
<SelectItem key={code} value={code}>
{label}
</SelectItem>
))}
</SelectContent>
</Select>
<FieldControl>
<InputGroupInput inputMode="numeric" placeholder="Enter amount" />
</FieldControl>
</InputGroup>
<FieldMessage description="Your base salary, before bonus and equity." />
</Field>
)
}
'use client'
import { Field, FieldControl, FieldLabel } from '@dex/shared/components/field'
import {
InputGroup,
InputGroupAddon,
InputGroupInput,
InputGroupText,
joinedLeadingClasses,
} from '@dex/shared/components/input-group'
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from '@dex/shared/components/select'
import { cn } from '@dex/shared/utils/cn'
const CURRENCIES = { GBP: 'GBP (£)', EUR: 'EUR (€)', USD: 'USD ($)' }
export function JoinedFieldTextAtTheEnd() {
return (
<Field className="max-w-sm">
<FieldLabel>Minimum base salary</FieldLabel>
<InputGroup>
<Select items={CURRENCIES} defaultValue="GBP">
<SelectTrigger aria-label="Currency" className={cn(joinedLeadingClasses, 'w-28')}>
<SelectValue />
</SelectTrigger>
<SelectContent>
{Object.entries(CURRENCIES).map(([code, label]) => (
<SelectItem key={code} value={code}>
{label}
</SelectItem>
))}
</SelectContent>
</Select>
<FieldControl>
<InputGroupInput inputMode="numeric" defaultValue="110,000" />
</FieldControl>
<InputGroupAddon align="inline-end">
<InputGroupText className="text-muted-foreground">per year</InputGroupText>
</InputGroupAddon>
</InputGroup>
</Field>
)
}
import { Search } from 'lucide-react'
import { InputGroup, InputGroupAddon, InputGroupInput } from '@dex/shared/components/input-group'
export function JoinedFieldIconAtTheStart() {
return (
<InputGroup className="max-w-sm">
<InputGroupAddon>
<Search />
</InputGroupAddon>
<InputGroupInput aria-label="Search roles" placeholder="Search roles" />
</InputGroup>
)
}
Enter your minimum salary.
'use client'
import { Field, FieldControl, FieldLabel, FieldMessage } from '@dex/shared/components/field'
import {
InputGroup,
InputGroupInput,
joinedLeadingClasses,
} from '@dex/shared/components/input-group'
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from '@dex/shared/components/select'
import { cn } from '@dex/shared/utils/cn'
const CURRENCIES = { GBP: 'GBP (£)', EUR: 'EUR (€)', USD: 'USD ($)' }
export function JoinedFieldInvalid() {
return (
<Field invalid className="max-w-sm">
<FieldLabel>Minimum base salary</FieldLabel>
<InputGroup>
<Select items={CURRENCIES} defaultValue="GBP">
<SelectTrigger aria-label="Currency" className={cn(joinedLeadingClasses, 'w-28')}>
<SelectValue />
</SelectTrigger>
<SelectContent>
{Object.entries(CURRENCIES).map(([code, label]) => (
<SelectItem key={code} value={code}>
{label}
</SelectItem>
))}
</SelectContent>
</Select>
<FieldControl>
<InputGroupInput inputMode="numeric" placeholder="Enter amount" />
</FieldControl>
</InputGroup>
<FieldMessage error="Enter your minimum salary." />
</Field>
)
}
'use client'
import { Field, FieldControl, FieldLabel } from '@dex/shared/components/field'
import {
InputGroup,
InputGroupInput,
joinedLeadingClasses,
} from '@dex/shared/components/input-group'
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from '@dex/shared/components/select'
import { cn } from '@dex/shared/utils/cn'
export function JoinedFieldDisabled() {
return (
<Field disabled className="max-w-sm">
<FieldLabel>Minimum base salary</FieldLabel>
<InputGroup>
<Select items={{ GBP: 'GBP (£)' }} defaultValue="GBP" disabled>
<SelectTrigger aria-label="Currency" className={cn(joinedLeadingClasses, 'w-28')}>
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="GBP">GBP (£)</SelectItem>
</SelectContent>
</Select>
<FieldControl>
<InputGroupInput inputMode="numeric" defaultValue="110,000" disabled />
</FieldControl>
</InputGroup>
</Field>
)
}
Set by Northwind on the role.
import { LockIcon } from 'lucide-react'
import { Field, FieldControl, FieldLabel, FieldMessage } from '@dex/shared/components/field'
import { InputGroup, InputGroupAddon, InputGroupInput } from '@dex/shared/components/input-group'
import { readOnlyIconClasses } from '@dex/shared/styles/control-styles'
export function JoinedFieldReadOnly() {
return (
<Field className="max-w-sm">
<FieldLabel>Salary band</FieldLabel>
<InputGroup>
<span className="flex h-full w-28 shrink-0 items-center border-r border-control-border-subtle px-3.5 text-base text-foreground">
GBP (£)
</span>
<FieldControl>
<InputGroupInput readOnly defaultValue="95,000–120,000" />
</FieldControl>
<InputGroupAddon align="inline-end">
<LockIcon aria-hidden className={readOnlyIconClasses} />
</InputGroupAddon>
</InputGroup>
<FieldMessage description="Set by Northwind on the role." />
</Field>
)
}
- Use a joined field for any control and input that make one answer, such as a currency and an amount. The phone input is built the same way.
- The group is the field. Hover, focus, error, disabled and read-only show on the outer border, whichever part caused them, and the parts' own focus styles are hidden.
- Give the leading control
joinedLeadingClassesand a width, and anaria-label, since the field's label names the input. FieldControlgoes round the input, not the group. The group takes its error, disabled and read-only states from the input.- An input from another library joins the group by taking
data-slot="input-group-control", as the currency input on the application form does. - A read-only joined field shows the leading value as plain text, with no chevron, and a lock at the end.