Select
Write a normal <select class="form-select">. momo.js turns it into a Momo dropdown that looks and works the same in every browser, iPhone included. The real select stays underneath, in sync, so forms and validation keep working.
Basic
<div class="form-field">
<label class="form-label" for="sel-role">Role</label>
<select class="form-select" id="sel-role">
<option>Designer</option>
<option selected>Developer</option>
<option>Manager</option>
<option disabled>Owner (only one)</option>
</select>
</div>Placeholder
An empty, disabled first option is shown as grey placeholder text, not as a choice.
<div class="form-field">
<label class="form-label" for="sel-country">Country</label>
<select class="form-select" id="sel-country" required>
<option value="" disabled selected>Choose a country</option>
<option value="ca">Canada</option>
<option value="us">United States</option>
<option value="mx">Mexico</option>
</select>
</div>Icons and descriptions
Add data-icon (a Moey icon name) and data-desc (a second line) on options.
<div class="form-field">
<label class="form-label" for="sel-status">Status</label>
<select class="form-select" id="sel-status">
<option value="todo" data-icon="circle-dashed" data-desc="Not started yet">To do</option>
<option value="doing" data-icon="loader" data-desc="Someone is on it" selected>In progress</option>
<option value="review" data-icon="eye" data-desc="Waiting for a check">In review</option>
<option value="done" data-icon="circle-check" data-desc="Shipped">Done</option>
</select>
</div>Search
Add data-momo-search for long lists: a search box sits at the top and filters as you type.
<div class="form-field">
<label class="form-label" for="sel-tz">Time zone</label>
<select class="form-select" id="sel-tz" data-momo-search>
<optgroup label="Americas">
<option>Vancouver (PST)</option>
<option>Denver (MST)</option>
<option>Chicago (CST)</option>
<option selected>Toronto (EST)</option>
<option>Halifax (AST)</option>
<option>São Paulo (BRT)</option>
</optgroup>
<optgroup label="Europe">
<option>London (GMT)</option>
<option>Paris (CET)</option>
<option>Athens (EET)</option>
</optgroup>
<optgroup label="Asia and Pacific">
<option>Dubai (GST)</option>
<option>Tokyo (JST)</option>
<option>Sydney (AEST)</option>
</optgroup>
</select>
</div>Multiple
With multiple, each option gets a check box and the list stays open while you pick.
<div class="form-field">
<label class="form-label" for="sel-skills">Skills</label>
<select class="form-select" id="sel-skills" multiple>
<option selected>Business</option>
<option>Marketing</option>
<option selected>Interface design</option>
<option>User experience</option>
<option>Development</option>
<option>Mobile app</option>
</select>
</div>Sizes, states and groups
Classes on the select carry over: .form-control-sm, .form-control-lg, .is-invalid. disabled works. It also fits in an .input-group.
Choose a plan to continue.
<div class="form-grid">
<div class="form-field">
<label class="form-label" for="sel-sm">Small</label>
<select class="form-select form-control-sm" id="sel-sm"><option>Weekly</option><option>Monthly</option></select>
</div>
<div class="form-field">
<label class="form-label" for="sel-off">Disabled</label>
<select class="form-select" id="sel-off" disabled><option>Locked</option></select>
</div>
<div class="form-field">
<label class="form-label" for="sel-bad">With an error</label>
<select class="form-select is-invalid" id="sel-bad" aria-invalid="true" aria-describedby="sel-bad-msg"><option value="" disabled selected>Pick a plan</option><option>Basic</option><option>Pro</option></select>
<p class="form-error" id="sel-bad-msg"><i class="mi mi-circle-alert"></i> Choose a plan to continue.</p>
</div>
<div class="form-field">
<label class="form-label" for="sel-amt">Amount</label>
<div class="input-group">
<input class="form-control" id="sel-amt" inputmode="decimal" placeholder="0.00">
<select class="form-select" aria-label="Currency"><option>USD</option><option>CAD</option><option>EUR</option></select>
</div>
</div>
</div>Keep the browser select
Add data-momo-native to skip the Momo dropdown. In Chrome and Edge the open list is still styled by CSS.
<div class="form-field">
<label class="form-label" for="sel-native">Native</label>
<select class="form-select" id="sel-native" data-momo-native><option>One</option><option>Two</option></select>
</div>Phones
On small touch screens the list opens as a bottom sheet with bigger rows; tap outside or pick to close it.
Keyboard
| Key | Does |
|---|---|
| ↓ ↑ Enter Space | Open the list (closed), move or pick (open) |
| Home End PgUp PgDn | Jump in the list |
| Letters | Jump to the option that starts with them |
| Esc | Close and go back to the button |
| Tab | Close and move on |
JavaScript
Selects are set up on load and when added to the page later. Listen to change on the real select as usual. If you change its options or value in code, call:
Momo.select.refresh(document.querySelector('#role'));