syncfusion-aspnetcore-timeline

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Skill: Syncfusion Timeline Component

技能:Syncfusion Timeline组件

Overview

概述

The Timeline component presents a sequence of events or activities arranged chronologically. It enables developers to visualize temporal relationships and progressions in a configurable layout. Timeline supports both vertical and horizontal orientations, flexible content alignment strategies (Before, After, Alternate, AlternateReverse), and rich templating capabilities. It is commonly used for displaying project milestones, process flows, historical events, or any chronological progression in web applications.
Timeline组件按时间顺序展示一系列事件或活动,让开发者能够以可配置的布局可视化时间关系和进程。Timeline支持垂直和水平两种方向布局,灵活的内容对齐策略(Before、After、Alternate、AlternateReverse),以及丰富的模板功能。它常用于在Web应用中展示项目里程碑、流程、历史事件或任何时间顺序的进程。

Functional Scope

功能范围

Component Responsibility (Timeline owns):
  • Rendering the visual timeline structure (dots, connectors, timeline line)
  • Managing item layout according to specified orientation and alignment
  • Handling directional support (RTL mode)
  • Triggering lifecycle events during rendering and initialization
  • Applying CSS-based customization to visual elements
  • Parsing and rendering templated content for items
Developer Responsibility (You control):
  • Preparing item data with content and configuration properties
  • Designing content templates (HTML structure, formatting)
  • Styling dots, connectors, and timeline elements via CSS classes
  • Handling events (created, beforeItemRender) for custom behavior
  • Managing dynamic data updates
  • Ensuring accessibility attributes on templated content
  • Defining application-specific logic triggered by events
What Timeline Does NOT Handle:
  • Animation or transition effects between states (CSS responsibility)
  • Responsive layout breakpoints (CSS media queries required)
  • Data persistence or state management across page reloads (application layer)
  • Infinite scrolling or virtualization for very large datasets (100,000+ items)
  • Accessibility markup generation (you must ensure proper ARIA labels)
  • Filtering or sorting of items (pre-process data before passing to Timeline)
组件职责(Timeline负责):
  • 渲染时间线的视觉结构(节点、连接线、时间轴线)
  • 根据指定的方向和对齐方式管理项目布局
  • 支持方向设置(RTL模式)
  • 在渲染和初始化期间触发生命周期事件
  • 对视觉元素应用基于CSS的自定义样式
  • 解析并渲染项目的模板内容
开发者职责(由你控制):
  • 准备包含内容和配置属性的项目数据
  • 设计内容模板(HTML结构、格式)
  • 通过CSS类设置节点、连接线和时间线元素的样式
  • 处理事件(created、beforeItemRender)以实现自定义行为
  • 管理动态数据更新
  • 确保模板内容上的可访问性属性
  • 定义由事件触发的应用特定逻辑
Timeline不负责的内容:
  • 状态间的动画或过渡效果(由CSS负责)
  • 响应式布局断点(需要CSS媒体查询)
  • 跨页面重载的数据持久化或状态管理(应用层负责)
  • 超大数据集(100,000+条项目)的无限滚动或虚拟化
  • 生成可访问性标记(你必须确保正确的ARIA标签)
  • 项目的筛选或排序(在传递给Timeline前预处理数据)

How It Works

工作原理

Rendering Flow:
  1. Initialization: Timeline receives
    items
    array and configuration properties (align, orientation, reverse, etc.)
  2. Layout Calculation: Component determines item positioning based on orientation (Vertical/Horizontal) and alignment (Before/After/Alternate/AlternateReverse)
  3. Event Firing:
    created
    event fires when component rendering is complete
  4. Item Rendering: For each item,
    beforeItemRender
    event fires before the item DOM element is created (allows modification of item properties before rendering)
  5. DOM Construction: Timeline builds the visual structure:
    • Timeline line/connector connecting items
    • Dot elements at each item position
    • Content containers positioned according to alignment
    • Opposite content positioned opposite to main content
  6. CSS Application: All CSS classes specified in
    cssClass
    , item-level
    cssClass
    , and dot-level
    dotCss
    are applied
