Skip to content
API 风格:

IndexBar ​

A contacts-style index bar: a right-side letter index plus anchored group positioning. The scroll-spy active computation (resolveActiveIndex) and the touch computation (hitIndexBar) all consume the pure logic in @lh-ui/share/core/index-bar; this side is only DOM measurement + scrollTo glue.

Basic Usage ​

Index bar (tap / touch to position a group)

Current index:

vue
<script setup lang="ts">
import { ref } from 'vue'
import { LhIndexBar, LhIndexBarGroup, LhIndexBarItem } from '@lh-ui/vue3'

const current = ref('')
const groups: Record<string, string[]> = {
  A: ['Alan', 'Amber'],
  B: ['Bella', 'Brian'],
  C: ['Chloe', 'Claire'],
}

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

<template>
  <LhIndexBar :index-list="['A', 'B', 'C']" @select="onSelect">
    <LhIndexBarGroup v-for="key in ['A', 'B', 'C']" :key="key" :index="key">
      <LhIndexBarItem v-for="name in groups[key]" :key="name">{{ name }}</LhIndexBarItem>
    </LhIndexBarGroup>
  </LhIndexBar>
</template>

Sticky headers and custom highlight ​

sticky enables sticky group headers (on by default); sticky-offset-top is the navbar placeholder offset; highlight-color customizes the active index highlight color.

Sticky + custom highlight color

API ​

IndexBar Props ​

PropDescriptionTypeDefault
index-listIndex item array (defaults to the 26 items A-Z when not passed; an empty array renders no sidebar)string[]A-Z
stickySticky anchor group headersbooleantrue
sticky-offset-topSticky offset in px (for the navbar placeholder)number0
highlight-colorActive index highlight color (falls back to the indexBar.highlightColor token when not passed)string—

IndexBar Events ​

EventDescriptionCallback
selectTap / touch a sidebar index itemindex: string

IndexBar Slots ​

SlotDescriptionScoped props
defaultGroup content (LhIndexBarGroup / LhIndexBarItem pairs)—
itemCustom index item rendering{ index }

IndexBarGroup Props ​

PropDescriptionTypeDefault
indexGroup index key (aligned with an indexList item)string—

IndexBarItem Props ​

PropDescriptionTypeDefault
disabledDisabled (reduced contrast)booleanfalse

IndexBarItem Slots ​

SlotDescription
defaultItem content

Beauty of tradition, foundation of code