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 三端為 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 降級) | boolean | true |
| stickyOffsetTop | 吸頂偏移 px(導航列佔位用) | number | 0 |
| highlightColor | 啟用索引高亮色(未傳取 indexBar.highlightColor 令牌) | string | — |
| customClass | 自訂類名(透傳到根節點) | string | — |
| sx | LhSxProps | LhSxProps | — |
事件
| 事件 | 說明 |
|---|---|
| select | 點擊 / 觸控側欄索引項 index: string |
插槽
| 插槽 | 說明 |
|---|---|
| default | 分組內容(lh-index-bar-group / lh-index-bar-item 對) |
| item | 自訂索引項渲染 { index } |
LhIndexBarGroup 屬性
| 屬性 | 說明 | 類型 | 預設值 |
|---|---|---|---|
| index | 分組索引鍵(與 indexList 項對齊,必填) | string | — |
| customClass | 自訂類名(透傳到根節點) | string | — |
| sx | LhSxProps | LhSxProps | — |
LhIndexBarItem 屬性
| 屬性 | 說明 | 類型 | 預設值 |
|---|---|---|---|
| disabled | 停用(降低對比度) | boolean | false |
| customClass | 自訂類名(透傳到根節點) | string | — |
| sx | LhSxProps | LhSxProps | — |
無障礙
- 根節點 role="navigation" + aria-label="索引欄"。