Orientation Impact:
  • Vertical (default): Items stack top-to-bottom. Before/After alignment controls left/right positioning of content.
  • Horizontal: Items arrange left-to-right. Before/After alignment controls top/bottom positioning of content.
Alignment Behavior:
  • Before: Content on one side, oppositeContent on the other (orientation-dependent)
  • After: Content swapped to opposite side from Before
  • Alternate: Items alternate sides regardless of orientation
  • AlternateReverse: Items alternate sides in reverse order
Data Binding:
  • Items are rendered in the order they appear in the
    items
    array
  • reverse
    property reverses the display order without modifying source data
  • Content can be static strings or dynamically generated via functions with itemIndex context
渲染流程:
  1. 初始化:Timeline接收
    items
    数组和配置属性(align、orientation、reverse等)
  2. 布局计算:组件根据方向(垂直/水平)和对齐方式(Before/After/Alternate/AlternateReverse)确定项目的位置
  3. 事件触发:组件渲染完成时触发
    created
    事件
  4. 项目渲染:对于每个项目,在项目DOM元素创建前触发
    beforeItemRender
    事件(允许在渲染前修改项目属性)
  5. DOM构建:Timeline构建视觉结构:
    • 连接各个项目的时间轴线/连接线
    • 每个项目位置的节点元素
    • 根据对齐方式定位的内容容器
    • 与主内容相对的副内容
  6. CSS应用:所有在
    cssClass
    、项目级
    cssClass
    和节点级
    dotCss
    中指定的CSS类都会被应用
方向影响:
  • 垂直(默认):项目从上到下堆叠。Before/After对齐方式控制内容的左/右位置。
  • 水平:项目从左到右排列。Before/After对齐方式控制内容的上/下位置。
对齐行为:
  • Before:内容在一侧,oppositeContent在另一侧(取决于方向)
  • After:内容与Before的位置相反
  • Alternate:无论方向如何,项目交替显示在两侧
  • AlternateReverse:项目以相反顺序交替显示在两侧
数据绑定:
  • 项目按
    items
    数组中的顺序渲染
  • reverse
    属性反转显示顺序,但不修改源数据
  • 内容可以是静态字符串,也可以是带有itemIndex上下文的动态生成函数

Configuration and Usage

配置与使用

Required Configuration

必需配置

cshtml
@using Syncfusion.EJ2.Layouts;

<ejs-timeline id="timeline">
    <e-timeline-items>
        <e-timeline-item content="Initial Release"></e-timeline-item>
        <e-timeline-item content="Version 2.0"></e-timeline-item>
        <e-timeline-item content="Latest Update"></e-timeline-item>
    </e-timeline-items>
</ejs-timeline>
cshtml
@using Syncfusion.EJ2.Layouts;

<ejs-timeline id="timeline">
    <e-timeline-items>
        <e-timeline-item content="Initial Release"></e-timeline-item>
        <e-timeline-item content="Version 2.0"></e-timeline-item>
        <e-timeline-item content="Latest Update"></e-timeline-item>
    </e-timeline-items>
</ejs-timeline>

Optional Configuration

可选配置

cshtml
<ejs-timeline id="timeline" align="Alternate" orientation="Horizontal" reverse="false" enableRtl="false" enablePersistence="false" cssClass="custom-timeline" locale="en-US">
    <e-timeline-items>
        <e-timeline-item content="Phase 1" oppositeContent="Q1 2024" dotCss="e-icons e-check" cssClass="phase-active"></e-timeline-item>
        <e-timeline-item content="Phase 2" oppositeContent="Q2 2024" dotCss="e-icons e-pending"></e-timeline-item>
    </e-timeline-items>
