Skip to content

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>

Props ​

属性说明类型默认值
indexList索引项数组(未传默认 A-Z 26 项;空数组渲染无侧栏)string[]A-Z
sticky锚点分组头吸顶(登记:本端按 CSS sticky 降级)booleantrue
stickyOffsetTop吸顶偏移 px(导航栏占位用)number0
highlightColor激活索引高亮色(未传取 indexBar.highlightColor 令牌)string—
customClass自定义类名(透传到根节点)string—
sxsx 快速布局属性LhSxProps—

Events ​

事件说明载荷
select点击 / 触摸侧栏索引项index: string

Slots ​

名称说明载荷
default分组内容(lh-index-bar-group / lh-index-bar-item 对)—
item自定义索引项渲染{ index }

LhIndexBarGroup Props ​

属性说明类型默认值
index分组索引键(与 indexList 项对齐,必填)string—
customClass自定义类名(透传到根节点)string—
sxsx 快速布局属性LhSxProps—

LhIndexBarItem Props ​

属性说明类型默认值
disabled禁用(降低对比度)booleanfalse
customClass自定义类名(透传到根节点)string—
sxsx 快速布局属性LhSxProps—

无障碍 ​

根节点 role="navigation" + aria-label="索引栏"。