IndexBar
Contacts-style index bar: an alphabetical sidebar plus anchored groups. The scroll-spy activation (resolveActiveIndex) and touch hit testing (hitIndexBar) are all pure functions consumed from @lh-ui/share/core/index-bar. The scroll carrier is a self-rendered scroll-view (scroll-into-view anchoring + scroll-event-driven scroll-spy).
Platform differences (registered): anchor measurement uses synchronous DOM on H5 and createSelectorQuery on MP (via the getLhRect adapter); positioning is scroll-into-view throughout. The three web ports use DOM scrollTo; see wxapp/alipay docs for their forms.
Basic usage
<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 headers & custom highlight
sticky registers the group-header pinning intent (the local scroll-view has no sticky semantics, so it renders via CSS sticky); sticky-offset-top reserves space for a navbar and highlight-color overrides the active index color:
<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>Prop
| Prop | Description | Type | Default |
|---|---|---|---|
| indexList | Index entries (A-Z by default; empty array hides the sidebar) | string[] | A-Z |
| sticky | Pin group headers (registered: degrades to CSS sticky here) | boolean | true |
| stickyOffsetTop | Sticky offset px (navbar reservation) | number | 0 |
| highlightColor | Active index color (falls back to indexBar.highlightColor token) | string | — |
| customClass | Custom class (forwarded to the root node) | string | — |
| sx | LhSxProps | LhSxProps | — |
Event
| Event | Description |
|---|---|
| select | Click / touch a sidebar entry index: string |
Slot
| Slot | Description |
|---|---|
| default | Group content (lh-index-bar-group / lh-index-bar-item) |
| item | Custom index item rendering { index } |
LhIndexBarGroup Prop
| Prop | Description | Type | Default |
|---|---|---|---|
| index | Group key (required, aligned with indexList) | string | — |
| customClass | Custom class (forwarded to the root node) | string | — |
| sx | LhSxProps | LhSxProps | — |
LhIndexBarItem Prop
| Prop | Description | Type | Default |
|---|---|---|---|
| disabled | Disabled (dimmed) | boolean | false |
| customClass | Custom class (forwarded to the root node) | string | — |
| sx | LhSxProps | LhSxProps | — |
Accessibility
- The root node carries role="navigation" + aria-label="Index bar".