</ejs-timeline>
cshtml
<ejs-timeline id="timeline" align="Alternate" orientation="Horizontal" reverse="false" enableRtl="false" enablePersistence="false" cssClass="custom-timeline" locale="en-US">
    <e-timeline-items>
        <e-timeline-item content="Phase 1" oppositeContent="Q1 2024" dotCss="e-icons e-check" cssClass="phase-active"></e-timeline-item>
        <e-timeline-item content="Phase 2" oppositeContent="Q2 2024" dotCss="e-icons e-pending"></e-timeline-item>
    </e-timeline-items>
</ejs-timeline>

Defaults

默认值

PropertyDefault ValueBehavior
align
TimelineAlign.After
Content placed bottom/right by default
orientation
TimelineOrientation.Vertical
Items stack vertically
reverse
false
Items display in source order
enableRtl
false
Left-to-right text direction
enablePersistence
false
No state saved between sessions
locale
'en-US'
English localization
items
[]
(empty)
No items rendered if empty
属性默认值行为
align
TimelineAlign.After
内容默认显示在底部/右侧
orientation
TimelineOrientation.Vertical
项目垂直堆叠
reverse
false
项目按源数据顺序显示
enableRtl
false
文本方向从左到右
enablePersistence
false
会话间不保存状态
locale
'en-US'
英文本地化
items
[]
(空数组)
如果为空则不渲染任何项目

Key APIs

核心API

Timeline Component Properties

Timeline组件属性

PropertyTypePurposeDefault
items
TimelineItemModel[]
Array of timeline items to render
[]
align
TimelineAlign
enum
Content alignment strategy (Before/After/Alternate/AlternateReverse)
After
orientation
TimelineOrientation
enum
Display direction (Vertical/Horizontal)
Vertical
reverse
boolean
Reverse item display order
false
template
string
HTML template selector for custom item renderingN/A
enableRtl
boolean
Enable right-to-left text direction
false
enablePersistence
boolean
Persist state between page reloads
false
cssClass
string
CSS class(es) applied to Timeline container
''
locale
string
Culture/localization identifier
'en-US'
属性类型用途默认值
items
TimelineItemModel[]
要渲染的时间线项目数组
[]
align
TimelineAlign
枚举
内容对齐策略(Before/After/Alternate/AlternateReverse)
After
orientation
TimelineOrientation
枚举
显示方向(垂直/水平)
Vertical
reverse
boolean
反转项目显示顺序
false
template
string
用于自定义项目渲染的HTML模板选择器N/A
enableRtl
boolean
启用从右到左的文本方向
false
enablePersistence
boolean
在页面重载间持久化状态
false
cssClass
string
应用于Timeline容器的CSS类
''
locale
string
文化/本地化标识符
'en-US'

TimelineItem Properties

TimelineItem属性

PropertyTypePurposeDefault
content
string
|
Function
Main item text or template (receives itemIndex)
''
oppositeContent
string
|
Function
Secondary content opposite main content (receives itemIndex)
''
dotCss
string
CSS class(es) for dot element (icons, images, styling)
''
disabled
boolean
Disable this item visually/interactively
false
cssClass
string
CSS class(es) for this item container
''
属性类型用途默认值
content
string
|
Function
项目主文本或模板(接收itemIndex)
''
oppositeContent
string
|
Function
与主内容相对的副内容(接收itemIndex)
''
dotCss
string
节点元素的CSS类(图标、图片、样式)
''
disabled
boolean
视觉/交互上禁用该项目
false
cssClass
string
该项目容器的CSS类
''

Events

事件

EventTrigger PointUse Case
created
After component rendering completesInitialize custom behaviors, access rendered elements
beforeItemRender
Before each item's DOM element is createdModify item properties conditionally, apply dynamic styling
Event Arguments:
  • created
    : No custom properties
  • beforeItemRender
    : Provides
    element
    (HTMLElement),
    index
    (number),
    name
    ('beforeItemRender')
