Skip to content

IndexBar ​

連絡先スタイルのインデックスバー:右側のアルファベット索引 + アンカーグループ。scroll-spy の有効化(resolveActiveIndex)とタッチ判定(hitIndexBar)はすべて @lh-ui/share/core/index-bar の純関数です。スクロール载体は自前の scroll-view(scroll-into-view のアンカー定位 + scroll イベント駆動の scroll-spy)です。

プラットフォーム差異(登録):アンカー計測は H5 が同期 DOM、MP が createSelectorQuery(getLhRect adapter 経由)。定位は一律 scroll-into-view です。web 3 端は DOM scrollTo、wxapp/alipay はそれぞれのドキュメントを参照。

基本使い方 ​

vue
<template>
  <lh-index-bar :index-list="['A', 'B', 'C']" @select="onSelect">
    <lh-index-bar-group v-for="key in ['A', 'B', 'C']" :key="key" :index="key">
      <lh-index-bar-item v-for="name in groups[key]" :key="name">
        {{ name }}
      </lh-index-bar-item>
    </lh-index-bar-group>
  </lh-index-bar>
</template>

<script setup lang="ts">
import { ref } from 'vue'

const current = ref('')
const groups: Record<string, string[]> = {
  A: ['阿白', '阿黄'],
  B: ['柏舟', '薄荷'],
  C: ['春日', '椿'],
}

function onSelect(index: string) {
  current.value = index
}
</script>

スティッキーヘッダーとハイライト ​

sticky はグループヘッダー固定の口径を登録(本端の scroll-view に sticky セマンティクスはなく CSS sticky で描画します)。sticky-offset-top はナビバーの予約オフセット、highlight-color はアクティブ色を上書きします:

vue
<lh-index-bar :index-list="['甲', '乙', '丙']" highlight-color="#c0392b">
  <lh-index-bar-group index="甲"><lh-index-bar-item>甲一</lh-index-bar-item></lh-index-bar-group>
  <lh-index-bar-group index="乙"><lh-index-bar-item>乙一</lh-index-bar-item></lh-index-bar-group>
  <lh-index-bar-group index="丙"><lh-index-bar-item>丙一</lh-index-bar-item></lh-index-bar-group>
</lh-index-bar>

プロパティ ​

プロパティ説明型デフォルト
indexList索引項目配列(未指定時 A-Z 26 項、空配列はサイドバーなし)string[]A-Z
stickyグループヘッダー固定(登録:本端は CSS sticky に降格)booleantrue
stickyOffsetTop固定オフセット px(ナビバー予約用)number0
highlightColorアクティブ色(未指定時 indexBar.highlightColor トークン)string—
customClassカスタムクラス(ルートノードへ転送)string—
sxLhSxPropsLhSxProps—

イベント ​

イベント説明
selectサイドバー項目のクリック / タッチ index: string

スロット ​

スロット説明
defaultグループ内容(lh-index-bar-group / lh-index-bar-item)
item索引項目のカスタム描画 { index }

LhIndexBarGroup プロパティ ​

プロパティ説明型デフォルト
indexグループキー(必須、indexList と対応)string—
customClassカスタムクラス(ルートノードへ転送)string—
sxLhSxPropsLhSxProps—

LhIndexBarItem プロパティ ​

プロパティ説明型デフォルト
disabled無効化(コントラスト低下)booleanfalse
customClassカスタムクラス(ルートノードへ転送)string—
sxLhSxPropsLhSxProps—

アクセシビリティ ​

  • ルート要素に role="navigation" + aria-label="インデックスバー"。