Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
import { Box, Collapsible } from "@chakra-ui/react"
export const CollapsibleBasic = () => (
<Collapsible.Root>
<Collapsible.Trigger paddingY="3">Toggle Collapsible</Collapsible.Trigger>
<Collapsible.Content>
<Box padding="4" borderWidth="1px">
Lorem Ipsum is simply dummy text of the printing and typesetting
industry. Lorem Ipsum has been the industry's standard dummy text ever
since the 1500s, when an unknown printer took a galley of type and
scrambled it to make a type specimen book.
</Box>
</Collapsible.Content>
</Collapsible.Root>
)
用法
import { Collapsible } from "@chakra-ui/react"
<Collapsible.Root>
<Collapsible.Trigger />
<Collapsible.Content />
</Collapsible.Root>
示例
延迟挂载
使用 unmountOnExit
属性可在内容折叠时卸载它。
如果你检查 DOM,你会注意到内容在折叠时被卸载。当有大量可折叠内容时,这对于性能优化很有用。
import { Box, Collapsible } from "@chakra-ui/react"
export const CollapsibleLazyMounted = () => (
<Collapsible.Root unmountOnExit>
<Collapsible.Trigger paddingY="3">
Toggle Collapse (Unmount on exit)
</Collapsible.Trigger>
<Collapsible.Content>
<Box padding="4" borderWidth="1px">
If you inspect the DOM, you'll notice that the content is unmounted when
collapsed. This is useful for performance reasons when you have a lot of
collapsible content.
</Box>
</Collapsible.Content>
</Collapsible.Root>
)
属性
根组件
属性 | 默认值 | 类型 |
---|---|---|
lazyMount | false | 布尔值 是否启用延迟挂载 |
unmountOnExit | false | 布尔值 是否在退出时卸载。 |
asChild | ||
defaultOpen | 布尔值 可折叠组件首次渲染时的初始打开状态。当您不需要控制其打开状态时使用。 | |
disabled | 布尔值 可折叠组件是否禁用 | |
ids | Partial<{ root: string; content: string; trigger: string }> 可折叠组件中元素的 ID。对组合很有用。 | |
onExitComplete | () => void 当动画在关闭状态下结束时调用的函数。 | |
onOpenChange | (details: OpenChangeDetails) => void 当弹出窗口打开时调用的函数 | |
open | 布尔值 可折叠组件是否打开 |