syncfusion-react-popups
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSyncfusion React Popups Component
Syncfusion React 弹窗组件
Implementing Syncfusion React Dialog Component
实现 Syncfusion React Dialog 组件
The DialogComponent displays content in a floating window with support for modal and modeless modes, custom positioning, dragging, resizing, animations, templating, and comprehensive accessibility features.
DialogComponent 在浮动窗口中展示内容,支持模态与非模态模式、自定义定位、拖动、调整大小、动画、模板化以及全面的无障碍功能。
Component Overview
组件概述
DialogComponent Features:
- Modal/Modeless modes: Control parent interaction blocking
- 9 preset positions + custom X/Y: Flexible placement
- Dragging: Header-based drag and drop (allowDragging)
- Resizing: Diagonal resize grip (enableResize)
- Templating: Custom header, content, footer
- Animations: 16 effects (Fade, Zoom, Flip, Slide, FadeZoom, etc.)
- Buttons: Built-in action buttons with click handlers
- Events: open, close, beforeOpen, beforeClose, drag, dragStart, dragStop, resize events
- Keyboard Navigation: Tab, Escape (closeOnEscape), Enter
- WCAG 2.2 Accessibility: ARIA roles, focus management
- Localization: 20+ locales via locale property
- RTL Support: Right-to-left rendering
DialogComponent 特性:
- 模态/非模态模式:控制是否阻止父元素交互
- 9种预设位置 + 自定义X/Y坐标:灵活的布局方式
- 拖动功能:基于标题栏的拖拽(allowDragging属性)
- 调整大小:对角线调整手柄(enableResize属性)
- 模板化:自定义标题、内容、页脚
- 动画效果:16种动画(淡入、缩放、翻转、滑动、淡入缩放等)
- 按钮:内置带点击事件的操作按钮
- 事件:open、close、beforeOpen、beforeClose、drag、dragStart、dragStop、resize等事件
- 键盘导航:Tab、Escape(closeOnEscape属性)、Enter键支持
- WCAG 2.2 无障碍:ARIA角色、焦点管理
- 本地化:通过locale属性支持20+种语言环境
- RTL支持:从右到左渲染
Documentation & Navigation Guide
文档与导航指南
Getting Started
快速入门
📄 Read: references/getting-started.md
- Installation ()
@syncfusion/ej2-react-popups - CSS/theme imports (material, bootstrap, tailwind)
- Basic DialogComponent JSX structure
- show()/hide() methods and refs
- Functional component patterns with hooks
- Initial visibility with visible prop
📄 阅读: references/getting-started.md
- 安装()
@syncfusion/ej2-react-popups - CSS/主题导入(material、bootstrap、tailwind)
- 基础DialogComponent JSX结构
- show()/hide()方法与refs
- 使用hooks的函数组件模式
- 通过visible属性控制初始可见性
Modal vs Modeless
模态 vs 非模态
📄 Read: references/modal-vs-modeless.md
- isModal boolean property (true/false)
- Modal overlay behavior and parent blocking
- Modeless floating behavior
- Focus management differences
- When to choose each mode
- Side-by-side comparisons
📄 阅读: references/modal-vs-modeless.md
- isModal布尔属性(true/false)
- 模态遮罩行为与父元素交互阻止
- 非模态浮动行为
- 焦点管理差异
- 两种模式的适用场景
- 对比说明
Positioning and Dragging
定位与拖动
📄 Read: references/positioning-and-dragging.md
- position object (X: 'center'|'left'|'right'|number, Y: 'top'|'center'|'bottom'|number)
- 9 preset position combinations
- Custom pixel-based positioning
- allowDragging boolean property
- enableResize and resizeHandles configuration
- Target element constraints with target prop
📄 阅读: references/positioning-and-dragging.md
- position对象(X: 'center'|'left'|'right'|数字, Y: 'top'|'center'|'bottom'|数字)
- 9种预设位置组合
- 自定义像素级定位
- allowDragging布尔属性
- enableResize与resizeHandles配置
- 通过target属性设置目标元素约束
Templates and Content
模板与内容
📄 Read: references/templates-and-content.md
- content property (string, HTML, JSX function)
- header property (text or template)
- footerTemplate (custom footer JSX)
- Dynamic content updates
- HTML sanitization (enableHtmlSanitizer)
- Styling content and edge cases
📄 阅读: references/templates-and-content.md
- content属性(字符串、HTML、JSX函数)
- header属性(文本或模板)
- footerTemplate(自定义页脚JSX)
- 动态内容更新
- HTML清理(enableHtmlSanitizer)
- 内容样式与边缘情况处理
Buttons and Actions
按钮与操作
📄 Read: references/buttons-and-actions.md
- buttons array with ButtonPropsModel[]
- ButtonPropsModel structure (buttonModel, click, isFlat, type)
- buttonModel properties (content, isPrimary, cssClass)
- Click event handlers
- Styling buttons with cssClass
- Button types (Button, Submit, Reset)
📄 阅读: references/buttons-and-actions.md
- buttons数组,包含ButtonPropsModel[]
- ButtonPropsModel结构(buttonModel、click、isFlat、type)
- buttonModel属性(content、isPrimary、cssClass)
- 点击事件处理
- 通过cssClass设置按钮样式
- 按钮类型(Button、Submit、Reset)
Animation Effects
动画效果
📄 Read: references/animation-effects.md
- AnimationSettingsModel (effect, duration, delay)
- 16 animation effects (Fade, FadeZoom, FlipLeftDown, FlipLeftUp, etc.)
- Duration in milliseconds
- Delay before animation starts
- Disable animations (effect: 'None')
- Performance considerations
📄 阅读: references/animation-effects.md
- AnimationSettingsModel(effect、duration、delay)
- 16种动画效果(Fade、FadeZoom、FlipLeftDown、FlipLeftUp等)
- 动画时长(毫秒)
- 动画延迟启动时间
- 禁用动画(effect: 'None')
- 性能考量
Localization and Accessibility
本地化与无障碍
📄 Read: references/localization-and-accessibility.md
- locale property for culture/language
- WCAG 2.2 compliance
- Keyboard navigation (Tab, Enter, Escape)
- closeOnEscape behavior control
- ARIA roles and attributes
- Screen reader support
- RTL support with enableRtl
- Focus management patterns
📄 阅读: references/localization-and-accessibility.md
- locale属性设置文化/语言
- WCAG 2.2合规性
- 键盘导航(Tab、Enter、Escape)
- closeOnEscape行为控制
- ARIA角色与属性
- 屏幕阅读器支持
- enableRtl实现RTL支持
- 焦点管理模式
Advanced Patterns
高级模式
📄 Read: references/advanced-patterns.md
- Events: open, close, beforeOpen, beforeClose, drag, dragStart, dragStop, resizeStart, resizeStop, resizing
- Nested and stacked dialogs
- Forms with validation
- AJAX content loading
- Prevent close logic (beforeClose event)
- Full-screen dialogs
- HTML sanitization and security
- CSS classes and z-index management
- Enable persistence (enablePersistence)
- Common edge cases and troubleshooting
📄 阅读: references/advanced-patterns.md
- 事件:open、close、beforeOpen、beforeClose、drag、dragStart、dragStop、resizeStart、resizeStop、resizing
- 嵌套与堆叠对话框
- 带验证的表单
- AJAX内容加载
- 阻止关闭逻辑(beforeClose事件)
- 全屏对话框
- HTML清理与安全
- CSS类与z-index管理
- 启用持久化(enablePersistence)
- 常见边缘情况与故障排除
API Reference (Complete)
完整API参考
📄 Read: references/api-reference.md
- All 24 DialogModel properties with types and defaults
- All 11 events with event arguments
- Methods: show(), hide(), refresh(), destroy()
- ButtonPropsModel structure (buttonModel, click, isFlat, type)
- AnimationSettingsModel with all 16 effects
- Types and enumerations
- Quick reference patterns
📄 阅读: references/api-reference.md
- 所有24个DialogModel属性,包含类型与默认值
- 所有11个事件及事件参数
- 方法:show()、hide()、refresh()、destroy()
- ButtonPropsModel结构(buttonModel、click、isFlat、type)
- 包含所有16种效果的AnimationSettingsModel
- 类型与枚举
- 快速参考模式
Quick Start Example
快速入门示例
⚠️ Dependency Alignment: Allpackages must be on the same major version to avoid peer-dependency conflicts and supply-chain mismatches. Install them together:@syncfusion/ej2-*npm install @syncfusion/ej2-react-popups @syncfusion/ej2-base @syncfusion/ej2-buttons @syncfusion/ej2-popups
Basic Modal Dialog:
jsx
import React, { useRef, useState } from 'react';
import { DialogComponent } from '@syncfusion/ej2-react-popups';
import '@syncfusion/ej2-base/styles/material.css';
import '@syncfusion/ej2-buttons/styles/material.css';
import '@syncfusion/ej2-popups/styles/material.css';
export default function App() {
const dialogRef = useRef(null);
const [isOpen, setIsOpen] = useState(false);
const handleOpen = () => {
dialogRef.current?.show();
setIsOpen(true);
};
const handleClose = () => {
dialogRef.current?.hide();
setIsOpen(false);
};
const buttons = [
{
buttonModel: {
content: 'OK',
cssClass: 'e-flat',
isPrimary: true,
},
click: handleClose,
},
{
buttonModel: {
content: 'Cancel',
cssClass: 'e-flat',
},
click: handleClose,
},
];
return (
<div id="dialog-target" style={{ position: 'relative', width: '100%', minHeight: '400px' }}>
<button onClick={handleOpen} className="e-control e-btn e-primary">
Open Dialog
</button>
<DialogComponent
ref={dialogRef}
header="Confirm Action"
buttons={buttons}
showCloseIcon={true}
target="#dialog-target"
width="400px"
isModal={true}
visible={false}
>
<p>Are you sure you want to proceed with this action?</p>
</DialogComponent>
</div>
);
}⚠️ 依赖版本对齐: 所有包必须使用相同大版本,以避免peer依赖冲突和供应链不匹配。请一起安装:@syncfusion/ej2-*npm install @syncfusion/ej2-react-popups @syncfusion/ej2-base @syncfusion/ej2-buttons @syncfusion/ej2-popups
基础模态对话框:
jsx
import React, { useRef, useState } from 'react';
import { DialogComponent } from '@syncfusion/ej2-react-popups';
import '@syncfusion/ej2-base/styles/material.css';
import '@syncfusion/ej2-buttons/styles/material.css';
import '@syncfusion/ej2-popups/styles/material.css';
export default function App() {
const dialogRef = useRef(null);
const [isOpen, setIsOpen] = useState(false);
const handleOpen = () => {
dialogRef.current?.show();
setIsOpen(true);
};
const handleClose = () => {
dialogRef.current?.hide();
setIsOpen(false);
};
const buttons = [
{
buttonModel: {
content: 'OK',
cssClass: 'e-flat',
isPrimary: true,
},
click: handleClose,
},
{
buttonModel: {
content: 'Cancel',
cssClass: 'e-flat',
},
click: handleClose,
},
];
return (
<div id="dialog-target" style={{ position: 'relative', width: '100%', minHeight: '400px' }}>
<button onClick={handleOpen} className="e-control e-btn e-primary">
Open Dialog
</button>
<DialogComponent
ref={dialogRef}
header="Confirm Action"
buttons={buttons}
showCloseIcon={true}
target="#dialog-target"
width="400px"
isModal={true}
visible={false}
>
<p>Are you sure you want to proceed with this action?</p>
</DialogComponent>
</div>
);
}Common Patterns
常见模式
Pattern 1: Confirmation Dialog
模式1:确认对话框
Delete action with confirmation buttons:
jsx
const buttons = [
{
buttonModel: { content: 'Delete', cssClass: 'e-flat e-danger', isPrimary: true },
click: () => { performDelete(); dialogRef.current?.hide(); }
},
{
buttonModel: { content: 'Cancel', cssClass: 'e-flat' },
click: () => dialogRef.current?.hide()
}
];带确认按钮的删除操作:
jsx
const buttons = [
{
buttonModel: { content: 'Delete', cssClass: 'e-flat e-danger', isPrimary: true },
click: () => { performDelete(); dialogRef.current?.hide(); }
},
{
buttonModel: { content: 'Cancel', cssClass: 'e-flat' },
click: () => dialogRef.current?.hide()
}
];Pattern 2: Form Dialog
模式2:表单对话框
Dialog with form inputs and validation:
jsx
<DialogComponent header="Edit Profile" buttons={buttons} isModal={true} width="500px">
<div style={{ padding: '16px' }}>
<input type="text" placeholder="Name" className="form-control" />
<input type="email" placeholder="Email" className="form-control" />
<textarea placeholder="Bio" className="form-control"></textarea>
</div>
</DialogComponent>带输入框与验证的对话框:
jsx
<DialogComponent header="Edit Profile" buttons={buttons} isModal={true} width="500px">
<div style={{ padding: '16px' }}>
<input type="text" placeholder="Name" className="form-control" />
<input type="email" placeholder="Email" className="form-control" />
<textarea placeholder="Bio" className="form-control"></textarea>
</div>
</DialogComponent>Pattern 3: Centered Dialog
模式3:居中对话框
Position dialog in center of screen:
jsx
<DialogComponent
header="Alert"
position={{ X: 'center', Y: 'center' }}
isModal={true}
showCloseIcon={true}
width="350px"
>
This dialog is centered on the screen.
</DialogComponent>屏幕居中的对话框:
jsx
<DialogComponent
header="Alert"
position={{ X: 'center', Y: 'center' }}
isModal={true}
showCloseIcon={true}
width="350px"
>
This dialog is centered on the screen.
</DialogComponent>Pattern 4: Draggable Floating Panel
模式4:可拖动浮动面板
Non-modal, draggable properties panel:
jsx
<DialogComponent
header="Properties"
isModal={false}
allowDragging={true}
position={{ X: 200, Y: 150 }}
width="300px"
enableResize={true}
resizeHandles={['All']}
showCloseIcon={true}
>
Drag me around! I don't block the page.
</DialogComponent>非模态、可拖动的属性面板:
jsx
<DialogComponent
header="Properties"
isModal={false}
allowDragging={true}
position={{ X: 200, Y: 150 }}
width="300px"
enableResize={true}
resizeHandles={['All']}
showCloseIcon={true}
>
Drag me around! I don't block the page.
</DialogComponent>Pattern 5: Animated Dialog
模式5:动画对话框
Dialog with Zoom animation:
jsx
<DialogComponent
header="Welcome"
animationSettings={{ effect: 'Zoom', duration: 400, delay: 0 }}
isModal={true}
position={{ X: 'center', Y: 'center' }}
width="400px"
>
This dialog zooms in smoothly!
</DialogComponent>带缩放动画的对话框:
jsx
<DialogComponent
header="Welcome"
animationSettings={{ effect: 'Zoom', duration: 400, delay: 0 }}
isModal={true}
position={{ X: 'center', Y: 'center' }}
width="400px"
>
This dialog zooms in smoothly!
</DialogComponent>Pattern 6: Custom Footer Template
模式6:自定义页脚模板
Custom footer instead of buttons:
jsx
<DialogComponent
header="Custom Footer"
isModal={true}
footerTemplate={
<div style={{ padding: '12px', textAlign: 'right' }}>
<button className="e-control e-btn e-primary" style={{ marginRight: '8px' }}>
Save
</button>
<button className="e-control e-btn">Cancel</button>
</div>
}
>
Dialog content with custom footer.
</DialogComponent>自定义页脚替代默认按钮:
jsx
<DialogComponent
header="Custom Footer"
isModal={true}
footerTemplate={
<div style={{ padding: '12px', textAlign: 'right' }}>
<button className="e-control e-btn e-primary" style={{ marginRight: '8px' }}>
Save
</button>
<button className="e-control e-btn">Cancel</button>
</div>
}
>
Dialog content with custom footer.
</DialogComponent>Pattern 7: Nested Dialogs
模式7:嵌套对话框
Parent dialog containing child dialog:
jsx
const childDialogRef = useRef(null);
<DialogComponent header="Parent" isModal={true} width="400px">
<button onClick={() => childDialogRef.current?.show()} className="e-control e-btn">
Open Child Dialog
</button>
<DialogComponent
ref={childDialogRef}
header="Child"
isModal={true}
width="300px"
visible={false}
>
Nested dialog content
</DialogComponent>
</DialogComponent>包含子对话框的父对话框:
jsx
const childDialogRef = useRef(null);
<DialogComponent header="Parent" isModal={true} width="400px">
<button onClick={() => childDialogRef.current?.show()} className="e-control e-btn">
Open Child Dialog
</button>
<DialogComponent
ref={childDialogRef}
header="Child"
isModal={true}
width="300px"
visible={false}
>
Nested dialog content
</DialogComponent>
</DialogComponent>Key Props (DialogModel)
关键属性(DialogModel)
| Prop | Type | Description | Default | When to Use |
|---|---|---|---|---|
| boolean | Enable modal mode (blocks parent interaction) | false | Confirmations, alerts, critical actions |
| boolean | Initial visibility state | false | Control initial dialog display |
| string | JSX | Dialog header/title | - | Every dialog needs a title |
| string | HTML | JSX | Dialog body content | - | Main dialog information |
| ButtonPropsModel[] | Action buttons in footer | - | For OK/Cancel, action confirmations |
| JSX | Custom footer content | - | When buttons prop doesn't fit |
| boolean | Show close button in header | false | Allow users to dismiss |
| PositionData | X/Y positioning (center, top, etc.) | { X: 'center', Y: 'center' } | Custom placement |
| boolean | Enable drag functionality | false | Movable dialogs, floating panels |
| boolean | Enable resize with grip | false | Resizable dialogs |
| ResizeDirections[] | Which edges/corners resize | ['All'] | Control resize behavior |
| string | number | Dialog width | '330px' | Control dialog size |
| string | number | Dialog height | 'auto' | Control dialog size |
| string | number | Minimum height | - | Prevent too-small resize |
| AnimationSettingsModel | Animation effect/duration/delay | - | Smooth open/close transitions |
| boolean | Close on Escape key press | true | Keyboard navigation |
| string (selector) | Container element | document.body | Modal positioning |
| boolean | Sanitize HTML content | true | Security (prevent XSS) |
| string | Custom CSS classes | - | Styling and theming |
| boolean | Right-to-left rendering | false | RTL languages |
| string | Culture/language code | 'en-US' | Localization |
| number | Stack order | - | Manage overlapping dialogs |
| boolean | Persist state on reload | false | Remember size/position |
| 属性 | 类型 | 描述 | 默认值 | 适用场景 |
|---|---|---|---|---|
| boolean | 启用模态模式(阻止父元素交互) | false | 确认操作、警告、关键操作 |
| boolean | 初始可见状态 | false | 控制对话框初始显示 |
| string | JSX | 对话框标题 | - | 所有需要标题的对话框 |
| string | HTML | JSX | 对话框主体内容 | - | 对话框核心信息展示 |
| ButtonPropsModel[] | 页脚操作按钮 | - | OK/Cancel按钮、操作确认 |
| JSX | 自定义页脚内容 | - | 默认按钮属性无法满足需求时 |
| boolean | 在标题栏显示关闭按钮 | false | 允许用户关闭对话框 |
| PositionData | X/Y定位(center、top等) | { X: 'center', Y: 'center' } | 自定义布局 |
| boolean | 启用拖动功能 | false | 可移动对话框、浮动面板 |
| boolean | 启用调整大小手柄 | false | 可调整大小的对话框 |
| ResizeDirections[] | 可调整的边缘/角落 | ['All'] | 控制调整大小行为 |
| string | number | 对话框宽度 | '330px' | 控制对话框尺寸 |
| string | number | 对话框高度 | 'auto' | 控制对话框尺寸 |
| string | number | 最小高度 | - | 防止调整到过小尺寸 |
| AnimationSettingsModel | 动画效果/时长/延迟 | - | 平滑的打开/关闭过渡 |
| boolean | 按下Escape键关闭对话框 | true | 键盘导航支持 |
| string (选择器) | 容器元素 | document.body | 模态对话框定位 |
| boolean | 清理HTML内容 | true | 安全防护(防止XSS) |
| string | 自定义CSS类 | - | 样式与主题定制 |
| boolean | 从右到左渲染 | false | RTL语言环境 |
| string | 文化/语言代码 | 'en-US' | 本地化支持 |
| number | 堆叠顺序 | - | 管理重叠对话框层级 |
| boolean | 重载时保留状态 | false | 记住尺寸/位置 |
Common Use Cases
常见使用场景
- Confirmation Dialogs - Confirm delete, submit, or critical actions before proceeding
- Alert/Info Popups - Display system messages, warnings, or notifications
- Form Dialogs - Edit profiles, settings, or create new records in modal forms
- Input Prompts - Collect user input for specific actions (e.g., "Enter file name")
- Properties Panels - Draggable, non-modal panels for settings or properties
- Multi-Step Workflows - Nested dialogs for step-by-step processes
- Loading/Processing - Show progress indicators or loading states
- Help/Documentation - Contextual help, tips, or tutorial overlays
- Image Galleries - Lightbox dialogs for images or media previews
- Settings/Preferences - Organize application settings in tabbed dialogs
Next: Choose a reference based on what you need to implement. All references include working code examples, best practices, and troubleshooting guidance.
- 确认对话框 - 在执行删除、提交或关键操作前进行确认
- 警告/信息弹窗 - 显示系统消息、警告或通知
- 表单对话框 - 在模态表单中编辑个人资料、设置或创建新记录
- 输入提示框 - 收集用户特定操作的输入(如“输入文件名”)
- 属性面板 - 可拖动的非模态面板,用于设置或属性展示
- 多步骤工作流 - 使用嵌套对话框实现分步流程
- 加载/处理状态 - 显示进度指示器或加载状态
- 帮助/文档 - 上下文帮助、提示或教程叠加层
- 图片画廊 - 用于图片或媒体预览的灯箱对话框
- 设置/偏好 - 在标签式对话框中组织应用设置
下一步: 根据需要实现的功能选择对应的参考文档。所有参考文档均包含可运行的代码示例、最佳实践和故障排除指南。
Implementing Syncfusion React Predefined Dialog Component
实现 Syncfusion React 预定义对话框组件
Table of Contents
目录
Key Concept
核心概念
Syncfusion Predefined Dialogs are not component-based (). They are opened
imperatively via the utility class:
<ejs-dialog>DialogUtility| Dialog Type | Method |
|---|---|
| Alert | |
| Confirm | |
| Prompt (input) | |
Import:
import { DialogUtility } from '@syncfusion/ej2-react-popups';Syncfusion 预定义对话框不是基于组件的()。它们通过****工具类以命令式方式打开:
<ejs-dialog>DialogUtility| 对话框类型 | 方法 |
|---|---|
| 警告框 | |
| 确认框 | |
| 提示框(输入) | |
导入:
import { DialogUtility } from '@syncfusion/ej2-react-popups';Quick Start
快速入门
tsx
import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import { DialogUtility } from '@syncfusion/ej2-react-popups';
import * as React from 'react';
function App() {
function showAlert() {
DialogUtility.alert({
title: 'Low Battery',
width: '250px',
content: '10% of battery remaining',
});
}
return <ButtonComponent cssClass="e-danger" onClick={showAlert}>Alert</ButtonComponent>;
}
export default App;tsx
import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import { DialogUtility } from '@syncfusion/ej2-react-popups';
import * as React from 'react';
function App() {
function showAlert() {
DialogUtility.alert({
title: 'Low Battery',
width: '250px',
content: '10% of battery remaining',
});
}
return <ButtonComponent cssClass="e-danger" onClick={showAlert}>Alert</ButtonComponent>;
}
export default App;Documentation Guide
文档指南
Getting Started
快速入门
📄 Read: references/getting-started.md
- Installation ()
@syncfusion/ej2-react-popups - CSS imports
- Alert, Confirm, and Prompt minimal examples
- Functional and class component patterns
📄 阅读: references/getting-started.md
- 安装()
@syncfusion/ej2-react-popups - CSS导入
- 警告框、确认框、提示框的最简示例
- 函数组件与类组件模式
Animation
动画
📄 Read: references/animation.md
- property with
animationSettings,effect,durationdelay - Alert / Confirm / Prompt animation examples
📄 阅读: references/animation.md
- 属性,包含
animationSettings、effect、durationdelay - 警告框/确认框/提示框的动画示例
Draggable
可拖动
📄 Read: references/draggable.md
- boolean property
isDraggable - Alert / Confirm / Prompt drag examples
📄 阅读: references/draggable.md
- 布尔属性
isDraggable - 警告框/确认框/提示框的拖动示例
Position
定位
📄 Read: references/position.md
- property:
position—{ X, Y }/left|center|rightor numeric offsettop|center|bottom - Alert / Confirm / Prompt position examples
📄 阅读: references/position.md
- 属性:
position—{ X, Y }/left|center|right或数值偏移top|center|bottom - 警告框/确认框/提示框的定位示例
Dimension
尺寸
📄 Read: references/dimension.md
- and
widthpropertiesheight - for max-width / min-width constraints
cssClass - Alert / Confirm / Prompt dimension examples
📄 阅读: references/dimension.md
- 与
width属性height - 使用设置最大宽度/最小宽度约束
cssClass - 警告框/确认框/提示框的尺寸示例
Customization
自定义
📄 Read: references/customization.md
- /
okButton— customcancelButton,text,iconhandlerclick - and
showCloseIconcloseOnEscape - Custom for prompt dialogs
content
📄 阅读: references/customization.md
- /
okButton— 自定义cancelButton、text、icon处理函数click - 与
showCloseIconcloseOnEscape - 提示框的自定义
content
API Reference
API参考
📄 Read: references/api.md
- Full /
DialogUtility.alert()option propertiesconfirm() - All supported fields: ,
title,content,width,height,position,animationSettings,isDraggable,okButton,cancelButton,showCloseIcon,closeOnEscapecssClass
📄 阅读: references/api.md
- /
DialogUtility.alert()的完整配置属性confirm() - 所有支持字段:、
title、content、width、height、position、animationSettings、isDraggable、okButton、cancelButton、showCloseIcon、closeOnEscapecssClass
Common Patterns
常见模式
Alert with OK callback:
tsx
const dialogObj = DialogUtility.alert({
title: 'Info',
content: 'Operation complete.',
okButton: { click: () => { dialogObj.hide(); } }
});Confirm with Yes / No:
tsx
const dialogObj = DialogUtility.confirm({
title: 'Delete?',
content: 'Are you sure?',
width: '300px',
okButton: { text: 'Yes', click: () => { dialogObj.hide(); /* do delete */ } },
cancelButton: { text: 'No', click: () => { dialogObj.hide(); } }
});Prompt (input capture):
tsx
const dialogObj = DialogUtility.confirm({
title: 'Enter Name',
content: '<p>Your name:</p><input id="nameInput" class="e-input" placeholder="Type here..." />',
width: '300px',
okButton: {
text: 'Submit',
click: () => {
const val = (document.getElementById('nameInput') as HTMLInputElement).value;
dialogObj.hide();
}
},
cancelButton: { click: () => dialogObj.hide() }
});带OK回调的警告框:
tsx
const dialogObj = DialogUtility.alert({
title: 'Info',
content: 'Operation complete.',
okButton: { click: () => { dialogObj.hide(); } }
});带Yes/No的确认框:
tsx
const dialogObj = DialogUtility.confirm({
title: 'Delete?',
content: 'Are you sure?',
width: '300px',
okButton: { text: 'Yes', click: () => { dialogObj.hide(); /* do delete */ } },
cancelButton: { text: 'No', click: () => { dialogObj.hide(); } }
});提示框(捕获输入):
tsx
const dialogObj = DialogUtility.confirm({
title: 'Enter Name',
content: '<p>Your name:</p><input id="nameInput" class="e-input" placeholder="Type here..." />',
width: '300px',
okButton: {
text: 'Submit',
click: () => {
const val = (document.getElementById('nameInput') as HTMLInputElement).value;
dialogObj.hide();
}
},
cancelButton: { click: () => dialogObj.hide() }
});Implementing Syncfusion React Tooltip
实现 Syncfusion React Tooltip
A comprehensive skill for implementing the Syncfusion React — covering setup, content strategies, positioning, open modes, animation, customization, accessibility, and advanced how-to patterns.
TooltipComponentPackage:
Import:
@syncfusion/ej2-react-popupsImport:
import { TooltipComponent } from '@syncfusion/ej2-react-popups';本指南全面介绍如何实现Syncfusion React — 涵盖设置、内容策略、定位、触发模式、动画、自定义、无障碍支持以及高级实现模式。
TooltipComponent包:
导入:
@syncfusion/ej2-react-popups导入:
import { TooltipComponent } from '@syncfusion/ej2-react-popups';Quick Start
快速入门
bash
npm install @syncfusion/ej2-react-popups --savecss
/* src/App.css */
@import "../node_modules/@syncfusion/ej2-base/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-react-popups/styles/tailwind3.css";tsx
import * as React from 'react';
import { TooltipComponent } from '@syncfusion/ej2-react-popups';
import './App.css';
function App() {
return (
<TooltipComponent content="Tooltip Content" position="TopCenter">
<button className="e-btn">Show Tooltip</button>
</TooltipComponent>
);
}
export default App;bash
npm install @syncfusion/ej2-react-popups --savecss
/* src/App.css */
@import "../node_modules/@syncfusion/ej2-base/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-react-popups/styles/tailwind3.css";tsx
import * as React from 'react';
import { TooltipComponent } from '@syncfusion/ej2-react-popups';
import './App.css';
function App() {
return (
<TooltipComponent content="Tooltip Content" position="TopCenter">
<button className="e-btn">Show Tooltip</button>
</TooltipComponent>
);
}
export default App;Navigation Guide
导航指南
Getting Started & Setup
快速入门与设置
📄 Read: references/getting-started.md
- Installation and CSS imports
- Basic tooltip on a single element
- Tooltip on multiple targets within a container (prop)
target - Using attribute as fallback content
title - Running the application
📄 阅读: references/getting-started.md
- 安装与CSS导入
- 单个元素上的基础工具提示
- 容器内多个目标元素的工具提示(属性)
target - 使用属性作为备用内容
title - 运行应用
Content
内容
📄 Read: references/content.md
- Plain string content
- Template content (JSX function)
- Dynamic content loaded via Fetch/Ajax (event)
beforeRender - HTML content (iframe, embedded elements)
- Updating content programmatically with
dataBind()
📄 阅读: references/content.md
- 纯文本内容
- 模板内容(JSX函数)
- 通过Fetch/Ajax加载动态内容(事件)
beforeRender - HTML内容(iframe、嵌入元素)
- 使用以编程方式更新内容
dataBind()
Positioning
定位
📄 Read: references/position.md
- 12 static positions (,
TopLeft,TopCenter,TopRight,BottomLeft,BottomCenter,BottomRight,LeftTop,LeftCenter,LeftBottom,RightTop,RightCenter)RightBottom - Tip pointer show/hide () and positioning (
showTipPointer: Auto, Start, Middle, End)tipPointerPosition - Dynamic positioning with method (draggable targets)
refresh() - Mouse trailing ()
mouseTrail - Offset values (,
offsetX)offsetY - Collision handling (auto-flip behavior, )
windowCollision
📄 阅读: references/position.md
- 12种静态位置(、
TopLeft、TopCenter、TopRight、BottomLeft、BottomCenter、BottomRight、LeftTop、LeftCenter、LeftBottom、RightTop、RightCenter)RightBottom - 提示箭头显示/隐藏()与定位(
showTipPointer: Auto、Start、Middle、End)tipPointerPosition - 使用方法实现动态定位(可拖动目标)
refresh() - 鼠标跟随()
mouseTrail - 偏移值(、
offsetX)offsetY - 碰撞处理(自动翻转行为、)
windowCollision
Open Modes
触发模式
📄 Read: references/open-mode.md
- ,
Auto,Hover,Click,Focusmodes viaCustomopensOn - Combining multiple modes ()
opensOn="Hover Click" - Sticky mode () — close button appears
isSticky - Open/close delay (,
openDelay)closeDelay - Custom open mode with and
open()methodsclose() - Mobile behavior (tap-and-hold)
📄 阅读: references/open-mode.md
- 通过属性设置
opensOn、Auto、Hover、Click、Focus模式Custom - 组合多种模式()
opensOn="Hover Click" - 粘性模式()— 显示关闭按钮
isSticky - 打开/关闭延迟(、
openDelay)closeDelay - 使用与
open()方法实现自定义触发模式close() - 移动端行为(长按触发)
Animation
动画
📄 Read: references/animation.md
- property (open/close
animation)AnimationModel - All 15 available animation effects (FadeIn, ZoomIn, FlipX/Y, etc.)
- Custom duration and delay
- Animating via and
open()methods programmaticallyclose() - Transition effect using + CSS transitions
beforeRender
📄 阅读: references/animation.md
- 属性(打开/关闭
animation)AnimationModel - 所有15种可用动画效果(FadeIn、ZoomIn、FlipX/Y等)
- 自定义时长与延迟
- 通过与
open()方法以编程方式触发动画close() - 使用+ CSS过渡实现过渡效果
beforeRender
Customization
自定义
📄 Read: references/customization.md
- for custom themes and styles
cssClass - Tip pointer size, background, and border customization
- Full tooltip appearance (background, opacity, font)
- Curved tip and bubble tip arrow patterns
- Dimension control (,
width) and scroll modeheight - RTL support ()
enableRtl
📄 阅读: references/customization.md
- 使用自定义主题与样式
cssClass - 提示箭头大小、背景与边框定制
- 工具提示整体外观(背景、透明度、字体)
- 弧形提示与气泡箭头模式
- 尺寸控制(、
width)与滚动模式height - RTL支持()
enableRtl
How-To Patterns
实现模式
📄 Read: references/how-to.md
- Tooltip on multiple targets (dynamic content per target)
- Tooltip on disabled elements
- Enabling/disabling tooltip with and
destroy()render() - Displaying tooltip on SVG and Canvas elements
- Embedding iframes or HTML elements in tooltip content
- Custom open modes (double-click, right-click)
📄 阅读: references/how-to.md
- 多目标元素的工具提示(每个目标动态内容)
- 禁用元素上的工具提示
- 使用与
destroy()启用/禁用工具提示render() - SVG与Canvas元素上的工具提示
- 在工具提示内容中嵌入iframe或HTML元素
- 自定义触发模式(双击、右键点击)
Accessibility
无障碍支持
📄 Read: references/accessibility.md
- WCAG 2.2 and Section 508 compliance
- WAI-ARIA attributes (,
role="tooltip",aria-describedby)aria-hidden - Keyboard shortcuts (Escape, Tab)
- Screen reader behavior
📄 阅读: references/accessibility.md
- WCAG 2.2与Section 508合规性
- WAI-ARIA属性(、
role="tooltip"、aria-describedby)aria-hidden - 键盘快捷键(Escape、Tab)
- 屏幕阅读器行为
API Reference
API参考
📄 Read: references/api.md
- All properties, methods, and events with types and defaults
- ,
TooltipAnimationSettingstypesTooltipEventArgs - and
Positionenum valuesTipPointerPosition
📄 阅读: references/api.md
- 所有属性、方法与事件,包含类型与默认值
- 、
TooltipAnimationSettings类型TooltipEventArgs - 与
Position枚举值TipPointerPosition
Common Patterns
常见模式
Tooltip on a Button
按钮上的工具提示
tsx
<TooltipComponent content="Submit the form" position="TopCenter">
<button className="e-btn e-primary">Submit</button>
</TooltipComponent>tsx
<TooltipComponent content="Submit the form" position="TopCenter">
<button className="e-btn e-primary">Submit</button>
</TooltipComponent>Multi-Target Tooltip in a Container
容器内多目标工具提示
tsx
// Single TooltipComponent handles all .e-info targets;
// each uses its own `title` attribute as content
<TooltipComponent target=".e-info" position="RightCenter">
<form>
<input className="e-info" type="text" title="Enter your name" />
<input className="e-info" type="email" title="Enter a valid email" />
</form>
</TooltipComponent>tsx
// 单个TooltipComponent处理所有.e-info目标;
// 每个目标使用自身的`title`属性作为内容
<TooltipComponent target=".e-info" position="RightCenter">
<form>
<input className="e-info" type="text" title="Enter your name" />
<input className="e-info" type="email" title="Enter a valid email" />
</form>
</TooltipComponent>Click-Triggered Sticky Tooltip
点击触发的粘性工具提示
tsx
<TooltipComponent
content="Click the × to close me"
opensOn="Click"
isSticky={true}
position="BottomCenter"
>
<button className="e-btn">Click Me</button>
</TooltipComponent>tsx
<TooltipComponent
content="Click the × to close me"
opensOn="Click"
isSticky={true}
position="BottomCenter"
>
<button className="e-btn">Click Me</button>
</TooltipComponent>Programmatic Open/Close
编程式打开/关闭
tsx
import * as React from 'react';
import { TooltipComponent } from '@syncfusion/ej2-react-popups';
function App() {
let tooltipRef: TooltipComponent;
const target = React.useRef<HTMLButtonElement>(null);
return (
<TooltipComponent
ref={t => (tooltipRef = t)}
content="Tooltip opened programmatically"
opensOn="Custom"
>
<button
ref={target}
className="e-btn"
onClick={() => {
if (target.current.getAttribute('data-tooltip-id')) {
tooltipRef.close();
} else {
tooltipRef.open(target.current);
}
}}
>
Toggle Tooltip
</button>
</TooltipComponent>
);
}tsx
import * as React from 'react';
import { TooltipComponent } from '@syncfusion/ej2-react-popups';
function App() {
let tooltipRef: TooltipComponent;
const target = React.useRef<HTMLButtonElement>(null);
return (
<TooltipComponent
ref={t => (tooltipRef = t)}
content="Tooltip opened programmatically"
opensOn="Custom"
>
<button
ref={target}
className="e-btn"
onClick={() => {
if (target.current.getAttribute('data-tooltip-id')) {
tooltipRef.close();
} else {
tooltipRef.open(target.current);
}
}}
>
Toggle Tooltip
</button>
</TooltipComponent>
);
}Mouse-Trailing Tooltip
鼠标跟随工具提示
tsx
<TooltipComponent
content="Following your mouse!"
mouseTrail={true}
showTipPointer={false}
>
<div style={{ width: '200px', height: '100px', background: '#eee' }}>
Hover over me
</div>
</TooltipComponent>tsx
<TooltipComponent
content="Following your mouse!"
mouseTrail={true}
showTipPointer={false}
>
<div style={{ width: '200px', height: '100px', background: '#eee' }}>
Hover over me
</div>
</TooltipComponent>Key Props at a Glance
关键属性概览
| Prop | Type | Default | Purpose |
|---|---|---|---|
| | — | Tooltip text, HTML, or JSX template |
| | — | CSS selector for multi-target mode |
| | | 12 placement values |
| | | Hover / Click / Focus / Custom |
| | | Keep visible until user closes |
| | | Follow mouse cursor |
| | | Show/hide arrow tip |
| | | Auto / Start / Middle / End |
| | | ms delay before opening |
| | | ms delay before closing |
| | | Distance from target (px) |
| | | Tooltip dimensions |
| | | Custom CSS class |
| | FadeIn/FadeOut 150ms | Open/close animation |
| | | Right-to-left rendering |
| | | Sanitize HTML content |
| | | Popup append target |
| | | Collision vs viewport |
| 属性 | 类型 | 默认值 | 用途 |
|---|---|---|---|
| | — | 工具提示文本、HTML或JSX模板 |
| | — | 多目标模式的CSS选择器 |
| | | 12种布局位置 |
| | | 悬停/点击/聚焦/自定义触发 |
| | | 保持可见直到用户关闭 |
| | | 跟随鼠标光标 |
| | | 显示/隐藏箭头提示 |
| | | 自动/起始/中间/结束位置 |
| | | 打开前延迟(毫秒) |
| | | 关闭前延迟(毫秒) |
| | | 与目标元素的距离(像素) |
| | | 工具提示尺寸 |
| | | 自定义CSS类 |
| | 淡入/淡出150ms | 打开/关闭动画 |
| | | 从右到左渲染 |
| | | 清理HTML内容 |
| | | 弹窗挂载目标 |
| | | 与视口碰撞处理 |