事件触发时机使用场景
created
组件渲染完成后初始化自定义行为,访问已渲染元素
beforeItemRender
每个项目的DOM元素创建前有条件地修改项目属性,应用动态样式
事件参数:
  • created
    :无自定义属性
  • beforeItemRender
    :提供
    element
    (HTMLElement)、
    index
    (数字)、
    name
    ('beforeItemRender')

Alignment Enum (TimelineAlign)

对齐枚举(TimelineAlign)

csharp
public enum TimelineAlign
{
    Before,           // Content on first side (left/top depending on orientation)
    After,            // Content on second side (right/bottom) — DEFAULT
    Alternate,        // Items alternate sides in order
    AlternateReverse  // Items alternate sides in reverse order
}
csharp
public enum TimelineAlign
{
    Before,           // 内容显示在第一侧(取决于方向,左/上)
    After,            // 内容显示在第二侧(右/下)—— 默认值
    Alternate,        // 项目按顺序交替显示在两侧
    AlternateReverse  // 项目按相反顺序交替显示在两侧
}

Orientation Enum (TimelineOrientation)

方向枚举(TimelineOrientation)

csharp
public enum TimelineOrientation
{
    Vertical,        // Items stack top-to-bottom (default)
    Horizontal       // Items arrange left-to-right
}
csharp
public enum TimelineOrientation
{
    Vertical,        // 项目从上到下堆叠(默认)
    Horizontal       // 项目从左到右排列
}

Example

示例

Scenario: Display a product release timeline with milestone dates and status indicators.
cshtml
@using Syncfusion.EJ2.Layouts;

<ejs-timeline id="release-timeline" align="Alternate" orientation="Vertical" cssClass="release-timeline">
    <e-timeline-items>
        <e-timeline-item content="Alpha Release" oppositeContent="January 2024" dotCss="e-icons e-info"></e-timeline-item>
        <e-timeline-item content="Beta Release" oppositeContent="March 2024" dotCss="e-icons e-check"></e-timeline-item>
        <e-timeline-item content="Production Release" oppositeContent="June 2024" dotCss="e-icons e-star"></e-timeline-item>
    </e-timeline-items>
</ejs-timeline>
Template Example:
cshtml
@using Syncfusion.EJ2.Layouts;

<div class="container" style="height: 350px">
    <ejs-timeline id="timeline">
        <e-timeline-items>
            <e-timeline-item content="#content-template"></e-timeline-item>
            <e-timeline-item content="#content-template"></e-timeline-item>
            <e-timeline-item content="#content-template"></e-timeline-item>
            <e-timeline-item content="Out for Delivery"></e-timeline-item>
        </e-timeline-items>
    </ejs-timeline>
</div>

<script id="content-template" type="text/x-jsrender">
    <div class="content-container">
        <div class="title">
            ${if(itemIndex==0)} Shipped
            ${else if(itemIndex==1)} Departed
            ${else if(itemIndex==2)} Arrived
            ${/if}
        </div>
        <span class="description">
            ${if(itemIndex==0)} Package details received
            ${else if(itemIndex==1)} In-transit
            ${else if(itemIndex==2)} Package arrived at nearest hub
            ${/if}
        </span>
        <div class="info">
            ${if(itemIndex==0)} - Awaiting dispatch
            ${else if(itemIndex==1)} (International warehouse)
            ${else if(itemIndex==2)} (New york - US)
            ${/if}
        </div>
    </div>
</script>

