Interactive
Select (custom)
A fully custom select over a native one, which stays in the form with its value and change events in sync. Options can carry an icon, an image, a color or a description, optgroups become headings, long lists get a search box, multiple shows chips, and it can be clearable. Keyboard and screen readers follow the WAI-ARIA select only combobox pattern, and the size, tone and variant classes of .select carry over. Needs monsoon.js.
Needs monsoon.js. The styles work on their own, and the behavior comes from the optional interactive layer: add <script src="https://cdn.jsdelivr.net/npm/monsooncss/dist/monsoon.js" defer></script> or import 'monsooncss/js'. See the interactive layer.
Example
JavaScript API
Attribute
data-m-select
Options
| Option | Description |
|---|---|
data-m-select-search (on by default from 10 options, "false" turns it off) | |
data-m-select-clearable | |
data-m-select-placeholder="Pick one" (or an empty first option) | |
multiple on the select | |
data-description, data-icon, data-image or data-color on an option | |
select-xs to select-xl, select-primary, select-ghost and select-filled |
Methods
| Method | Description |
|---|---|
Monsoon.select(el).open() | |
Monsoon.select(el).close() | |
Monsoon.select(el).value | |
Monsoon.select(el).value = "team" | |
Monsoon.select(el).refresh() after changing select.value in code |
Events
| Event | Description |
|---|---|
change and input on the native select | |
monsoon:change { value } |
Classes
22 classes. Click a name to copy it. Utilities on the same element always win over component defaults, so any of them can be adjusted with plain utility classes.
| Class | Type | What it does |
|---|---|---|
| Base | Base class of the select (custom). Not used in the example above. Sets block display, width, height, padding, alignment and gap, and --tone and --tone-fg.CSS |
|
| Modifier | Modifier, combined with the select-menu class. Not used in the example above. Sets flex display, alignment, gap, text style, background and shadow, and --_line and --_line.CSS |
|
| Modifier | Modifier, combined with the select-menu class. Not used in the example above. Sets flex display, alignment, gap, width, overflow and text style.CSS |
|
| Modifier | Modifier, combined with the select-menu class. Not used in the example above. Sets overflow, text style and text color.CSS |
|
| Modifier | Modifier, combined with the select-menu class. Not used in the example above. Sets overflow and text style.CSS |
|
| Modifier | Modifier, combined with the select-menu class. Not used in the example above. Sets absolute position, offsets, grid display, alignment, width and height.CSS |
|
| Modifier | Modifier, combined with the select-menu class. Not used in the example above. Sets fixed position, offsets, stacking order, margin, padding and text color, and --tone.CSS |
|
| Modifier | Modifier, combined with the select-menu class. Not used in the example above. Sets alignment and margin.CSS |
|
| Modifier | Modifier, combined with the select-menu class. Not used in the example above. Sets alignment, height, overflow and border.CSS |
|
| Modifier | Modifier, combined with the select-menu class. Not used in the example above. Sets flex display, alignment, gap, padding, corner radius and pointer cursor.CSS |
|
| Modifier | Modifier, combined with the select-menu class. Not used in the example above. Sets grid display and width.CSS |
|
| Modifier | Modifier, combined with the select-menu class. Not used in the example above. Sets text size, font weight, text style and text color.CSS |
|
| Modifier | Modifier, combined with the select-menu class. Not used in the example above. Sets grid display, alignment, width, height, text color and text style.CSS |
|
| Modifier | Modifier, combined with the select-menu class. Not used in the example above. Sets alignment, width, height and corner radius.CSS |
|
| Modifier | Modifier, combined with the select-menu class. Not used in the example above. Sets alignment, width, height, background, corner radius and shadow.CSS |
|
| Modifier | Modifier, combined with the select-menu class. Not used in the example above. Sets margin, padding and border.CSS |
|
| Modifier | Modifier, combined with the select-menu class. Not used in the example above. Sets padding, text size, font weight and text color.CSS |
|
| Modifier | Modifier, combined with the select-menu class. Not used in the example above. Sets padding, text style and text color.CSS |
|
| Modifier | Modifier, combined with the select-menu class. Not used in the example above. Sets width.CSS |
|
| Modifier | Modifier, combined with the select-menu class. Not used in the example above. Sets grid display, alignment, width, height, margin and corner radius.CSS |
|
| Part | Part of the select (custom). On a <select> in the example. Sets block display, width, height, padding, text size and text style, and 9 custom properties.CSS |
|
| Part | Part of the select (custom). Not used in the example above. Sets block display, width, height, padding, text size and text style, and 9 custom properties.CSS |
Usage
The styles ship inside the same stylesheet as the utilities, and the behavior comes from the optional monsoon.js script, which enhances any element with a matching data-m attribute, including markup added later.
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/monsooncss">
<script src="https://cdn.jsdelivr.net/npm/monsooncss/dist/monsoon.js" defer></script>
<!-- Select (custom): start from the base class, then add modifiers -->
<div class="grid gap-4 max-w-sm">
<div class="field">
<label class="label" for="sm-plan">Plan</label>
<select id="sm-plan" class="select" name="plan" data-m-select>
<option value="">Choose a plan</option>
<option value="hobby" data-description="One project, community support">Hobby</option>
<option value="team" data-description="Up to 20 seats and shared billing" selected>Team</option>
<option value="business" data-description="SSO, audit logs and a 99.9% SLA">Business</option>
<option value="enterprise" data-description="Talk to sales" disabled>Enterprise</option>
</select>
</div>
<select class="select" data-m-select data-m-select-clearable aria-label="Status">
<option value="">Any status</option>
<option value="todo" data-color="var(--muted-foreground)">To do</option>
<!-- the full example is in the Code tab above -->Theme it with --seed on any ancestor, for example style="--seed: #0d9488", and force a scheme with class="dark" or class="light" on a wrapper.
Accessibility
- Give every control a visible
labellinked withfor, or anaria-labelwhen the purpose is obvious from context. Link help and error text witharia-describedby; invalid styles use:user-invalid, so they appear only after the user interacts. - Every interactive part shows a visible focus ring with
:focus-visible, and tone colors pair with-foregroundtokens that keep text at 4.5:1 or better in light and dark mode.