base-ui-react
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseBase UI React
Base UI React
Status: Beta (v1.0.0-beta.4) ⚠️ | Last Verified: 2025-11-18
状态:测试版(v1.0.0-beta.4)⚠️ | 最后验证时间:2025-11-18
What Is Base UI?
什么是Base UI?
MUI's unstyled, accessible React component library:
- 27+ accessible components
- Render props pattern
- Full styling control
- Floating UI integration
- Alternative to Radix UI
Beta status: v1.0.0-beta.4 (stable v1.0 expected Q4 2025)
MUI推出的无样式、无障碍React组件库:
- 27+个无障碍组件
- Render props模式
- 完全样式控制
- 集成Floating UI
- Radix UI的替代方案
测试版状态:v1.0.0-beta.4(预计2025年第四季度发布稳定版v1.0)
Quick Start
快速开始
Install
安装
bash
bun add @base-ui-components/reactbash
bun add @base-ui-components/reactBasic Dialog
基础Dialog组件
typescript
import * as Dialog from '@base-ui-components/react/dialog';
export function MyDialog() {
return (
<Dialog.Root>
<Dialog.Trigger>Open</Dialog.Trigger>
<Dialog.Portal>
<Dialog.Backdrop />
<Dialog.Popup>
<Dialog.Title>Title</Dialog.Title>
<Dialog.Description>Content</Dialog.Description>
<Dialog.Close>Close</Dialog.Close>
</Dialog.Popup>
</Dialog.Portal>
</Dialog.Root>
);
}typescript
import * as Dialog from '@base-ui-components/react/dialog';
export function MyDialog() {
return (
<Dialog.Root>
<Dialog.Trigger>Open</Dialog.Trigger>
<Dialog.Portal>
<Dialog.Backdrop />
<Dialog.Popup>
<Dialog.Title>Title</Dialog.Title>
<Dialog.Description>Content</Dialog.Description>
<Dialog.Close>Close</Dialog.Close>
</Dialog.Popup>
</Dialog.Portal>
</Dialog.Root>
);
}Basic Select
基础Select组件
typescript
import * as Select from '@base-ui-components/react/select';
<Select.Root>
<Select.Trigger>
<Select.Value placeholder="Select" />
</Select.Trigger>
<Select.Portal>
<Select.Positioner>
<Select.Popup>
<Select.Option value="1">Option 1</Select.Option>
<Select.Option value="2">Option 2</Select.Option>
</Select.Popup>
</Select.Positioner>
</Select.Portal>
</Select.Root>Load for complete examples.
references/setup-guide.mdtypescript
import * as Select from '@base-ui-components/react/select';
<Select.Root>
<Select.Trigger>
<Select.Value placeholder="Select" />
</Select.Trigger>
<Select.Portal>
<Select.Positioner>
<Select.Popup>
<Select.Option value="1">Option 1</Select.Option>
<Select.Option value="2">Option 2</Select.Option>
</Select.Popup>
</Select.Positioner>
</Select.Portal>
</Select.Root>查看 获取完整示例。
references/setup-guide.mdCore Components
核心组件
Available (27+):
- Dialog
- Select
- Popover
- Tooltip
- Accordion
- NumberField
- Checkbox
- Switch
- Tabs
- Slider
- And more...
已支持(27+个):
- Dialog
- Select
- Popover
- Tooltip
- Accordion
- NumberField
- Checkbox
- Switch
- Tabs
- Slider
- 更多...
Critical Rules
重要规则
Always Do ✅
必须遵循 ✅
- Use Portal for popups (Dialog, Select, Popover)
- Use Positioner for floating elements
- Add Backdrop for modal dialogs
- Style with Tailwind (or any CSS)
- Use render props (not asChild like Radix)
- Test accessibility (ARIA built-in)
- Handle Portal edge cases (SSR, hydration)
- Check beta docs for breaking changes
- Use TypeScript for better DX
- Test on target browsers
- 为弹窗类组件使用Portal(Dialog、Select、Popover)
- 为浮动元素使用Positioner
- 为模态Dialog添加Backdrop
- 使用Tailwind(或任意CSS)进行样式定制
- 使用render props(而非Radix的asChild)
- 测试无障碍性(内置ARIA支持)
- 处理Portal边缘情况(SSR、 hydration)
- 查看测试版文档了解破坏性变更
- 使用TypeScript提升开发体验
- 在目标浏览器上测试
Never Do ❌
禁止操作 ❌
- Never use asChild (use render function instead)
- Never skip Portal for popups (positioning breaks)
- Never skip Positioner (Floating UI won't work)
- Never assume API stability (beta software)
- Never skip accessibility testing
- Never use with React <19 (requires React 19+)
- Never skip Backdrop for modals
- Never hardcode z-index (use Portal)
- Never skip SSR testing (hydration issues)
- Never assume Radix compatibility (different API)
- 禁止使用asChild(改用渲染函数)
- 禁止为弹窗跳过Portal(会导致定位失效)
- 禁止跳过Positioner(Floating UI将无法正常工作)
- 不要假设API稳定(测试版软件)
- 禁止跳过无障碍测试
- 禁止与React <19版本搭配使用(要求React 19+)
- 禁止为模态框跳过Backdrop
- 禁止硬编码z-index(使用Portal)
- 禁止跳过SSR测试(会出现hydration问题)
- 不要假设与Radix兼容(API不同)
With Tailwind
搭配Tailwind使用
typescript
<Dialog.Popup className="rounded-lg bg-white p-6 shadow-xl dark:bg-gray-800">
<Dialog.Title className="text-xl font-bold text-gray-900 dark:text-white">
Dialog Title
</Dialog.Title>
<Dialog.Description className="mt-2 text-gray-600 dark:text-gray-300">
Dialog content here
</Dialog.Description>
<Dialog.Close className="mt-4 rounded bg-blue-500 px-4 py-2 text-white hover:bg-blue-600">
Close
</Dialog.Close>
</Dialog.Popup>typescript
<Dialog.Popup className="rounded-lg bg-white p-6 shadow-xl dark:bg-gray-800">
<Dialog.Title className="text-xl font-bold text-gray-900 dark:text-white">
Dialog Title
</Dialog.Title>
<Dialog.Description className="mt-2 text-gray-600 dark:text-gray-300">
Dialog content here
</Dialog.Description>
<Dialog.Close className="mt-4 rounded bg-blue-500 px-4 py-2 text-white hover:bg-blue-600">
Close
</Dialog.Close>
</Dialog.Popup>Common Use Cases
常见使用场景
Use Case 1: Modal Dialog
场景1:模态Dialog
typescript
<Dialog.Root>
<Dialog.Trigger className="btn">Open Modal</Dialog.Trigger>
<Dialog.Portal>
<Dialog.Backdrop className="fixed inset-0 bg-black/50" />
<Dialog.Popup className="fixed left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 rounded-lg bg-white p-6">
<Dialog.Title>Confirm Action</Dialog.Title>
<Dialog.Description>Are you sure?</Dialog.Description>
<Dialog.Close>Cancel</Dialog.Close>
</Dialog.Popup>
</Dialog.Portal>
</Dialog.Root>typescript
<Dialog.Root>
<Dialog.Trigger className="btn">Open Modal</Dialog.Trigger>
<Dialog.Portal>
<Dialog.Backdrop className="fixed inset-0 bg-black/50" />
<Dialog.Popup className="fixed left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 rounded-lg bg-white p-6">
<Dialog.Title>Confirm Action</Dialog.Title>
<Dialog.Description>Are you sure?</Dialog.Description>
<Dialog.Close>Cancel</Dialog.Close>
</Dialog.Popup>
</Dialog.Portal>
</Dialog.Root>Use Case 2: Dropdown Select
场景2:下拉选择器Select
typescript
<Select.Root>
<Select.Trigger className="flex items-center gap-2 rounded border px-4 py-2">
<Select.Value placeholder="Select option" />
</Select.Trigger>
<Select.Portal>
<Select.Positioner className="z-50">
<Select.Popup className="rounded border bg-white shadow-lg">
<Select.Option value="1" className="px-4 py-2 hover:bg-gray-100">
Option 1
</Select.Option>
<Select.Option value="2" className="px-4 py-2 hover:bg-gray-100">
Option 2
</Select.Option>
</Select.Popup>
</Select.Positioner>
</Select.Portal>
</Select.Root>typescript
<Select.Root>
<Select.Trigger className="flex items-center gap-2 rounded border px-4 py-2">
<Select.Value placeholder="Select option" />
</Select.Trigger>
<Select.Portal>
<Select.Positioner className="z-50">
<Select.Popup className="rounded border bg-white shadow-lg">
<Select.Option value="1" className="px-4 py-2 hover:bg-gray-100">
Option 1
</Select.Option>
<Select.Option value="2" className="px-4 py-2 hover:bg-gray-100">
Option 2
</Select.Option>
</Select.Popup>
</Select.Positioner>
</Select.Portal>
</Select.Root>Use Case 3: Tooltip
场景3:Tooltip提示框
typescript
import * as Tooltip from '@base-ui-components/react/tooltip';
<Tooltip.Root>
<Tooltip.Trigger>Hover me</Tooltip.Trigger>
<Tooltip.Portal>
<Tooltip.Positioner>
<Tooltip.Popup className="rounded bg-gray-900 px-2 py-1 text-sm text-white">
Tooltip text
</Tooltip.Popup>
</Tooltip.Positioner>
</Tooltip.Portal>
</Tooltip.Root>typescript
import * as Tooltip from '@base-ui-components/react/tooltip';
<Tooltip.Root>
<Tooltip.Trigger>Hover me</Tooltip.Trigger>
<Tooltip.Portal>
<Tooltip.Positioner>
<Tooltip.Popup className="rounded bg-gray-900 px-2 py-1 text-sm text-white">
Tooltip text
</Tooltip.Popup>
</Tooltip.Positioner>
</Tooltip.Portal>
</Tooltip.Root>Beta Considerations
测试版注意事项
Stable for production:
- Dialog
- Popover
- Tooltip
- Select
- Accordion
Use with caution:
- NumberField (API may change)
- Complex form components
Migration path:
- v1.0 stable expected Q4 2025
- Breaking changes will be documented
- Codemods likely provided
可稳定用于生产环境的组件:
- Dialog
- Popover
- Tooltip
- Select
- Accordion
需谨慎使用的组件:
- NumberField(API可能变更)
- 复杂表单组件
迁移路径:
- 预计2025年第四季度发布v1.0稳定版
- 破坏性变更将有文档说明
- 可能提供代码转换工具(Codemods)
vs Radix UI
与Radix UI对比
| Feature | Base UI | Radix UI |
|---|---|---|
| Pattern | Render props | asChild |
| Positioning | Floating UI built-in | Manual |
| Beta | Yes | Stable |
| Tree-shaking | Better | Good |
| Bundle size | Smaller | Larger |
When to use Base UI:
- Prefer render props
- Need built-in positioning
- Want smaller bundle
- Okay with beta
When to use Radix:
- Need stability
- Prefer asChild pattern
- Established ecosystem
| 特性 | Base UI | Radix UI |
|---|---|---|
| 模式 | Render props | asChild |
| 定位 | 内置Floating UI | 手动配置 |
| 版本状态 | 测试版 | 稳定版 |
| 树摇优化 | 更优 | 良好 |
| 包体积 | 更小 | 更大 |
何时选择Base UI:
- 偏好render props模式
- 需要内置定位功能
- 希望包体积更小
- 可以接受测试版状态
何时选择Radix UI:
- 需要版本稳定性
- 偏好asChild模式
- 依赖成熟的生态系统
Resources
资源
References ():
references/- - Detailed component examples and patterns
example-reference.md - - Complete migration guide from Radix UI (includes render prop pattern explanation)
migration-from-radix.md - - Installation and setup walkthrough
setup-guide.md
Templates ():
templates/- - Accordion component with render props
Accordion.tsx - - Modal dialog example
Dialog.tsx - - Number input with validation
NumberField.tsx - - Popover with positioning
Popover.tsx - - Select dropdown
Select.tsx - - Tooltip component
Tooltip.tsx - - Radix to Base UI migration example
migration-example.tsx
参考文档(目录):
references/- - 详细的组件示例与模式说明
example-reference.md - - 完整的Radix UI迁移指南(包含render props模式解释)
migration-from-radix.md - - 安装与配置分步教程
setup-guide.md
模板(目录):
templates/- - 使用render props的Accordion组件
Accordion.tsx - - 模态Dialog示例
Dialog.tsx - - 带验证的数字输入框
NumberField.tsx - - 带定位的Popover组件
Popover.tsx - - 下拉选择器
Select.tsx - - Tooltip提示框
Tooltip.tsx - - Radix UI迁移到Base UI的示例
migration-example.tsx
Official Documentation
官方文档
- Base UI: https://base-ui.mui.com/
- Components: https://base-ui.mui.com/components/
- Migration Guide: https://base-ui.mui.com/base-ui/getting-started/migration/
Questions? Issues?
- Check for setup
references/setup-guide.md - Review beta status warnings
- See official docs for latest updates
- Consider Radix if need stability
- Base UI官网:https://base-ui.mui.com/
- 组件文档:https://base-ui.mui.com/components/
- 迁移指南:https://base-ui.mui.com/base-ui/getting-started/migration/
有疑问?遇到问题?
- 查看了解配置方法
references/setup-guide.md - 查看测试版状态警告
- 查看官方文档获取最新更新
- 若需要稳定性,可考虑使用Radix UI