<style>
    .content-container {
        position: relative;
        width: 180px;
        padding: 10px;
        margin-left: 5px;
        box-shadow: rgba(9, 30, 66, 0.25) 0px 4px 8px -2px, rgba(9, 30, 66, 0.08) 0px 0px 0px 1px;
        background-color: ghostwhite;
    }

    .content-container::before {
        content: '';
        position: absolute;
        left: -8px;
        transform: translateY(-50%);
        width: 0;
        height: 0;
        border-top: 5px solid transparent;
        border-bottom: 5px solid transparent;
        border-right: 8px solid silver;
    }

    .content-container .title {
        font-size: 16px;
    }
    .content-container .description {
        color: #999999;
        font-size: 12px;
    }
    .content-container .info {
        color: #999999;
        font-size: 10px;
    }
</style>
场景:展示产品发布时间线,包含里程碑日期和状态指示器。
cshtml
@using Syncfusion.EJ2.Layouts;

<ejs-timeline id="release-timeline" align="Alternate" orientation="Vertical" cssClass="release-timeline">
    <e-timeline-items>
        <e-timeline-item content="Alpha Release" oppositeContent="January 2024" dotCss="e-icons e-info"></e-timeline-item>
        <e-timeline-item content="Beta Release" oppositeContent="March 2024" dotCss="e-icons e-check"></e-timeline-item>
        <e-timeline-item content="Production Release" oppositeContent="June 2024" dotCss="e-icons e-star"></e-timeline-item>
    </e-timeline-items>
</ejs-timeline>
模板示例:
cshtml
@using Syncfusion.EJ2.Layouts;

<div class="container" style="height: 350px">
    <ejs-timeline id="timeline">
        <e-timeline-items>
            <e-timeline-item content="#content-template"></e-timeline-item>
            <e-timeline-item content="#content-template"></e-timeline-item>
            <e-timeline-item content="#content-template"></e-timeline-item>
            <e-timeline-item content="Out for Delivery"></e-timeline-item>
        </e-timeline-items>
    </ejs-timeline>
</div>

<script id="content-template" type="text/x-jsrender">
    <div class="content-container">
        <div class="title">
            ${if(itemIndex==0)} Shipped
            ${else if(itemIndex==1)} Departed
            ${else if(itemIndex==2)} Arrived
            ${/if}
        </div>
        <span class="description">
            ${if(itemIndex==0)} Package details received
            ${else if(itemIndex==1)} In-transit
            ${else if(itemIndex==2)} Package arrived at nearest hub
            ${/if}
        </span>
        <div class="info">
            ${if(itemIndex==0)} - Awaiting dispatch
            ${else if(itemIndex==1)} (International warehouse)
            ${else if(itemIndex==2)} (New york - US)
            ${/if}
        </div>
    </div>
</script>

<style>
    .content-container {
        position: relative;
        width: 180px;
        padding: 10px;
        margin-left: 5px;
        box-shadow: rgba(9, 30, 66, 0.25) 0px 4px 8px -2px, rgba(9, 30, 66, 0.08) 0px 0px 0px 1px;
        background-color: ghostwhite;
    }

    .content-container::before {
        content: '';
        position: absolute;
        left: -8px;
        transform: translateY(-50%);
        width: 0;
        height: 0;
        border-top: 5px solid transparent;
        border-bottom: 5px solid transparent;
        border-right: 8px solid silver;
    }

    .content-container .title {
        font-size: 16px;
    }
    .content-container .description {
        color: #999999;
        font-size: 12px;
    }
    .content-container .info {
        color: #999999;
        font-size: 10px;
    }
</style>

Edge Cases and Constraints

