syncfusion-react-toolbar
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseImplementing Syncfusion React Toolbar
实现Syncfusion React Toolbar
Component Overview
组件概述
The Syncfusion React Toolbar component provides a flexible command bar for organizing and executing commands. It supports multiple item types (buttons, separators, inputs), responsive overflow modes, and comprehensive accessibility features.
Key Capabilities:
- Multiple item types: Button, Separator, Input
- Responsive overflow modes: Scrollable, Popup, MultiRow, Extended
- Built-in keyboard navigation and ARIA support
- Component rendering within toolbar items
- Customizable appearance and behavior
- Tab key navigation support
- Dynamic item management (add/remove/enable/disable)
- Rich event system (beforeCreate, clicked, keyDown, created, destroyed)
- Full RTL and locale support
- Stateless template rendering
Syncfusion React Toolbar组件为组织和执行命令提供了灵活的命令栏。它支持多种项类型(按钮、分隔符、输入框)、响应式溢出模式以及全面的无障碍功能。
核心功能:
- 多种项类型:按钮、分隔符、输入框
- 响应式溢出模式:滚动式、弹出式、多行式、扩展式
- 内置键盘导航和ARIA支持
- 工具栏项内渲染组件
- 可自定义外观与行为
- Tab键导航支持
- 动态项管理(添加/移除/启用/禁用)
- 丰富的事件系统(beforeCreate、clicked、keyDown、created、destroyed)
- 完整的RTL(从右到左)和本地化支持
- 无状态模板渲染
Complete Table of Contents
完整目录
1. Getting Started
1. 快速入门
File: references/getting-started.md
- Dependencies setup
- Project initialization (Vite/CRA)
- Package installation
- CSS theme imports (Tailwind, Bootstrap, Fluent, Material)
- Basic implementation examples
- Global configuration:
- Locale support for internationalization
- RTL (Right-to-Left) layout
- Persistence settings
- Collision detection
- HTML sanitizer
- Development server setup
文件: references/getting-started.md
- 依赖项设置
- 项目初始化(Vite/CRA)
- 包安装
- CSS主题导入(Tailwind、Bootstrap、Fluent、Material)
- 基础实现示例
- 全局配置:
- 国际化本地化支持
- RTL(从右到左)布局
- 持久化设置
- 碰撞检测
- HTML清理器
- 开发服务器设置
2. Item Configuration
2. 项配置
File: references/item-configuration.md
- ItemModel API Reference:
- Complete interface structure
- All 16 properties with types
- Property reference with descriptions
- Items array configuration patterns
- Configuration examples (simple, grouped, conditional, accessible)
- Button item type with properties:
- - Display text
text - - Unique identifier
id - /
prefixIcon- Icons positioningsuffixIcon - - Custom width
width - - Alignment (Left/Center/Right)
align - - Disabled state
disabled - - Visibility control
visible - - Custom CSS classes
cssClass - - HTML attributes
htmlAttributes - - Priority display (Show/Hide/None)
overflow - - Force popup display
showAlwaysInPopup - - Text display mode (Both/Overflow/Toolbar)
showTextOn
- Separator item type
- Input item type for components
- Tab navigation with
tabIndex - Complete working examples
文件: references/item-configuration.md
- ItemModel API参考:
- 完整接口结构
- 全部16个属性及类型
- 属性参考及描述
- 项数组配置模式
- 配置示例(简单、分组、条件化、无障碍)
- 按钮项类型及属性:
- - 显示文本
text - - 唯一标识符
id - /
prefixIcon- 图标位置suffixIcon - - 自定义宽度
width - - 对齐方式(左/中/右)
align - - 禁用状态
disabled - - 可见性控制
visible - - 自定义CSS类
cssClass - - HTML属性
htmlAttributes - - 优先级显示(显示/隐藏/无)
overflow - - 强制在弹出框中显示
showAlwaysInPopup - - 文本显示模式(两者/溢出时/工具栏)
showTextOn
- 分隔符项类型
- 用于组件的输入项类型
- 使用进行Tab导航
tabIndex - 完整可运行示例
3. Responsive Modes
3. 响应式模式
File: references/responsive-modes.md
- Scrollable Mode (default)
- Horizontal scrolling with navigation arrows
- Touch swipe support
- Keyboard arrow navigation
- Use cases: many items, large screens
- Popup Mode
- Dropdown overflow container
- Command priority control
- Compact appearance
- Use cases: limited space, mobile
- MultiRow Mode
- Item wrapping to multiple rows
- No scrolling needed
- All items visible
- Use cases: responsive width containers
- Extended Mode
- Multi-row with horizontal scrolling
- Row-level navigation
- Use cases: many items in limited width
- Command priority (Show/Hide/None)
- Text display options (Both/Overflow/Toolbar)
- Mode comparison table
- Practical examples for each mode
文件: references/responsive-modes.md
- 滚动模式(默认)
- 带导航箭头的水平滚动
- 触摸滑动支持
- 键盘箭头导航
- 使用场景:项数量多、大屏幕
- 弹出模式
- 下拉溢出容器
- 命令优先级控制
- 紧凑外观
- 使用场景:空间有限、移动端
- 多行模式
- 项自动换行到多行
- 无需滚动
- 所有项可见
- 使用场景:响应式宽度容器
- 扩展模式
- 多行+水平滚动
- 行级导航
- 使用场景:有限宽度内包含多项
- 命令优先级(显示/隐藏/无)
- 文本显示选项(两者/溢出时/工具栏)
- 模式对比表
- 每种模式的实用示例
4. Accessibility & Keyboard Support
4. 无障碍与键盘支持
File: references/accessibility.md
- Compliance standards:
- WCAG 2.2 Level AA
- Section 508 compliance
- Screen reader support (NVDA, JAWS, VoiceOver)
- ARIA attributes:
role="toolbar"- ,
aria-labelaria-orientation - ,
aria-expandedaria-haspopup
- Keyboard navigation:
- allowKeyboard property control
- Arrow keys (Left/Right) navigation
- Home/End keys
- Tab/Shift+Tab for focus
- Enter/Space for activation
- Escape to close popups
- keyDown Event handling:
- Event parameters (currentItem, nextItem, originalEvent)
- Custom keyboard shortcuts
- Preventing default navigation
- Key-specific actions
- Screen reader support and testing
- Color contrast WCAG compliance
- Mobile/touch accessibility
- RTL support
- ARIA best practices
- Testing checklist and tools
文件: references/accessibility.md
- 合规标准:
- WCAG 2.2 Level AA
- Section 508合规
- 屏幕阅读器支持(NVDA、JAWS、VoiceOver)
- ARIA属性:
role="toolbar"- ,
aria-labelaria-orientation - ,
aria-expandedaria-haspopup
- 键盘导航:
- 属性控制
allowKeyboard - 箭头键(左/右)导航
- Home/End键
- Tab/Shift+Tab切换焦点
- Enter/Space激活
- Escape关闭弹出框
- keyDown事件处理:
- 事件参数(currentItem、nextItem、originalEvent)
- 自定义键盘快捷键
- 阻止默认导航
- 特定按键操作
- 屏幕阅读器支持与测试
- WCAG色彩对比度合规
- 移动端/触摸无障碍
- RTL支持
- ARIA最佳实践
- 测试清单与工具
5. Item Configuration (Continued)
5. 项配置(续)
File: references/item-configuration.md
- Button properties reference
- Separator styling
- Input components (NumericTextBox, DropDownList, CheckBox, RadioButton)
- Tab navigation control
- Complete toolbar examples
文件: references/item-configuration.md
- 按钮属性参考
- 分隔符样式
- 输入组件(NumericTextBox、DropDownList、CheckBox、RadioButton)
- Tab导航控制
- 完整工具栏示例
6. Styling & Customization
6. 样式与自定义
File: references/styling-customization.md
- CSS class structure:
- - Container
.e-toolbar - - Item wrapper
.e-toolbar-item - - Button
.e-tbar-btn - - Icon element
.e-icons - - Separator
.e-separator - - Popup
.e-toolbar-pop
- Toolbar container styling
- Item & button styling
- Icon styling and customization
- State styling (hover, focus, active, disabled)
- Theme integration (Tailwind, Bootstrap, Fluent, Material)
- Popup customization CSS classes:
- - Popup container
.e-toolbar-pop - - Dropdown toggle
.e-overflow-button - - Show priority items
.e-overflow-show - - Hide priority items
.e-overflow-hide - - Popup text styling
.e-popup-text - - Toolbar text styling
.e-toolbar-text
- Custom styling examples
- Performance optimization
- Complete styled examples
文件: references/styling-customization.md
- CSS类结构:
- - 容器
.e-toolbar - - 项包装器
.e-toolbar-item - - 按钮
.e-tbar-btn - - 图标元素
.e-icons - - 分隔符
.e-separator - - 弹出框
.e-toolbar-pop
- 工具栏容器样式
- 项与按钮样式
- 图标样式与自定义
- 状态样式(悬停、聚焦、激活、禁用)
- 主题集成(Tailwind、Bootstrap、Fluent、Material)
- 弹出框自定义CSS类:
- - 弹出框容器
.e-toolbar-pop - - 下拉切换按钮
.e-overflow-button - - 显示优先级项
.e-overflow-show - - 隐藏优先级项
.e-overflow-hide - - 弹出框文本样式
.e-popup-text - - 工具栏文本样式
.e-toolbar-text
- 自定义样式示例
- 性能优化
- 完整样式示例
7. Advanced Features & Templates
7. 高级功能与模板
File: references/advanced-features.md
- Template Configuration:
- Template basics (functions/JSX)
- Template properties
- When to use templates
- Item-Wise Custom Templates:
- Single item templates
- Multiple different templates
- State within templates
- Template styling
- Stateless Templates:
- Performance optimization
- CSS class customization
- Popup customization equivalents
- Toggle Buttons:
- Single toggle state
- Toggle groups (radio-like)
- CSS styling
- Link Items:
- Navigation links
- External links
- Breadcrumb patterns
- Tooltips:
- HTML title attribute
- Custom tooltip components
- Styling and positioning
- Rendering Other Components:
- Syncfusion components (DropDownList, NumericTextBox, ColorPicker)
- React components
- Custom components
- Command Customization:
- Click handlers
- Context menus
- Custom actions
- Dynamic Item Management:
- - Add items at runtime
addItems() - - Remove by index or ID
removeItems() - - Enable/disable items
enableItems() - - Show/hide items
hideItem() - - Disable entire toolbar
disable() - - Cleanup
destroy() - - Recalculate layout
refreshOverflow()
- Event Handling:
- - Pre-initialization customization
beforeCreate - - Post-initialization callback
created - - Item click events with ClickEventArgs
clicked - - Keyboard events with KeyDownEventArgs
keyDown - - Cleanup event
destroyed
- Scroll Step Customization:
- Control scroll distance
- Dynamic scroll step
- Touch swipe behavior
- Complete advanced example
文件: references/advanced-features.md
- 模板配置:
- 模板基础(函数/JSX)
- 模板属性
- 模板适用场景
- 逐项自定义模板:
- 单项模板
- 多种不同模板
- 模板内状态
- 模板样式
- 无状态模板:
- 性能优化
- CSS类自定义
- 弹出框自定义等效方案
- 切换按钮:
- 单一切换状态
- 切换组(类似单选按钮)
- CSS样式
- 链接项:
- 导航链接
- 外部链接
- 面包屑模式
- 工具提示:
- HTML title属性
- 自定义工具提示组件
- 样式与定位
- 渲染其他组件:
- Syncfusion组件(DropDownList、NumericTextBox、ColorPicker)
- React组件
- 自定义组件
- 命令自定义:
- 点击处理器
- 上下文菜单
- 自定义操作
- 动态项管理:
- - 运行时添加项
addItems() - - 通过索引或ID移除
removeItems() - - 启用/禁用项
enableItems() - - 显示/隐藏项
hideItem() - - 禁用整个工具栏
disable() - - 清理
destroy() - - 重新计算布局
refreshOverflow()
- 事件处理:
- - 初始化前自定义
beforeCreate - - 初始化后回调
created - - 项点击事件(带ClickEventArgs)
clicked - - 键盘事件(带KeyDownEventArgs)
keyDown - - 清理事件
destroyed
- 滚动步长自定义:
- 控制滚动距离
- 动态滚动步长
- 触摸滑动行为
- 完整高级示例
Documentation and Navigation Guide
文档与导航指南
Getting Started
快速入门
📄 Read: references/getting-started.md
- Package installation and dependencies
- Setup with Vite and React
- CSS imports and theme configuration
- Basic toolbar with ItemsDirective
- HTML element initialization
- Running the development server
📄 阅读: references/getting-started.md
- 包安装与依赖项
- Vite与React环境搭建
- CSS导入与主题配置
- 使用ItemsDirective的基础工具栏
- HTML元素初始化
- 运行开发服务器
Item Configuration & Types
项配置与类型
📄 Read: references/item-configuration.md
- Button item type with properties (text, icons, width, align)
- Separator item type
- Input item type for components
- Tab key navigation with tabIndex
- Complete working examples
📄 阅读: references/item-configuration.md
- 按钮项类型及属性(文本、图标、宽度、对齐)
- 分隔符项类型
- 用于组件的输入项类型
- 使用tabIndex进行Tab键导航
- 完整可运行示例
Responsive Modes
响应式模式
📄 Read: references/responsive-modes.md
- Scrollable mode (default behavior)
- Popup overflow mode
- Command priority (show, hide, none)
- Text display options
- Navigation and interaction patterns
📄 阅读: references/responsive-modes.md
- 滚动模式(默认行为)
- 弹出溢出模式
- 命令优先级(显示、隐藏、无)
- 文本显示选项
- 导航与交互模式
Accessibility & Keyboard Support
无障碍与键盘支持
📄 Read: references/accessibility.md
- WCAG 2.2 and Section 508 compliance
- ARIA attributes and roles
- Keyboard navigation keys
- Screen reader support
- Mobile device accessibility
📄 阅读: references/accessibility.md
- WCAG 2.2与Section 508合规
- ARIA属性与角色
- 键盘导航按键
- 屏幕阅读器支持
- 移动设备无障碍
Styling & Customization
样式与自定义
📄 Read: references/styling-customization.md
- CSS customization patterns
- Toolbar and item styling
- Icon and button customization
- Hover and focus states
- Theme integration
📄 阅读: references/styling-customization.md
- CSS自定义模式
- 工具栏与项样式
- 图标与按钮自定义
- 悬停与聚焦状态
- 主题集成
Advanced Features & Templates
高级功能与模板
📄 Read: references/advanced-features.md
- Template configuration and patterns
- Item-wise custom templates
- Toggle buttons
- Link items
- Tooltips
- Rendering other Syncfusion components
- Command and scroll customization
📄 阅读: references/advanced-features.md
- 模板配置与模式
- 逐项自定义模板
- 切换按钮
- 链接项
- 工具提示
- 渲染其他Syncfusion组件
- 命令与滚动自定义
Quick Start Example
快速开始示例
jsx
import { ItemDirective, ItemsDirective, ToolbarComponent } from '@syncfusion/ej2-react-navigations';
import './App.css';
const App = () => {
return (
<ToolbarComponent id='toolbar'>
<ItemsDirective>
<ItemDirective text="Cut" prefixIcon="e-cut-icon" />
<ItemDirective text="Copy" prefixIcon="e-copy-icon" />
<ItemDirective text="Paste" prefixIcon="e-paste-icon" />
<ItemDirective type="Separator" />
<ItemDirective text="Bold" prefixIcon="e-bold-icon" />
<ItemDirective text="Italic" prefixIcon="e-italic-icon" />
<ItemDirective text="Underline" prefixIcon="e-underline-icon" />
</ItemsDirective>
</ToolbarComponent>
);
};
export default App;Required CSS imports in App.css:
css
@import '../node_modules/@syncfusion/ej2-base/styles/tailwind3.css';
@import '../node_modules/@syncfusion/ej2-buttons/styles/tailwind3.css';
@import '../node_modules/@syncfusion/ej2-popups/styles/tailwind3.css';
@import '../node_modules/@syncfusion/ej2-react-navigations/styles/tailwind3.css';jsx
import { ItemDirective, ItemsDirective, ToolbarComponent } from '@syncfusion/ej2-react-navigations';
import './App.css';
const App = () => {
return (
<ToolbarComponent id='toolbar'>
<ItemsDirective>
<ItemDirective text="Cut" prefixIcon="e-cut-icon" />
<ItemDirective text="Copy" prefixIcon="e-copy-icon" />
<ItemDirective text="Paste" prefixIcon="e-paste-icon" />
<ItemDirective type="Separator" />
<ItemDirective text="Bold" prefixIcon="e-bold-icon" />
<ItemDirective text="Italic" prefixIcon="e-italic-icon" />
<ItemDirective text="Underline" prefixIcon="e-underline-icon" />
</ItemsDirective>
</ToolbarComponent>
);
};
export default App;App.css中所需的CSS导入:
css
@import '../node_modules/@syncfusion/ej2-base/styles/tailwind3.css';
@import '../node_modules/@syncfusion/ej2-buttons/styles/tailwind3.css';
@import '../node_modules/@syncfusion/ej2-popups/styles/tailwind3.css';
@import '../node_modules/@syncfusion/ej2-react-navigations/styles/tailwind3.css';Common Patterns
常见模式
Basic Toolbar with Buttons and Separators
带按钮和分隔符的基础工具栏
Create a simple toolbar with button commands and visual separators between groups:
jsx
<ToolbarComponent>
<ItemsDirective>
{/* Edit commands */}
<ItemDirective text="Cut" />
<ItemDirective text="Copy" />
<ItemDirective type="Separator" />
{/* Format commands */}
<ItemDirective text="Bold" />
<ItemDirective text="Italic" />
</ItemsDirective>
</ToolbarComponent>创建包含按钮命令和组间视觉分隔符的简单工具栏:
jsx
<ToolbarComponent>
<ItemsDirective>
{/* 编辑命令 */}
<ItemDirective text="Cut" />
<ItemDirective text="Copy" />
<ItemDirective type="Separator" />
{/* 格式命令 */}
<ItemDirective text="Bold" />
<ItemDirective text="Italic" />
</ItemsDirective>
</ToolbarComponent>Toolbar with Icons
带图标的工具栏
Use prefixIcon to add icons to buttons for better visual representation:
jsx
<ItemDirective text="Save" prefixIcon="e-save-icon" />
<ItemDirective text="Print" prefixIcon="e-print-icon" />使用prefixIcon为按钮添加图标,提升视觉表现力:
jsx
<ItemDirective text="Save" prefixIcon="e-save-icon" />
<ItemDirective text="Print" prefixIcon="e-print-icon" />Responsive Overflow Handling
响应式溢出处理
Choose between Scrollable (default) for continuous display or Popup for compact overflow:
jsx
{/* Scrollable mode with navigation arrows */}
<ToolbarComponent overflowMode="Scrollable">
{/* items */}
</ToolbarComponent>
{/* Popup mode with dropdown */}
<ToolbarComponent overflowMode="Popup">
{/* items */}
</ToolbarComponent>在滚动式(默认)连续显示和弹出式紧凑溢出之间选择:
jsx
{/* 带导航箭头的滚动模式 */}
<ToolbarComponent overflowMode="Scrollable">
{/* 项 */}
</ToolbarComponent>
{/* 带下拉框的弹出模式 */}
<ToolbarComponent overflowMode="Popup">
{/* 项 */}
</ToolbarComponent>Toolbar with Input Components
带输入组件的工具栏
Include interactive components like dropdowns within toolbar items:
jsx
<ItemDirective type="Input" template={<DropDownComponent {...props} />} />在工具栏项中包含下拉框等交互组件:
jsx
<ItemDirective type="Input" template={<DropDownComponent {...props} />} />Key Props
核心属性
| Property | Type | Description |
|---|---|---|
| string | Unique identifier for the toolbar |
| "Scrollable" | "Popup" | How to handle overflow items |
| string | Width of the toolbar container |
| ItemModel[] | Array of toolbar items |
| string | Display text for button items |
| string | Icon class for prefix position |
| string | Icon class for suffix position |
| "Button" | "Separator" | "Input" | Item type |
| "Left" | "Center" | "Right" | Item alignment |
| "Show" | "Hide" | "None" | Priority for popup mode |
| number | Tab navigation order |
| function | Custom template for items |
| 属性 | 类型 | 描述 |
|---|---|---|
| string | 工具栏的唯一标识符 |
| "Scrollable" | "Popup" | 溢出项的处理方式 |
| string | 工具栏容器的宽度 |
| ItemModel[] | 工具栏项数组 |
| string | 按钮项的显示文本 |
| string | 前缀位置的图标类 |
| string | 后缀位置的图标类 |
| "Button" | "Separator" | "Input" | 项类型 |
| "Left" | "Center" | "Right" | 项对齐方式 |
| "Show" | "Hide" | "None" | 弹出模式下的优先级 |
| number | Tab导航顺序 |
| function | 项的自定义模板 |
Common Use Cases
常见使用场景
-
Text Editor Toolbar
- Format buttons (Bold, Italic, Underline)
- Alignment options
- Color and font pickers
- See: responsive-modes.md, advanced-features.md
-
File Operations Toolbar
- New, Open, Save, Save As buttons
- Print functionality
- Undo/Redo commands
- See: item-configuration.md, advanced-features.md
-
Responsive Mobile Toolbar
- Popup overflow mode for compact display
- Scrollable mode for continuous access
- See: responsive-modes.md
-
Accessible Command Bar
- Keyboard navigation support
- ARIA attributes
- Screen reader friendly
- See: accessibility.md
-
Customized Branded Toolbar
- Custom CSS styling
- Theme integration
- Company-specific icons
- See: styling-customization.md
-
文本编辑器工具栏
- 格式按钮(粗体、斜体、下划线)
- 对齐选项
- 颜色和字体选择器
- 参考:responsive-modes.md、advanced-features.md
-
文件操作工具栏
- 新建、打开、保存、另存为按钮
- 打印功能
- 撤销/重做命令
- 参考:item-configuration.md、advanced-features.md
-
响应式移动端工具栏
- 弹出溢出模式实现紧凑显示
- 滚动模式实现连续访问
- 参考:responsive-modes.md
-
无障碍命令栏
- 键盘导航支持
- ARIA属性
- 屏幕阅读器友好
- 参考:accessibility.md
-
定制品牌工具栏
- 自定义CSS样式
- 主题集成
- 企业专属图标
- 参考:styling-customization.md
Summary
总结
The Toolbar component provides a comprehensive solution for command organization and execution in React applications. Start with getting-started.md for basic setup, then explore specific features based on your needs. Use advanced-features.md for template customization and complex scenarios.
Navigation Path:
- Getting Started → Basic toolbar setup
- Item Configuration → Add different item types
- Responsive Modes → Handle overflow
- Accessibility → Ensure keyboard support
- Styling → Customize appearance
- Advanced Features → Templates and custom components
Toolbar组件为React应用中的命令组织与执行提供了全面的解决方案。从getting-started.md开始进行基础搭建,然后根据需求探索特定功能。复杂场景下可参考advanced-features.md进行模板定制。
导航路径:
- 快速入门 → 基础工具栏搭建
- 项配置 → 添加不同类型的项
- 响应式模式 → 处理溢出
- 无障碍 → 确保键盘支持
- 样式 → 自定义外观
- 高级功能 → 模板与自定义组件