Components
Input
A single line of text, such as a job title, an email address, a URL or a number.
import { Input } from '@dex/shared/components/input'
export function InputDefault() {
return (
<div className="w-full max-w-sm">
<Input aria-label="Job title" placeholder="e.g. Staff engineer" />
</div>
)
}
As it reads on your CV.
import { Field, FieldControl, FieldLabel, FieldMessage } from '@dex/shared/components/field'
import { Input } from '@dex/shared/components/input'
export function InputInAField() {
return (
<Field className="max-w-sm">
<FieldLabel>Current job title</FieldLabel>
<FieldControl>
<Input placeholder="e.g. Staff engineer" />
</FieldControl>
<FieldMessage description="As it reads on your CV." />
</Field>
)
}
A portfolio, a blog or your GitHub profile.
import { Field, FieldControl, FieldLabel, FieldMessage } from '@dex/shared/components/field'
import { Input } from '@dex/shared/components/input'
export function InputOptional() {
return (
<Field className="max-w-sm">
<FieldLabel optional>Personal website</FieldLabel>
<FieldControl>
<Input type="url" placeholder="https://" />
</FieldControl>
<FieldMessage description="A portfolio, a blog or your GitHub profile." />
</Field>
)
}
Enter an email address like name@company.com.
import { Field, FieldControl, FieldLabel, FieldMessage } from '@dex/shared/components/field'
import { Input } from '@dex/shared/components/input'
export function InputInvalid() {
return (
<Field invalid className="max-w-sm">
<FieldLabel>Work email</FieldLabel>
<FieldControl>
<Input type="email" defaultValue="sam@northwind" />
</FieldControl>
<FieldMessage
description="We only use this to contact you about roles."
error="Enter an email address like name@company.com."
/>
</Field>
)
}
import { Field, FieldControl, FieldLabel } from '@dex/shared/components/field'
import { Input } from '@dex/shared/components/input'
export function InputDisabled() {
return (
<Field disabled className="max-w-sm">
<FieldLabel>Work email</FieldLabel>
<FieldControl>
<Input type="email" defaultValue="sam@northwind.io" disabled />
</FieldControl>
</Field>
)
}
From your LinkedIn sign-in.
import { Field, FieldControl, FieldLabel, FieldMessage } from '@dex/shared/components/field'
import { Input } from '@dex/shared/components/input'
export function InputReadOnly() {
return (
<Field className="max-w-sm">
<FieldLabel>Email</FieldLabel>
<FieldControl>
<Input type="email" defaultValue="sam@northwind.io" readOnly />
</FieldControl>
<FieldMessage description="From your LinkedIn sign-in." />
</Field>
)
}
- Put an input in a
Field: a label, the control, then helper text or an error.Fieldconnects the three, so the label focuses the input and a screen reader reads the message with it. - Give
FieldMessagethe helper text and the error together. The error shows in the helper text's place, and the label keeps its colour. - Write an error as one sentence that says what to do: "Enter your work email.", "Choose a notice period.". Never "Please", "required", "invalid" or "This field".
- Give a read-only input helper text saying where the value came from.
- The text is 16px at every screen size, so a phone does not zoom in when the input takes focus. Leave it at that size.