Skip to content

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 ​

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 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:

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>

Prop ​

PropDescriptionTypeDefault
indexListIndex entries (A-Z by default; empty array hides the sidebar)string[]A-Z
stickyPin group headers (registered: degrades to CSS sticky here)booleantrue
stickyOffsetTopSticky offset px (navbar reservation)number0
highlightColorActive index color (falls back to indexBar.highlightColor token)string—
customClassCustom class (forwarded to the root node)string—
sxLhSxPropsLhSxProps—

Event ​

EventDescription
selectClick / touch a sidebar entry index: string

Slot ​

SlotDescription
defaultGroup content (lh-index-bar-group / lh-index-bar-item)
itemCustom index item rendering { index }

LhIndexBarGroup Prop ​

PropDescriptionTypeDefault
indexGroup key (required, aligned with indexList)string—
customClassCustom class (forwarded to the root node)string—
sxLhSxPropsLhSxProps—

LhIndexBarItem Prop ​

PropDescriptionTypeDefault
disabledDisabled (dimmed)booleanfalse
customClassCustom class (forwarded to the root node)string—
sxLhSxPropsLhSxProps—

Accessibility ​

  • The root node carries role="navigation" + aria-label="Index bar".