边缘情况与限制

  1. Empty Items Array: Timeline renders no visible content if
    items
    is empty or null. Component container still renders (empty HTML). Always validate data before passing to Timeline.
  2. Very Large Datasets (1000+ items): Timeline renders all items in DOM without virtualization. Performance degrades linearly with item count. For large datasets, implement pagination or filter items client-side before binding.
  3. Template Functions with Side Effects: If
    content
    or
    oppositeContent
    are function-type properties with side effects (logging, API calls), functions execute during rendering. Ensure functions are idempotent and fast (no async operations).
  4. RTL (enableRtl=true) with Horizontal Orientation: Timeline correctly reverses layout direction. Test content alignment thoroughly—Alternate alignment behavior reverses in RTL mode.
  5. Disabled Items Styling: Setting
    disabled=true
    does not automatically style items visually. You must define CSS for
    .e-disabled
    or custom class to show disabled state (e.g., opacity, strikethrough).
  6. Dot CSS Class Conflicts: If
    dotCss
    specifies both icon class (e.g.,
    e-icons e-check
    ) and custom class, ensure no CSS conflicts. Icon fonts may fail to load if CDN is unreachable.
  7. Dynamic Content Updates: If you modify
    items
    array after rendering, the Timeline does not automatically refresh. You must re-instantiate or call update methods. Changes to item objects alone do not trigger re-render.
  8. Accessibility with Templates: Custom templates (using
    template
    property) are developer-controlled. Component does not auto-generate ARIA labels. You must include
    role
    ,
    aria-label
    ,
    aria-describedby
    attributes in templates.
  9. Locale Fallback: If specified
    locale
    is not registered, Timeline falls back to
    en-US
    . Ensure locale data is loaded before Timeline initialization.
  10. Reverse Property Logic:
    reverse=true
    reverses visual order only; source
    items
    array order is unchanged. This affects user perception of chronological flow but does not modify underlying data.
  1. 空项目数组:如果
    items
    为空或null,Timeline不会渲染任何可见内容,但组件容器仍会渲染(空HTML)。传递给Timeline前务必验证数据。
  2. 超大数据集(1000+条项目):Timeline会在DOM中渲染所有项目,不支持虚拟化。性能会随项目数量线性下降。对于大数据集,实现分页或在客户端绑定前筛选项目。
  3. 带有副作用的模板函数:如果
    content
    oppositeContent
    是带有副作用(日志记录、API调用)的函数类型属性,函数会在渲染期间执行。确保函数是幂等且快速的(无异步操作)。
  4. 水平方向下的RTL(enableRtl=true):Timeline会正确反转布局方向。务必彻底测试内容对齐——Alternate对齐行为在RTL模式下会反转。
  5. 禁用项目的样式:设置
    disabled=true
    不会自动为项目设置视觉样式。你必须为
    .e-disabled
    或自定义类定义CSS,以显示禁用状态(例如透明度、删除线)。
  6. 节点CSS类冲突:如果
    dotCss
    同时指定了图标类(如
    e-icons e-check
    )和自定义类,确保没有CSS冲突。如果CDN不可用,图标字体可能无法加载。
  7. 动态内容更新:如果在渲染后修改
    items
    数组,Timeline不会自动刷新。你必须重新实例化或调用更新方法。仅修改项目对象不会触发重新渲染。
  8. 模板的可访问性:自定义模板(使用
    template
    属性)由开发者控制。组件不会自动生成ARIA标签。你必须在模板中包含
    role
    aria-label
    aria-describedby
    属性。
  9. 本地化回退:如果指定的
    locale
    未注册,Timeline会回退到
    en-US
    。确保在Timeline初始化前加载本地化数据。
  10. Reverse属性逻辑
    reverse=true
    仅反转视觉顺序;源
    items
    数组的顺序不变。这会影响用户对时间流的感知,但不会修改底层数据。

Testing Checklist

