Skip to content
v0.9.1
Forms

Combobox

A text field with suggestions. Point any input at a <datalist> and it gets a Momo suggestion list instead of the browser's: typing filters it, best matches first, and capitals and accents don't matter.

Suggestions

Anything can be typed; the list only suggests. A tap on the field shows everything. Add data-detail for a second line and data-group for headings.

<div class="form-field w-72">
  <label class="form-label" for="cb-city">City</label>
  <input class="form-control" id="cb-city" name="city" list="cb-cities" placeholder="Try &quot;sao&quot;">
  <datalist id="cb-cities">
    <option value="Lisbon" data-detail="Portugal">
    <option value="Porto" data-detail="Portugal">
    <option value="São Paulo" data-detail="Brazil">
    <option value="Rio de Janeiro" data-detail="Brazil">
    <option value="Montréal" data-detail="Canada">
    <option value="Toronto" data-detail="Canada">
    <option value="Vancouver" data-detail="Canada">
    <option value="Mexico City" data-detail="Mexico">
    <option value="Seoul" data-detail="South Korea">
    <option value="Tokyo" data-detail="Japan">
    <option value="Osaka" data-detail="Japan">
    <option value="Berlin" data-detail="Germany">
  </datalist>
</div>

Only values from the list

data-strict: the first match is highlighted so Enter or Tab takes it, capitals are fixed ("ana kim" becomes "Ana Kim"), and anything else makes the field invalid. data-id-field also fills a hidden input with the option's data-id, so the server gets an id, not a name. data-color adds a dot, data-icon a Moey icon.

Pick someone from the team.

<form class="form-field w-72" id="cb-assign" onsubmit="event.preventDefault();Momo.toast({ title: 'Assigned', text: 'id ' + this.assignee_id.value, color: 'green' })">
  <label class="form-label" for="cb-assignee">Assign to</label>
  <input class="form-control" id="cb-assignee" list="cb-team" data-strict data-id-field="#cb-assignee-id" required>
  <input type="hidden" name="assignee_id" id="cb-assignee-id">
  <datalist id="cb-team">
    <option value="Ana Kim" data-detail="Design" data-color="pink" data-id="u-101">
    <option value="Max Ruiz" data-detail="Support" data-color="cyan" data-id="u-102">
    <option value="Lea Novak" data-detail="Engineering" data-color="lime" data-id="u-103">
    <option value="Sam Okafor" data-detail="Sales" data-color="yellow" data-id="u-104">
  </datalist>
  <p class="form-hint">Pick someone from the team.</p>
  <div><button class="btn btn-brand mt-2" type="submit">Assign</button></div>
</form>

Add new values

data-create offers Add "..." when nothing matches. It fires momo:create: cancel it to say no, or save the value to your server. The value is added to the list.

<div class="form-field w-72">
  <label class="form-label" for="cb-cat">Product category</label>
  <input class="form-control" id="cb-cat" list="cb-cats" data-create>
  <datalist id="cb-cats">
    <option value="Mugs" data-group="Kitchen" data-icon="coffee">
    <option value="Plates" data-group="Kitchen" data-icon="utensils">
    <option value="Totes" data-group="Bags" data-icon="shopping-bag">
    <option value="Backpacks" data-group="Bags" data-icon="backpack">
    <option value="Posters" data-group="Prints" data-icon="image">
  </datalist>
</div>
input.addEventListener('momo:create', (e) => {
  saveCategory(e.detail.value);           // or e.preventDefault() to refuse
});

From your server

data-source loads suggestions as people type; {q} is replaced with what was typed. Return a JSON array of strings, or of { value, label, detail, group, color, icon, id }. Requests wait until typing pauses (data-delay, default 200 ms), and an older request is cancelled when a newer one starts. data-min-chars sets how many letters it waits for (default 1).

<input class="form-control" data-momo-combobox data-source="/api/countries?q={q}">

Or hand it a function:

Loaded by a function, with a fake half-second wait.

<div class="form-field w-72">
  <label class="form-label" for="cb-customer">Customer</label>
  <input class="form-control" id="cb-customer" type="search" data-momo-combobox>
  <p class="form-hint">Loaded by a function, with a fake half-second wait.</p>
