Form adorn
Decorate inputs with icons, text, and more using a custom wrapper that easily handles styling and positioning.
How it works
Wrap adornments and a FormGhost control in FormAdornment. The wrapper provides the border, background, padding, and focus states, and uses flexbox to position adornments beside the visually unstyled FormGhost, which inherits the wrapper's styles.
FormAdornment renders a label by default. This lets people click the icon, text, or surrounding padding to focus the control without any JavaScript.
Mark decorative FormAdornmentIcon and FormAdornmentText components with aria-hidden="true". Because the default FormAdornment label also labels its nested input, text adornments such as $ can become part of the input's accessible name. Keep decorative content out of the accessibility tree, and provide meaningful names with FormLabel or visible label text and descriptions with FormText.
An input can have more than one label, so the default
FormAdornmentlabel and a separateFormLabelcan work together. SetFormLabel'shtmlForto the input'sid. Do not put a button or another interactive control inside the defaultFormAdornmentlabel. If the wrapper needs interactive content, use itsasprop to render a non-label element and label the input separately.
See the form control documentation for more information on FormControl and FormGhost.
Example
Use FormAdornment to wrap an icon and a FormGhost input. Place the adornment before the input in the DOM to position it at the start (left in LTR).
<FormAdornment>
<FormAdornmentIcon
aria-hidden="true"
name="search"
/>
<FormGhost
placeholder="Search..."
type="search"
/>
</FormAdornment>Set the end prop to position the adornment on the trailing side. The DOM order stays the same while the visual order changes:
<FormAdornment end>
<FormAdornmentIcon
aria-hidden="true"
name="envelope"
/>
<FormGhost
placeholder="you@example.com"
type="email"
/>
</FormAdornment>With labels
Add a FormLabel outside FormAdornment to give the field a visible name. Set its htmlFor prop to the id of the FormGhost input so the label remains associated with the field if you change the wrapper:
<Stack gap={3}>
<div>
<FormLabel htmlFor="searchInput">
Search
</FormLabel>
<FormAdornment>
<FormAdornmentIcon
aria-hidden="true"
name="search"
/>
<FormGhost
id="searchInput"
placeholder="Search..."
type="search"
/>
</FormAdornment>
</div>
<div>
<FormLabel htmlFor="emailInput">
Email address
</FormLabel>
<FormAdornment end>
<FormAdornmentIcon
aria-hidden="true"
name="envelope"
/>
<FormGhost
id="emailInput"
placeholder="you@example.com"
type="email"
/>
</FormAdornment>
</div>
</Stack>With form field
Use FormField to group FormLabel, FormAdornment, and FormText into a field with a label and description.
<FormField>
<FormLabel htmlFor="adornField">
Search
</FormLabel>
<FormAdornment>
<FormAdornmentIcon
aria-hidden="true"
name="search"
/>
<FormGhost
id="adornField"
placeholder="Search..."
type="search"
/>
</FormAdornment>
<FormText>
Search across all pages and posts.
</FormText>
</FormField>Text adornments
Use FormAdornmentText for currency symbols, units, domain suffixes, and other text-based adornments. Text adornments auto-size to their content.
<Stack gap={3}>
<FormAdornment>
<FormAdornmentText aria-hidden="true">
$
</FormAdornmentText>
<FormGhost
placeholder="0.00"
type="text"
/>
</FormAdornment>
<FormAdornment end>
<FormAdornmentText aria-hidden="true">
USD
</FormAdornmentText>
<FormGhost
placeholder="Amount"
type="text"
/>
</FormAdornment>
<FormAdornment>
<FormAdornmentText aria-hidden="true">
https://
</FormAdornmentText>
<FormGhost
placeholder="example.com"
type="text"
/>
</FormAdornment>
<FormAdornment end>
<FormAdornmentText aria-hidden="true">
@example.com
</FormAdornmentText>
<FormGhost
placeholder="username"
type="text"
/>
</FormAdornment>
</Stack>Sizing
Set the size prop to sm or lg on FormAdornment to adjust its size.
<Stack gap={3}>
<FormAdornment size="sm">
<FormAdornmentIcon
aria-hidden="true"
name="search"
/>
<FormGhost
placeholder="Small input"
type="text"
/>
</FormAdornment>
<FormAdornment>
<FormAdornmentIcon
aria-hidden="true"
name="search"
/>
<FormGhost
placeholder="Default input"
type="text"
/>
</FormAdornment>
<FormAdornment size="lg">
<FormAdornmentIcon
aria-hidden="true"
name="search"
/>
<FormGhost
placeholder="Large input"
type="text"
/>
</FormAdornment>
</Stack>CSS
Variables
.example {
--bs-form-adorn-gap: 0.375rem;
--bs-form-adorn-icon-size: 1rem;
--bs-form-adorn-icon-color: var(--bs-fg-2);
}