Select
Write a normal <select class="form-select"> — Moey shows a clean dropdown instead of the browser's list. The select is still there, so forms, validation and your code work exactly as before.
<label class="form-label" for="shipping">Shipping</label>
<select class="form-select" id="shipping" name="shipping">
<option>Standard</option>
<option selected>Express</option>
<option>Overnight</option>
</select>
- Mouse, touch or keyboard: ↓ / Enter / Space opens, arrows move, Enter picks, Esc closes, Tab picks and moves on, and typing a letter jumps to an option — like the browser's select.
- The hidden
<select>always holds the value:select.value,changeevents,FormDataandrequiredall just work — even settingselect.value = 'Overnight'from code updates the field. - Screen readers hear a real select (a combobox with a list of options).
Placeholder and required
An empty, disabled first option is the placeholder. required is checked by the browser as usual.
<select class="form-select" name="country" required>
<option value="" disabled selected>Choose a country</option>
<option>Argentina</option>
…
</select>
That list has 43 options, so it got a search box by itself (more than 10). Force it either way with data-moey-search="true" or "false".
Groups, icons, details and colors
<select class="form-select">
<optgroup label="Express">
<option data-moey-icon="zap" data-moey-detail="Next day">Moey Express</option>
</optgroup>
<optgroup label="Standard">
<option data-moey-icon="truck" data-moey-detail="3–5 days" selected>Ground</option>
<option disabled>Pick up (unavailable)</option>
</optgroup>
</select>
<option data-moey-color="green">Paid</option> <!-- a colored dot -->
Multiple
With multiple the list shows checkmarks and stays open while you pick. The field lists what's chosen.
<select class="form-select" name="notify" multiple placeholder="Nothing yet">
<option selected>New orders</option>
<option>Refunds</option>
…
</select>
Sizes, states and colors
<select class="form-select form-select-sm" aria-label="Small">
<option>Small</option>
<option>Two</option>
</select>
<select class="form-select" aria-label="Default">
<option>Default</option>
<option>Two</option>
</select>
<select class="form-select form-select-lg" aria-label="Large">
<option>Large</option>
<option>Two</option>
</select>
<select class="form-select" aria-label="Disabled" disabled>
<option>Disabled</option>
</select>
<select class="form-select theme-pink" aria-label="Pink">
<option>theme-pink (focus & checks)</option>
<option>Two</option>
</select>
Changing it from code
Set the value like on any select — the field follows. After adding or removing options, it follows too (Moey watches the select).
select.value = 'Team'; // the field updates
select.add(new Option('Enterprise', 'Enterprise', true, true)); // so does the list
select.addEventListener('change', () => save(select.value));
Keep the browser's select
Add data-moey-native to a select (or to a form around it) to keep the browser's own list — for example on a page where you want the phone's wheel picker.
<select class="form-select" data-moey-native>…</select>
| Attribute | What it does |
|---|---|
<option value="" disabled selected> | A placeholder (not offered as a choice) |
<optgroup label> · disabled | A header in the list · an option (or group) that can't be picked |
data-moey-icon="truck" · data-moey-detail="…" · data-moey-color="green" | On an option: an icon · a second line · a colored dot |
multiple · placeholder | Pick several (checkmarks, stays open) · text when nothing's picked |
data-moey-search="true|false" | A search box in the list (automatic above 10 options) |
data-moey-native | Keep the browser's select |
Moey.select(el) | Enhance a select now / refresh it (normally automatic) |