测试清单

  • Visual Rendering: All items render with correct content, opposite content, and dots in DOM
  • Orientation Switch: Timeline correctly renders in both Vertical and Horizontal modes
  • Alignment Modes: All four alignment modes (Before/After/Alternate/AlternateReverse) position content correctly
  • RTL Mode: With
    enableRtl=true
    , content direction reverses and layout mirroring is correct
  • Reverse Property: With
    reverse=true
    , items display in reverse visual order (verify against items array)
  • Empty Dataset: Timeline handles empty or null
    items
    without JavaScript errors
  • Large Dataset Performance: Timeline renders 500+ items without browser freezing (baseline test)
  • Event Firing:
    created
    event fires once after rendering;
    beforeItemRender
    fires for each item
  • CSS Application: Custom CSS classes (component-level
    cssClass
    and item-level
    cssClass
    ) apply correctly
  • Dot Customization: Dot CSS classes (icons, images, text) render without font failures
  • Template Rendering: Custom templates (if using
    template
    property) render content without script errors
  • Accessibility (Keyboard): Timeline structure is keyboard-navigable; focus management works (if interactive)
  • Accessibility (Screen Reader): Screen reader announces items in logical order; ARIA labels present (if configured)
  • Disabled Items: Items with
    disabled=true
    render but are visually distinguishable (if styled)
  • Persistence: With
    enablePersistence=true
    , state is restored on page reload (verify localStorage)
  • Dynamic Updates: Modifying
    items
    after render requires manual refresh; verify no auto-refresh (expected behavior)
  • Locale Switching: Changing
    locale
    property updates localized strings correctly
  • Browser Compatibility: Timeline renders correctly in Chrome, Firefox, Safari, Edge (latest versions)
  • 视觉渲染:所有项目在DOM中渲染出正确的内容、副内容和节点
  • 方向切换:Timeline在垂直和水平模式下都能正确渲染
  • 对齐模式:四种对齐模式(Before/After/Alternate/AlternateReverse)都能正确定位内容
  • RTL模式:设置
    enableRtl=true
    后,内容方向反转且布局镜像正确
  • Reverse属性:设置
    reverse=true
    后,项目以相反的视觉顺序显示(与items数组对比验证)
  • 空数据集:Timeline处理空或null的
    items
    时无JavaScript错误
  • 大数据集性能:Timeline渲染500+条项目时浏览器不会冻结(基准测试)
  • 事件触发
    created
    事件在渲染完成后触发一次;
    beforeItemRender
    为每个项目触发一次
  • CSS应用:自定义CSS类(组件级
    cssClass
    和项目级
    cssClass
    )正确应用
  • 节点自定义:节点CSS类(图标、图片、文本)渲染时无字体加载失败
  • 模板渲染:自定义模板(如果使用
    template
    属性)渲染内容时无脚本错误
  • 可访问性(键盘):Timeline结构可通过键盘导航;焦点管理正常(如果是交互式的)
  • 可访问性(屏幕阅读器):屏幕阅读器按逻辑顺序播报项目;存在ARIA标签(如果已配置)
  • 禁用项目:设置
    disabled=true
    的项目可渲染且视觉上可区分(如果已设置样式)
  • 持久化:设置
    enablePersistence=true
    后,页面重载时状态会恢复(验证localStorage)
  • 动态更新:渲染后修改
    items
    需要手动刷新;验证不会自动刷新(预期行为)
  • 本地化切换:修改
    locale
    属性后,本地化字符串正确更新
  • 浏览器兼容性:Timeline在Chrome、Firefox、Safari、Edge(最新版本)中正确渲染

Best Practices

