base-ui
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseBase UI (React)
Base UI (React)
Base UI provides unstyled, composable React components. This skill focuses on assembling multi-part components, composing with the prop, and meeting accessibility requirements while you supply styling.
renderBase UI 提供无样式、可组合的 React 组件。本技能聚焦于组装多部分组件、使用 prop进行组件组合,以及在你自定义样式的同时满足无障碍访问要求。
renderWhen to use
使用场景
Use this skill when the user wants to:
- Build UI with primitives.
@base-ui/react - Compose unstyled components with custom markup and styling.
- Implement menus, overlays, toasts, and toolbars.
- Build accessible form controls and grouped inputs.
当用户有以下需求时,可使用本技能:
- 使用基础组件构建UI。
@base-ui/react - 通过自定义标记和样式组合无样式组件。
- 实现菜单、浮层、提示框(Toast)和工具栏。
- 构建符合无障碍标准的表单控件和分组输入框。
Quick navigation (references)
快速导航(参考文档)
Utilities
工具类
- references/csp-provider.md
- references/direction-provider.md
- references/merge-props.md
- references/use-render.md
- references/csp-provider.md
- references/direction-provider.md
- references/merge-props.md
- references/use-render.md
Forms & inputs
表单与输入框
- references/form.md
- references/fieldset.md
- references/input.md
- references/number-field.md
- references/radio.md
- references/select.md
- references/slider.md
- references/switch.md
- references/form.md
- references/fieldset.md
- references/input.md
- references/number-field.md
- references/radio.md
- references/select.md
- references/slider.md
- references/switch.md
Feedback & status
反馈与状态
- references/meter.md
- references/progress.md
- references/toast.md
- references/meter.md
- references/progress.md
- references/toast.md
Menus, navigation, overlays
菜单、导航、浮层
- references/menu.md
- references/menubar.md
- references/navigation-menu.md
- references/popover.md
- references/preview-card.md
- references/tooltip.md
- references/menu.md
- references/menubar.md
- references/navigation-menu.md
- references/popover.md
- references/preview-card.md
- references/tooltip.md
Toggles & controls
开关与控件
- references/toggle.md
- references/toggle-group.md
- references/toolbar.md
- references/toggle.md
- references/toggle-group.md
- references/toolbar.md
Layout & separators
布局与分隔符
- references/scroll-area.md
- references/separator.md
- references/scroll-area.md
- references/separator.md
Core concepts to apply
核心概念
- Unstyled primitives: all visuals come from your CSS/Tailwind/CSS Modules. Base UI handles behavior and accessibility.
- Multi-part anatomy: most components follow + subparts (
Root,Trigger,Popup, etc.). Assemble them explicitly.Item - prop: replace the default element or wrap with your own component; when using the function form, merge props manually with
render.mergeProps - State-driven styling: many parts expose data attributes such as ,
data-[popup-open],data-[highlighted],data-[pressed],data-[checked], etc.data-[invalid] - Portals for overlays: use +
Portal+Positionerfor popovers, menus, tooltips, select, navigation menu content, and preview cards.Popup
- 无样式基础组件:所有视觉样式均来自你的CSS/Tailwind/CSS Modules。Base UI 负责处理组件行为和无障碍访问逻辑。
- 多部分结构:大多数组件遵循「Root + 子部件(如Trigger、Popup、Item等)」的结构,需要你显式组装。
- prop:替换默认元素或用自定义组件包裹;当使用函数形式时,需用
render手动合并props。mergeProps - 状态驱动样式:许多部件会暴露数据属性,例如、
data-[popup-open]、data-[highlighted]、data-[pressed]、data-[checked]等。data-[invalid] - 浮层使用Portal:对于弹出框、菜单、提示框、选择器、导航菜单内容和预览卡片,需结合使用+
Portal+Positioner。Popup
Recipes
实践方案
1) Build accessible forms quickly
1) 快速构建无障碍表单
- Wrap inputs with for submission and error aggregation.
Form - Use with a
Field.Root, thenname,Field.Label, andField.Controlfor labels and errors.Field.Error - Group related fields with +
Fieldset.Root.Fieldset.Legend - For groups, either use
RadiowithRadioGroup, or renderaria-labelledbyviaRadioGroupand useFieldset.Rootfor each option.Field.Label - Ensure every form control has an accessible name (label or /
Fieldlabeling pattern).Fieldset
- 用包裹输入框,处理表单提交和错误聚合。
Form - 使用带属性的
name,搭配Field.Root、Field.Label和Field.Control实现标签和错误提示。Field.Error - 用+
Fieldset.Root对相关字段进行分组。Fieldset.Legend - 对于组,可使用带
Radio的aria-labelledby,或通过RadioGroup渲染Fieldset.Root,并为每个选项使用RadioGroup。Field.Label - 确保每个表单控件都有可访问的名称(通过标签或/
Field标记模式)。Fieldset
2) Compose with render
+ mergeProps
rendermergeProps2) 结合render
+ mergeProps
进行组件组合
rendermergeProps- When passing a React element to , Base UI merges props automatically.
render - When passing a function to , merge Base UI props and your props with
render.mergeProps - Use inside merged event handlers to stop Base UI’s internal behavior when needed (synthetic events only).
event.preventBaseUIHandler()
- 当向传递React元素时,Base UI会自动合并props。
render - 当向传递函数时,必须使用
render合并Base UI的props和你的自定义props。mergeProps - 当需要阻止Base UI的内部行为时,可在合并后的事件处理函数中使用(仅适用于合成事件)。
event.preventBaseUIHandler()
3) Overlays and menus (portaled UI)
3) 浮层与菜单(使用Portal的UI)
- Build popups using +
Root+Trigger+Portal+Positioner.Popup - For menus and navigation, add ,
Item,Separator, and list/viewport parts as needed.Arrow - supports
NavigationMenu.Linkfor framework router links.render
- 结合+
Root+Trigger+Portal+Positioner构建弹出框。Popup - 对于菜单和导航,按需添加、
Item、Separator以及列表/视口部件。Arrow - 支持通过
NavigationMenu.Link适配框架路由链接。render
4) Toasts
4) 提示框(Toast)
- Wrap the app (or a subtree) with .
Toast.Provider - Use to create toasts.
Toast.useToastManager() - Render a inside
Toast.Viewport, then mapToast.Portaltotoastsentries withToast.Root,Toast.Content,Toast.Title, andToast.Description.Toast.Close
- 用包裹应用(或其子树)。
Toast.Provider - 使用创建提示框。
Toast.useToastManager() - 在内渲染
Toast.Portal,然后将Toast.Viewport映射为包含toasts、Toast.Content、Toast.Title和Toast.Description的Toast.Close条目。Toast.Root
5) RTL and CSP constraints
5) RTL布局与CSP约束
- For RTL behavior, wrap with and also set
DirectionProvider(provider does not set the DOM direction).dir="rtl" - For strict CSP, wrap with and pass
CSPProvider, or disable inline style elements if your app supplies external styles. Beware inline style attributes are not controlled bynonce.CSPProvider
- 如需RTL(从右到左)布局,用包裹组件,同时设置
DirectionProvider(Provider不会自动设置DOM的方向属性)。dir="rtl" - 对于严格的CSP(内容安全策略),用包裹并传入
CSPProvider,或在应用使用外部样式时禁用内联样式元素。注意,内联样式属性不受nonce控制。CSPProvider
6) Sliders and ranges
6) 滑块与范围选择器
- Single value sliders: one .
Slider.Thumb - Range sliders: pass an array and render a per value; add
Slider.Thumbfor SSR alignment.index - Adjust thumb alignment with when edge alignment is required.
thumbAlignment
- 单值滑块:使用一个。
Slider.Thumb - 范围滑块:传入数组并为每个值渲染一个;为了SSR对齐,需添加
Slider.Thumb属性。index - 当需要边缘对齐时,使用调整滑块的对齐方式。
thumbAlignment
Critical prohibitions
注意事项
- Do not omit accessible labels for inputs, sliders, switches, or radio groups.
- Do not expect Base UI to provide default styling; apply your own styles.
- Do not forget for overlays that need to escape stacking/overflow contexts.
Portal - Do not skip when using the function form of
mergeProps.render
- 不得省略输入框、滑块、开关或单选按钮组的无障碍标签。
- 不要期望Base UI提供默认样式;需自行应用自定义样式。
- 对于需要突破堆叠/溢出上下文的浮层,不要忘记使用。
Portal - 当使用的函数形式时,不得遗漏
render。mergeProps
Output expectations
输出要求
When responding to the user, provide:
- The specific Base UI components to use (and their key parts).
- A brief assembly plan (Root + parts + portal/positioner where relevant).
- A short checklist for accessibility and state-driven styling.
回复用户时,需包含:
- 推荐使用的具体Base UI组件(及其核心部件)。
- 简短的组装方案(Root + 部件 + 按需使用的portal/positioner)。
- 无障碍访问和状态驱动样式的简短检查清单。",