Skip to content

Build a region picker

createRegionList turns the engine’s region data into picker rows. The RegionList filters, searches, sorts, and prioritizes the list, while your renderList function draws the rows.

All 245 regions are in the list, with US, CA, and GB pinned on top. Search united and the list narrows to three rows. The match runs over names, region codes, and calling codes; +44 finds the United Kingdom too. Click a row and the status reports the selection, while the arrow keys walk the list from the search box and Enter picks the active row.

    The demo and the source are the same three files. The markup is a search input, an empty list, and a status line. createRegionList builds the rows, with prioritize pinning US, CA, and GB and a dataFactory putting a flag emoji in each option’s data slot. The search box feeds search. renderList rebuilds the rows from each emitted state.

    <div id="region-picker">
    <label for="region-picker-search">Region</label>
    <input
    id="region-picker-search"
    type="text"
    role="combobox"
    aria-expanded="true"
    aria-controls="region-picker-listbox"
    aria-autocomplete="list"
    placeholder="Search regions"
    />
    <ul id="region-picker-listbox" role="listbox" aria-label="Regions"></ul>
    <p class="region-picker-status"></p>
    </div>

    The picker so far only reports the selection. Build the complete field wires it to a phone input.