最佳实践

  1. Pre-process Data Before Binding: Sort, filter, and validate item data before passing to Timeline. Timeline renders items in order received—apply business logic (sorting by date, filtering by status) at the data layer, not in the component.
  2. Use Opposite Content Strategically: Reserve opposite content for supplementary information (dates, metadata, statuses). Keep opposite content brief; use main content for primary narrative. This prevents visual clutter and maintains chronological clarity.
  3. Choose Alignment Based on Content Volume: Use
    Before
    or
    After
    for simple, short content. Use
    Alternate
    when content is substantial and you need to balance visual weight.
    AlternateReverse
    is rarely needed; use only for specific design requirements (e.g., reverse chronological with intentional mirroring).
  4. Customize Dots with Icons, Not Text: Leverage
    dotCss
    with icon fonts (Material Icons, Syncfusion icons) for visual status indicators. Avoid long text in dots; instead, encode meaning via icon and color. Icons are faster to recognize than text.
  5. Style Disabled Items Explicitly: If using
    disabled=true
    for historical or read-only items, define clear CSS to visually differentiate them (e.g., reduced opacity, grayscale, strikethrough). Users must immediately recognize disabled state without hovering.
  6. Leverage Templates for Complex Layouts: For items requiring rich HTML (images, nested lists, interactive elements), use the
    template
    property instead of string content. Templates offer full control; ensure templates remain self-contained and do not create accessibility barriers.
  7. Handle Accessibility in Custom Templates: If using custom templates, manually include
    role="article"
    ,
    aria-label
    , and
    aria-describedby
    attributes. Test with screen readers (NVDA, JAWS) to ensure content is announced in expected order and context is clear.
  8. Monitor Performance with Large Datasets: If binding 500+ items, profile rendering time in browser DevTools. If rendering takes >500ms, consider pagination, lazy loading, or filtering. Inform users of rendering delay with a loading indicator.
  9. Test RTL Rendering If Supporting Right-to-Left Languages: Set
    enableRtl=true
    and verify all alignment modes, dot positioning, and content placement mirror correctly. Test on actual right-to-left content (Arabic, Hebrew, Persian) to catch subtle layout issues.
  10. Validate Event Handlers Are Idempotent: If
    beforeItemRender
    handler modifies component state, ensure modifications are safe to repeat. Handlers may fire multiple times if component re-renders; avoid side effects that compound.
  1. 绑定前预处理数据:在传递给Timeline前,对项目数据进行排序、筛选和验证。Timeline按接收顺序渲染项目——在数据层应用业务逻辑(按日期排序、按状态筛选),而非在组件中。
  2. 策略性使用副内容:将副内容用于补充信息(日期、元数据、状态)。保持副内容简洁;主内容用于展示核心叙事。这样可避免视觉混乱,保持时间顺序的清晰性。
  3. 根据内容量选择对齐方式:简单短内容使用
    Before
    After
    。内容较多时使用
    Alternate
    ,以平衡视觉权重。
    AlternateReverse
    很少需要使用;仅在特定设计需求下使用(例如反向时间顺序且需要有意镜像)。
  4. 用图标而非文本自定义节点:利用
    dotCss
    搭配图标字体(Material Icons、Syncfusion图标)作为视觉状态指示器。避免在节点中使用长文本;而是通过图标和颜色传递含义。图标比文本更容易识别。
  5. 显式设置禁用项目的样式:如果使用
    disabled=true
    标记历史或只读项目,定义清晰的CSS以视觉区分它们(例如降低透明度、灰度化、删除线)。用户无需悬停即可立即识别禁用状态。
  6. 对复杂布局使用模板:对于需要富HTML(图片、嵌套列表、交互元素)的项目,使用
    template
    属性而非字符串内容。模板提供完全控制权;确保模板自包含且不会造成可访问性障碍。
  7. 在自定义模板中处理可访问性:如果使用自定义模板,手动添加
    role="article"
    aria-label
    aria-describedby
    属性。使用屏幕阅读器(NVDA、JAWS)测试,确保内容按预期顺序播报且上下文清晰。
  8. 监控大数据集的性能:如果绑定500+条项目,在浏览器开发者工具中分析渲染时间。如果渲染时间超过500ms,考虑分页、懒加载或筛选。使用加载指示器告知用户渲染延迟。
  9. 如果支持从右到左语言,测试RTL渲染:设置
    enableRtl=true
    并验证所有对齐模式、节点位置和内容布局是否正确镜像。使用实际的从右到左内容(阿拉伯语、希伯来语、波斯语)测试,以发现细微的布局问题。
  10. 验证事件处理程序是幂等的:如果
    beforeItemRender
    处理程序修改组件状态,确保修改可以安全重复。如果组件重新渲染,处理程序可能会触发多次;避免产生复合副作用。