</div>
<script>
  addEventListener('DOMContentLoaded', () => Momo.combobox('#cb-customer', {
    source: async (query, signal) => {
      await new Promise((r) => setTimeout(r, 500));
      const people = [
        { name: 'Avery Chen', email: 'avery@example.com', id: 7 },
        { name: 'Bruno Silva', email: 'bruno@example.com', id: 8 },
        { name: 'Chloé Martin', email: 'chloe@example.com', id: 9 },
        { name: 'Dara Singh', email: 'dara@example.com', id: 10 },
      ];
      const q = query.toLowerCase();
      return people.filter((p) => p.name.toLowerCase().includes(q) || p.email.includes(q))
        .map((p) => ({ value: p.name, detail: p.email, id: p.id }));
    },
  }));
</script>

JavaScript

Momo.combobox('#customer', { source: async (query, signal) => [...] });
Momo.combobox.refresh('#city');          // read the datalist again after you change it
input.addEventListener('momo:pick', (e) => console.log(e.detail.value, e.detail.id));

The field fires input and change when a suggestion is picked. Screen readers hear the field as a combobox, the highlighted suggestion, and how many there are.

Need a fixed list with no typing? Use the Select. Several values? Use the Tag input.

Start

OverviewStart Getting startedStart CustomizeStart

Guides

AccessibilityGuides BreakpointsGuides ChangelogGuides Customize componentsGuides JavaScriptGuides MotionGuides OptimizeGuides PhonesGuides RebootGuides Right-to-left (RTL)Guides Stacking orderGuides Using Momo with AIGuides

Foundations

ColorsFoundations TypographyFoundations ProseFoundations Images & figuresFoundations CodeFoundations Lines & shadowsFoundations Dark modeFoundations

Forms

Checkbox & switchForms ComboboxForms Date pickerForms Date rangeForms Fields & labelsForms File uploadForms Floating labelsForms Number stepperForms PasswordForms PIN codeForms RatingForms SelectForms SliderForms Tag inputForms Time pickerForms ValidationForms

Components

AccordionComponents Alert & bannerComponents AvatarComponents BadgeComponents BreadcrumbComponents ButtonComponents Button groupComponents CalendarComponents CardComponents CarouselComponents ChartsComponents ChipsComponents CollapseComponents Command paletteComponents CommentsComponents Confirm dialogsComponents Cookie bannerComponents Data tableComponents Description listComponents Dialog & toastComponents DividerComponents DrawerComponents Dropdown menuComponents Empty stateComponents File managerComponents Filter & sortComponents Gallery & lightboxComponents Inbox & chatComponents Infinite scrollComponents KanbanComponents Keyboard shortcutsComponents List groupComponents MarqueeComponents Media objectComponents Nav overflowComponents Notification centerComponents PaginationComponents ProgressComponents Pull to refreshComponents SkeletonComponents SortableComponents SpinnerComponents Split viewComponents Stat cardComponents Steps & wizardComponents Swipe actionsComponents TableComponents TabsComponents TimelineComponents TogglerComponents Tooltip & popoverComponents TourComponents Tree viewComponents VideoComponents WhiteboardComponents

Layout

Announcement barLayout App shellLayout Back to topLayout Container & sectionLayout ExamplesLayout FooterLayout HeroLayout JumbotronLayout Mega menuLayout NavbarLayout Site sidebarLayout

Sections

Bento gridSections Blog cardsSections Call to actionSections Contact & newsletterSections FAQSections FeaturesSections Logo cloudSections PricingSections TeamSections TestimonialsSections

Utilities

OverviewUtilities State variantsUtilities Display & flexUtilities Grid & gapUtilities SpacingUtilities SizingUtilities TextUtilities Links & color strengthUtilities Position & overflowUtilities BackgroundsUtilities Borders & effectsUtilities Transforms & filtersUtilities InteractionsUtilities

Helpers

Fixed, sticky & frostedHelpers Hover & focusHelpers Hover revealHelpers Icon linkHelpers PrintHelpers Relative timeHelpers Screen reader textHelpers Scroll inHelpers ScrollspyHelpers Share buttonHelpers Skip linkHelpers StacksHelpers Stretched linkHelpers Theme toggleHelpers Truncated textHelpers

Page patterns

404 pagePage patterns Coming soonPage patterns Login & registerPage patterns SettingsPage patterns ProfilePage patterns CRM contactsPage patterns ProjectsPage patterns File manager pagePage patterns Billing & plansPage patterns Help centerPage patterns Mobile app screensPage patterns
↑ ↓ moveEnter openEsc close