显示一个选项列表,供用户选择 - 由按钮触发。
¥API Reference
¥Root
包含选择框的所有部分。它继承了 Select 基元 根 部分的 props。
¥Contains all the parts of a select. It inherits props from the Select primitive Root part.
¥Trigger
切换选择按钮。此组件继承了 Select 基础组件 触发器 和 值 部件的属性。支持 常用边距属性。
¥The button that toggles the select. This component inherits props from the Select primitive Trigger and Value parts. It supports common margin props.
¥Content
选择框打开时弹出的组件。它继承了 Select.Portal 基础组件 和 Select.Content 基础组件 部分的 props。
¥The component that pops out when the select is open. It inherits props from the Select.Portal primitive and Select.Content primitive parts.
¥Item
包含选择项的组件。它继承了 Select.Item 基础组件 部分的 props。
¥The component that contains the select items. It inherits props from the Select.Item primitive part.
¥Group
用于对多个项目进行分组。它继承了 Select.Group 基础组件 部分的 props。与 Select.Label
结合使用,通过自动标记确保良好的可访问性。
¥Used to group multiple items. It inherits props from the Select.Group primitive part. Use in conjunction with Select.Label
to ensure good accessibility via automatic labelling.
¥Label
用于渲染组的标签,无法使用箭头键获得焦点。它继承了 Select.Label 基础组件 部分的 props。
¥Used to render the label of a group, it isn't focusable using arrow keys. It inherits props from the Select.Label primitive part.
¥Separator
用于在选择菜单中以视觉方式分隔项目。它继承了 Select.Separator 基础组件 部分的 props。
¥Used to visually separate items in the Select. It inherits props from the Select.Separator primitive part.
¥Examples
¥Size
使用 size
属性控制大小。
¥Use the size
prop to control the size.
¥Variant
在 Trigger
和 Content
上使用 variant
属性来自定义视觉样式。
¥Use the variant
prop on Trigger
and Content
to customize the visual style.
¥Ghost
使用 ghost
触发器变体渲染触发器,使其不包含视觉包含元素。幽灵触发器在布局中的行为有所不同,因为它们使用负边距使其与兄弟按钮在视觉上对齐,同时在活动和悬停状态下保持填充。
¥Use the ghost
trigger variant to render the trigger without a visually containing element. Ghost triggers behave differently in layout as they use a negative margin to optically align themselves against their siblings while maintaining their padded active and hover states.
¥Color
在 Trigger
和 Content
上使用 color
属性来分配特定的颜色值。
¥Use the color
prop on Trigger
and Content
to assign a specific color value.
¥High-contrast
在 Content
上使用 highContrast
属性来增加项目对比度。
¥Use the highContrast
prop on Content
to increase item contrast.
¥Radius
使用 radius
属性指定特定的圆角值。
¥Use the radius
prop to assign a specific radius value.
¥Placeholder
使用 placeholder
属性创建不需要初始值的 Trigger
。
¥Use the placeholder
prop to create a Trigger
that doesn’t need an initial value.
¥Position
设置 position="popper"
属性,将选择菜单置于触发器下方。
¥Set position="popper"
prop to position the select menu below the trigger.
¥With SSR
使用服务器端渲染时,你可能会注意到水合后布局发生变化。这是因为触发器执行客户端代码来显示所选项目的文本。为避免布局偏移,你可以通过映射值手动渲染。
¥When using server-side rendering, you might notice a layout shift after hydration. This is because Trigger executes client-side code to display the selected item’s text. To avoid that layout shift, you can render it manually by mapping values.
¥With an icon
你可以通过手动控制触发器的子项来自定义触发器如何呈现值。例如,你可以在所选项目的文本旁边渲染一个图标。
¥You can customise how Trigger renders the value by controlling its children manually. For example, you can render an icon next to the selected item’s text.