Input group
An input with icons, text or buttons inside the same border, such as a search box or a URL field.
Installation
Usage
Put the input (.bootcn-input-group__input) and its addons inside .bootcn-input-group. Addons can hold an icon, text or a small button. The group draws one border and one focus ring around everything.
Unlike Bootstrap's .input-group, the addons sit inside the field.
Accessibility
- The input still needs its own
<label>; addon text is not part of its name. - An icon-only button inside the group needs visually hidden text.
- The focus ring appears on the whole group when the input is focused.
Dependencies
- Bootstrap 5.3+ CSS.
themes/tokens/tokens.css.- The
buttoncomponent. - The
labelcomponent.
Source
The exact files the CLI installs (input-group@1.0.0). View on GitHub · Report an issue
html
<div class="bootcn-field">
<label class="bootcn-label" for="bootcn-input-group-search">Search</label>
<div class="bootcn-input-group">
<span class="bootcn-input-group__addon"
><svg
class="bootcn-icon"
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
focusable="false"
>
<circle cx="11" cy="11" r="7" />
<path d="m20 20-3.5-3.5" /></svg
></span>
<input
class="bootcn-input-group__input"
type="search"
id="bootcn-input-group-search"
name="q"
placeholder="Search projects"
/>
<span class="bootcn-input-group__addon">12 results</span>
</div>
</div>
<div class="bootcn-field mt-3">
<label class="bootcn-label" for="bootcn-input-group-site">Website</label>
<div class="bootcn-input-group">
<span class="bootcn-input-group__addon">https://</span>
<input
class="bootcn-input-group__input"
type="text"
id="bootcn-input-group-site"
name="site"
placeholder="example"
/>
<span class="bootcn-input-group__addon">.com</span>
</div>
</div>
<div class="bootcn-field mt-3">
<label class="bootcn-label" for="bootcn-input-group-key">API key</label>
<div class="bootcn-input-group">
<input
class="bootcn-input-group__input"
type="text"
id="bootcn-input-group-key"
name="key"
value="sk_test_4f2a9c"
readonly
/>
<button
type="button"
class="btn bootcn-button bootcn-button--ghost bootcn-button--icon bootcn-button--sm bootcn-input-group__button"
>
<svg
class="bootcn-icon"
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
focusable="false"
>
<rect x="8" y="8" width="13" height="13" rx="2" />
<path d="M16 8V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h3" />
</svg>
<span class="visually-hidden">Copy API key</span>
</button>
</div>
</div>css
.bootcn-input-group {
display: flex;
align-items: center;
min-height: var(--bootcn-control-height);
border: var(--bootcn-border-width) solid var(--bootcn-input);
border-radius: var(--bootcn-radius);
background-color: transparent;
box-shadow: var(--bootcn-shadow-sm);
transition:
border-color var(--bootcn-transition),
box-shadow var(--bootcn-transition);
}
.bootcn-input-group:focus-within {
border-color: var(--bootcn-ring);
box-shadow: 0 0 0 3px var(--bs-focus-ring-color);
}
.bootcn-input-group__input {
flex: 1 1 auto;
min-width: 0;
height: 100%;
padding: var(--bootcn-control-padding-y) var(--bootcn-control-padding-x);
border: 0;
background: transparent;
color: var(--bootcn-foreground);
font-size: 1rem;
outline: 0;
}
.bootcn-input-group__input::placeholder {
color: var(--bootcn-muted-foreground);
}
@media (min-width: 768px) {
.bootcn-input-group__input {
font-size: var(--bootcn-control-font-size);
}
}
.bootcn-input-group__addon {
display: inline-flex;
flex: none;
align-items: center;
gap: 0.375rem;
padding: 0 var(--bootcn-control-padding-x);
color: var(--bootcn-muted-foreground);
font-size: 0.875rem;
white-space: nowrap;
}
.bootcn-input-group__addon + .bootcn-input-group__input {
padding-left: 0;
}
.bootcn-input-group__input + .bootcn-input-group__addon {
padding-left: 0;
}
.bootcn-input-group__button {
margin-right: 0.25rem;
}
