Select
A native select with label, help text, option groups, invalid and disabled states.
Installation
bash
npx bootcn add selectbash
pnpm dlx bootcn add selectbash
yarn dlx bootcn add selectbash
bunx --bun bootcn add selectThe CLI also installs the design tokens and these components: input. It prints the <link> and <script> tags to add to your layout.
Usage
html
<div class="bootcn-field">
<label for="country" class="form-label bootcn-field__label">Country</label>
<select
class="form-select bootcn-select"
id="country"
name="country"
aria-describedby="country-help"
>
<option value="">Choose a country</option>
<option value="gr">Greece</option>
</select>
<p class="bootcn-field__help" id="country-help">Used for tax calculation.</p>
</div>The bootcn-field, bootcn-field__label and bootcn-field__help classes come from the Input component's stylesheet. Install input too (it is a registry dependency) or replace them with Bootstrap's mb-3/form-text.
States
- Invalid:
aria-invalid="true"plus an.invalid-feedbackelement referenced fromaria-describedby. - Disabled: the native
disabledattribute. - Option groups: native
<optgroup label>.
A searchable multi-select is a separate, JavaScript-based component planned for later.
Dependencies
- Bootstrap 5.3+ CSS.
themes/tokens/tokens.css,input(field layout classes).
No JavaScript.
Accessibility
- Always pair the select with a
<label for>. - Use an empty first option as a prompt rather than a placeholder-only label.
Source
The exact files the CLI installs (select@1.1.0). View on GitHub · Report an issue
html
<div class="bootcn-field">
<label for="bootcn-select-country" class="form-label bootcn-field__label">Country</label>
<select
class="form-select bootcn-select"
id="bootcn-select-country"
name="country"
aria-describedby="bootcn-select-country-help"
>
<option value="">Choose a country</option>
<option value="gr" selected>Greece</option>
<option value="cy">Cyprus</option>
<option value="it">Italy</option>
</select>
<p class="bootcn-field__help" id="bootcn-select-country-help">Used for tax calculation.</p>
</div>
<div class="bootcn-field mt-3">
<label for="bootcn-select-timezone" class="form-label bootcn-field__label">Timezone</label>
<select class="form-select bootcn-select" id="bootcn-select-timezone" name="timezone">
<optgroup label="Europe">
<option value="Europe/Athens">Athens</option>
<option value="Europe/Berlin">Berlin</option>
</optgroup>
<optgroup label="America">
<option value="America/New_York">New York</option>
</optgroup>
</select>
</div>
<div class="bootcn-field mt-3">
<label for="bootcn-select-role" class="form-label bootcn-field__label">Role</label>
<select
class="form-select bootcn-select"
id="bootcn-select-role"
name="role"
required
aria-invalid="true"
aria-describedby="bootcn-select-role-error"
>
<option value="" selected>Choose a role</option>
<option value="admin">Admin</option>
<option value="member">Member</option>
</select>
<div class="invalid-feedback" id="bootcn-select-role-error">Choose a role.</div>
</div>
<div class="bootcn-field mt-3">
<label for="bootcn-select-disabled" class="form-label bootcn-field__label">Disabled</label>
<select class="form-select bootcn-select" id="bootcn-select-disabled" disabled>
<option>Not available</option>
</select>
</div>css
.bootcn-select {
min-height: var(--bootcn-control-height);
border-color: var(--bootcn-input);
border-radius: var(--bootcn-radius);
background-color: transparent;
box-shadow: var(--bootcn-shadow-sm);
font-size: 1rem;
cursor: pointer;
transition:
border-color var(--bootcn-transition),
box-shadow var(--bootcn-transition);
}
.bootcn-select:focus {
outline: 0;
border-color: var(--bootcn-ring);
box-shadow: 0 0 0 3px var(--bs-focus-ring-color);
}
.bootcn-select:disabled {
cursor: not-allowed;
}
.bootcn-select[aria-invalid='true'] {
border-color: var(--bs-danger);
}
.bootcn-select[aria-invalid='true']:focus {
border-color: var(--bs-danger);
box-shadow: 0 0 0 3px rgba(var(--bs-danger-rgb), 0.2);
}
.bootcn-select[aria-invalid='true'] ~ .invalid-feedback {
display: block;
}
/* text-base on phones (no zoom on focus in iOS Safari), text-sm from md. */
@media (min-width: 768px) {
.bootcn-select {
font-size: var(--bootcn-control-font-size);
}
}
