Components/Forms/Select
COMPONENT06.06

Select

Custom listbox on the Popover API — trigger button plus popover list with check mark, groups and disabled options. Native select stays for simple forms.


INSTALL

1pnpm dlx @sayagodev/mo add select

Or import the files from the package (no copy):

1import "@sayagodev/mo/css/select.css";2import "@sayagodev/mo/css/shared.css";3import "@sayagodev/mo/js/select.js";

EXAMPLES

Basic
Groups
  • Fruits

  • Vegetables
Disabled
Fully disabled
Invalid
Scrollable

USAGE

1<mo-select data-placeholder="Select a fruit">2  <button type="button" popovertarget="sel1" data-select-trigger aria-label="Fruit"></button>3  <ul popover id="sel1" class="popover" role="listbox" aria-label="Fruits">4    <li><button type="button" role="option" value="apple">Apple</button></li>5    <li><button type="button" role="option" disabled>Banana</button></li>6    <li role="group"><div data-label>Citrus</div>7      <button type="button" role="option" value="lemon">Lemon</button>8    </li>9  </ul>10</mo-select>

API

NAMEKINDDESCRIPTION
<mo-select>elementOrchestrator: roving [aria-selected], typeahead, placement with flip; emits mo-select-change
data-placeholderattributeTrigger label while no value is chosen (dimmed via [data-empty])
[data-select-trigger]attributeTrigger button; chevron drawn via ::after
[role=option] + valueattributeOption row; text is the label, value feeds events (falls back to the text)
disabled / aria-disabledattributeSkipped by arrows and typeahead, unclickable
[data-label]attributeGroup heading inside li[role=group]
mo-select-changeelementEvent, detail { value } on pick
--mo-select-*tokenheight, padding-x, radius, min-width, max-height hooks

FILES

src/css/select.csssrc/css/shared.csssrc/js/select.js
Install:mo add select

THEMING · PLAYGROUND

This is the exact component from the examples above, wearing a completely different theme. Edit the tokens and --mo-* hooks in the editor — autocomplete knows them all — and the preview obeys in real time. Your CSS always wins.

Tokens & hooks — edit live
Global tokens
--accent--accent-foreground--border--destructive--foreground--input--muted-foreground--radius--ring
Component hooks
--mo-select-height--mo-select-max-height--mo-select-min-width--mo-select-padding-x--mo-select-radius

Preview

Your CSS

Try it: type --mo- for the component hooks, or edit any value — the preview obeys in real time.