<tap-pat-picker>

Searchable single-select list page with an alphabetical index, modeled on the Region picker in iOS Settings. Suited to long lists such as countries/regions, cities and languages.

It only emits change on selection; going to the next level or closing is up to the caller. Put it in Sheet.open({ hasStack: true }) for multi-level selection.

Example

Country or region

getRegionItems uses Intl.DisplayNames to generate names in the current language with flags, searchable by code and English name; in Chinese the items are grouped by pinyin initial.

import { html } from '@mantou/gem/lib/element';
import { Sheet } from '@mantou/tap-ui/elements/sheet';
import { getCurrentRegion, getRegionItems } from '@mantou/tap-ui/lib/region';

import '@mantou/tap-ui/patterns/picker';

const { sheet } = Sheet.open({
  hasStack: true,
  snap: [0.9],
  body: html`
    <tap-pat-picker
      heading="Country or Region"
      searchable
      indexed
      pinned-heading="Current"
      value=${region}
      .items=${getRegionItems()}
      .pinned=${getRegionItems([getCurrentRegion()])}
      @change=${(evt) => {
        region = evt.detail;
        sheet.close(null);
      }}
    ></tap-pat-picker>
  `,
});

Multi-level

Set action: true on items with a next level, and push the next level into the current stack on selection; the data comes from the app.

import { Stack } from '@mantou/tap-ui/elements/stack';

const page = (parent, back) => html`
  <tap-pat-picker
    heading=${parent}
    ?back=${back}
    .items=${areas[parent].map((label) => ({ label, action: !!areas[label] }))}
    @change=${(evt) => {
      if (areas[evt.detail]) {
        Stack.getClosestStack(evt.target)?.push({ content: page(evt.detail, true) });
      } else {
        sheet.close(null);
      }
    }}
  ></tap-pat-picker>
`;

const { sheet } = Sheet.open({ hasStack: true, snap: [0.9], body: page('China', false) });

API

可搜索、带字母索引的单选列表页,例如国家/地区、城市、语言

选择后只发出 change,进入下一级或关闭由调用方处理

Extends GemElement

Instance Properties

Property(Attribute) Reactive Type Description
heading(heading) Yes string
value(value) Yes string
pinnedHeading(pinned-heading) Yes string
back(back) Yes boolean Show the back button of the navbar, pops the closest stack
searchable(searchable) Yes boolean
indexed(indexed) Yes boolean Sort items and group them by initial, with a side index
items Yes PickerItem[]
pinned Yes PickerItem[] Shown above all items, e.g. the current region
change Emitter<string>

Other

Type Value
Event change