ScrollList

滚动列表,类似 iOS 的滚动选择模式。ScrollList 是纯容器(header/footer/bodyHeight),内部放若干 ScrollItem 组成多列。ScrollItem 有 wheel(滚轮,滚动/点击将候选吸附到中央选区居中)与 normal(普通列表,点击选中并高亮)两种模式;wheel 支持 cycled 无限循环、motion 缓动、transform 选中项文案变换、disabled 跳过。选择通过 selectedIndex 受控 + onSelect(data) 回调(data 含 value/index/type)。复用 @chenzy-design/core 纯函数(resolveItemText/centerOffset/nearestIndex/wrapIndex/scrollFrame/shouldPrepend/shouldAppend)。

设计文档

如何引入

import { ScrollList, ScrollItem } from '@chenzy-design/svelte';

基本使用

滚轮三列(时段 / 小时 / 分钟),滚动或点击选择,选中项吸附到中央选区;header/footer 自定义头尾。

无限滚动列表
  • 上午
  • 下午
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 0
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
当前:下午 2 时 1 分

普通列表模式

mode="normal" 不吸附居中,点击项即选中并高亮背景(对齐 Semi ScrollList 演示)。

hello world
  • 0
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 0
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 0
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
选中:1 / 1 / 1

单列无限循环

cycled 到头尾可继续翻动、无缝衔接;奇数项禁用会被滚动落定跳过;motion=false 直达无缓动。

单个无限滚动列表
  • 0
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
选中分钟:2

选中项文案变换

transform 对选中项文案变换(加单位);项级 transform 优先于列级公共 transform。

小时(选中加「时」)
  • 00
  • 01
  • 02
  • 03
  • 04
  • 05
  • 06
  • 07
  • 08
  • 9 时
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
选中:9 时

自定义 body 高度

bodyHeight 收窄可视高度,wheel 列按实测高度自适应居中吸附。

紧凑高度
  • 0
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
选中:5

日期三列联动

年 / 月 / 日三 wheel 列,改年/月时日列天数联动重算并夹回合法日。

日期选择
  • 2015
  • 2016
  • 2017
  • 2018
  • 2019
  • 2020
  • 2021
  • 2022
  • 2023
  • 2024
  • 2025
  • 2026
  • 2027
  • 2028
  • 2029
  • 2030
  • 2031
  • 2032
  • 2033
  • 2034
  • 1 月
  • 2 月
  • 3 月
  • 4 月
  • 5 月
  • 6 月
  • 7 月
  • 8 月
  • 9 月
  • 10 月
  • 11 月
  • 12 月
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
2024 年 2 月 15 日

API 参考

ScrollList

Props

属性说明类型默认值
header头部 addon(对齐 Semi header)Snippet | stringundefined
footer底部 addon(对齐 Semi footer)Snippet | stringundefined
bodyHeightbody 高度;数字按 px(对齐 Semi bodyHeight)number | stringundefined
class根节点类名(对齐 Semi className)stringundefined
style根节点内联样式(对齐 Semi style)stringundefined
children列内容:若干 <ScrollItem>Snippetundefined

Events

事件载荷说明
onSelect选中项变化(wheel 滚动落定/点击、normal 点击);载荷 {...item, value, index, type}

Slots

名称说明
headerScrollList 头部 addon
footerScrollList 底部 addon

ScrollItem

单列滚动选择:wheel(滚轮吸附居中)/ normal(点击选中并高亮)。对齐 Semi ScrollItem。

Props

属性说明类型默认值
mode模式:wheel 吸附居中 / normal 点击选中'wheel' | 'normal''wheel'
cycled无限循环(仅 wheel 生效)booleanfalse
list列表数据,项 = { value; text?; disabled?; transform? }ScrollItemData[][]
selectedIndex选中项索引(受控)number0
motion是否开启滚动缓动动画booleantrue
transform选中项文案变换(列级公共)(value, text) => stringundefined
type列标识,透传回 onSelect 供外层区分列string | numberundefined
onSelect选中回调,data 含 value/index/type(data: ScrollItemSelectPayload) => voidundefined
class列样式类名stringundefined
style列内联样式stringundefined
ariaLabel列无障碍标签stringundefined

Accessibility

  • 每列 ul role=listbox + aria-label + aria-multiselectable=false;每项 li role=option + aria-selected;disabled 项 aria-disabled。

设计变量

变量默认值用法
--cd-transition-delay-scroll-list-selected-item-bg 0ms滚动列表选中项背景色过渡延迟
--cd-transition-duration-scroll-list-selected-item-bg var(--cd-motion-duration-none)滚动列表选中项背景色过渡时长
--cd-transition-function-scroll-list-selected-item-bg var(--cd-motion-ease-standard)滚动列表选中项背景色过渡曲线(easeOut)