Skip to Content
文档

列表框

用于显示可供选择的选项列表。

SourceStorybookRecipeArk
React.js
Vue.js
Angular
Svelte

用法

¥Usage

import { Listbox } from "@chakra-ui/react"
<Listbox.Root>
  <Listbox.Label />
  <Listbox.Content>
    <Listbox.Item>
      <Listbox.ItemText />
      <Listbox.ItemIndicator />
    </Listbox.Item>
  </Listbox.Content>
</Listbox.Root>

示例

¥Examples

受控

¥Controlled

使用 valueonValueChange 属性从外部控制列表框值,以进行自定义状态管理。

¥Control the listbox value externally using the value and onValueChange props for custom state management.

React.js
Vue.js
Angular
Svelte
Selected: []

带存储

¥With Store

控制列表框的另一种方法是使用 RootProvider 组件和 useListbox store 钩子。

¥An alternative way to control the listbox is to use the RootProvider component and the useListbox store hook.

这样,您可以从列表框外部访问列表框的状态和方法。

¥This way you can access the listbox state and methods from outside the listbox.

请使用 RootProvider + useListboxRoot,不要同时使用两者。

React.js
Vue.js
Angular
Svelte
Selected: []

已禁用项目

¥Disabled Item

禁用列表框中的特定项目以指示不可用选项,同时保持它们在上下文中可见。

¥Disable specific items in the listbox to indicate unavailable options while keeping them visible for context.

React.js
Vue.js
Angular
Svelte
Next.js

分组

¥Grouped

使用项目组来组织相关选项,并使其具有清晰的章节标题,使用户更容易找到特定类别的项目。

¥Use item groups to organize related options with clear section headers, making it easier for users to find specific categories of items.

Naruto
One Piece
Dragon Ball
The Shawshank Redemption
The Godfather
The Dark Knight

水平

¥Horizontal

以卡片式呈现方式水平布局显示列表框项目,非常适合媒体图库或可视化选择界面。

¥Display listbox items in a horizontal layout with card-based presentation, perfect for media galleries or visual selection interfaces.

Euphoric Echoes

Euphoric Echoes

Luna Solstice

Neon Dreamscape

Neon Dreamscape

Electra Skyline

Cosmic Serenade

Cosmic Serenade

Orion's Symphony

Melancholy Melodies

Melancholy Melodies

Violet Mistral

Rhythmic Illusions

Rhythmic Illusions

Mirage Beats

多选

¥Multiple Selection

允许用户从列表中选择多个项目,这在选择标签、类别或偏好设置等场景中非常有用。

¥Enable users to select multiple items from the list, useful for scenarios like choosing tags, categories, or preferences.

React.js
Vue.js
Angular
Svelte
Next.js
Nuxt.js

全选

¥Select All

为多选场景提供便捷的 "全选" 和 "选择无" 控件,并通过可视化指示器显示选择状态。

¥Provide convenient "Select All" and "Select None" controls for multiple selection scenarios, with visual indicators showing selection state.

React.js
Vue.js
Angular
Svelte
Next.js
Nuxt.js
Remix
Gatsby
Ember.js
Preact

扩展选择

¥Extended Select

使用扩展选择模式,允许用户使用键盘快捷键(例如 Cmd/Ctrl)选择多个项目,以实现高级选择模式。

¥Use extended selection mode to allow users to select multiple items using keyboard shortcuts like Cmd/Ctrl for advanced selection patterns.

React.js
Vue.js
Angular
Svelte

带复选标记

¥With Checkmark

在多选场景下显示自定义复选标记,为所选项目提供清晰的视觉反馈。

¥Display custom checkmarks for multiple selection scenarios, providing clear visual feedback for selected items.

React.js
Vue.js
Angular
Svelte
Next.js
Nuxt.js

包含图标

¥With Icon

为列表框项添加图标,以提供视觉上下文并提高对不同选项的识别度。

¥Add icons to listbox items to provide visual context and improve recognition of different options.

React.js
Vue.js
Angular
Svelte

带描述

¥With Description

为每个项目添加额外的描述性文字,以提供更多上下文并帮助用户做出明智的选择。

¥Include additional descriptive text for each item to provide more context and help users make informed choices.

React.js

A JavaScript library for building user interfaces

Vue.js

The progressive JavaScript framework

Angular

Platform for building mobile and desktop web applications

Svelte

Cybernetically enhanced web apps

Next.js

The React framework for production

带输入框

¥With Input

将搜索输入与列表框结合使用,可以动态过滤选项,从而轻松地在长列表中找到特定项目。

¥Combine a search input with the listbox to filter options dynamically, making it easy to find specific items in long lists.

React.js
Vue.js
Angular
Svelte
Next.js
Nuxt.js
Remix
Gatsby
Ember.js
Preact

带弹出框

¥With Popover

使用弹出框中的列表框创建类似下拉的选择菜单,这些菜单可以覆盖其他内容,而不会占用永久的屏幕空间。

¥Use the listbox within a popover to create dropdown-like selection menus that overlay other content without taking up permanent screen space.

带对话框

¥With Dialog

在模态对话框中呈现列表框,以获得聚焦选择体验,尤其适用于需要用户注意的重要选项。

¥Present the listbox in a modal dialog for focused selection experiences, particularly useful for important choices that need user attention.

虚拟化

¥Virtualized

通过虚拟化高效处理大型数据集,仅渲染可见项目,即使项目数量达到数千个也能保持流畅的滚动性能。

¥Handle large datasets efficiently with virtualization, rendering only visible items to maintain smooth scrolling performance even with thousands of items.

图像浏览器

¥Image Explorer

创建一个交互式图库,其中列表框充当导航栏,用于显示不同的图片或媒体内容。

¥Create an interactive gallery where the listbox acts as navigation for displaying different images or media content.

Mountain Landscape
Ocean Waves
Forest Path
City Skyline
Desert Dunes

Mountain Landscape

Mountain Landscape

Scenic mountain view

传输列表

¥Transfer List

创建一个双列表框界面,用于在可用状态和选中状态之间移动项目,通常用于权限管理或项目选择工作流。

¥Create a dual-listbox interface for moving items between available and selected states, commonly used for permission management or item selection workflows.

Naruto
Sasuke
Sakura
Kakashi
Shisui
Itachi
Gaara
Rock Lee
Neji
Tenten
Hinata
Kiba
Shino
Choji
Ino
No items available

属性

¥Props

根元素

¥Root

标签

¥Label

内容

¥Content

项目

¥Item

ItemText

ItemIndicator

ItemGroup

ItemGroupLabel

Previous

组合框

Next

选择