# IndexBar
A contacts-style index bar: a letter index on the right plus anchored group positioning. The
scroll-spy activation math (resolveActiveIndex) and the touch math (hitIndexBar) all consume
the pure logic of @lh-ui/share/core/index-bar; this side is only DOM measurement + scrollTo
glue.
IndexBar (click / touch to locate a group)
<template>
<div class="demo-col" style="gap: 18px">
<div class="index-demo-scroll">
<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>
</div>
<p class="demo-note">Current index: {{ current }}</p>
</div>
</template>
<script>
export default {
data: () => ({
current: '',
groups: {
A: ['Alba', 'Amber'],
B: ['Birch', 'Bergamot'],
C: ['Camellia', 'Cedar'],
},
}),
methods: {
onSelect(index) {
this.current = index
},
},
}
</script>
# Sticky headers and custom highlight
sticky enables sticky group headers (on by default); sticky-offset-top is the offset
reserved for a navbar, and highlight-color customizes the active index highlight color.
<LhIndexBar :index-list="['A', 'B', 'C']" :sticky-offset-top="0" highlight-color="#c0392b">
<LhIndexBarGroup index="A"><LhIndexBarItem>A1</LhIndexBarItem></LhIndexBarGroup>
<LhIndexBarGroup index="B"><LhIndexBarItem>B1</LhIndexBarItem></LhIndexBarGroup>
<LhIndexBarGroup index="C"><LhIndexBarItem>C1</LhIndexBarItem></LhIndexBarGroup>
</LhIndexBar>
# Props
| Prop | Description | Type | Default |
|---|---|---|---|
| indexList | Index item array (defaults to the 26 letters A-Z when not passed; an empty array renders no sidebar) | string[] | A-Z |
| sticky | Sticky anchor group headers | boolean | true |
| stickyOffsetTop | Sticky offset in px (to reserve space for a navbar) | number | 0 |
| highlightColor | Active index highlight color (falls back to the indexBar.highlightColor token) | string | — |
| sx | sx shorthand layout props | LhSxProps | — |
# Events
| Event | Description | Payload |
|---|---|---|
| select | Click / touch a sidebar index item | index: string |
# Slots
| Slot | Description | Payload |
|---|---|---|
| default | Group content (LhIndexBarGroup / LhIndexBarItem pairs) | — |
| item | Custom index item rendering | { index } |
# LhIndexBarGroup Props
| Prop | Description | Type | Default |
|---|---|---|---|
| index | Group index key (aligned with the indexList items, required) | string | — |
| sx | sx shorthand layout props | LhSxProps | — |
# LhIndexBarItem Props
| Prop | Description | Type | Default |
|---|---|---|---|
| disabled | Disabled (reduced contrast) | boolean | false |
| sx | sx shorthand layout props | LhSxProps | — |
# Accessibility
Root element role="navigation" + aria-label="Index bar".
← PullRefresh Watermark →
Copyright © 2024-2026 FengMo WenXue