Skip to content

Collapse Component

Collapse Component

Collapse component is used to fold/expand content areas, saving page space. It's commonly used for grouped information display, FAQ, settings, and other content. It's suitable for scenarios with large amounts of information that need to be displayed in groups.

Basic Usage

Basic collapse usage, click panel title to toggle expand/collapse state of content area.

Currently active panels: [ "1" ]

Show CodeArrow
CopyGitHub

Accordion Mode

Setting the accordion attribute to true enables accordion mode, where only one panel can be expanded at a time.

Accordion Mode (Only one panel can be expanded at a time)

Comparison: Normal Mode (Multiple panels can be expanded simultaneously)

Show CodeArrow
CopyGitHub

Custom Styles

You can customize the style of collapse panels by setting related attributes, such as background color, borders, etc.

Custom Styles

Borderless Style

Show CodeArrow
CopyGitHub

Nested Panels

Collapse panels can be nested to achieve multi-level content organization.

Nested Collapse Panels

Tip: By nesting collapse panels in the content area, you can achieve multi-level content organization, suitable for complex hierarchical structure display.
Show CodeArrow
CopyGitHub

Disabled State

Setting the disabled attribute on panel items can disable specific panel items.

Partially Disabled Panels

Toggle Disable Function

You can disable specific panel items by setting the disabled attribute.

Disabled panels cannot be expanded or collapsed by clicking, but their state can be controlled programmatically.

Show CodeArrow
CopyGitHub

Custom Icons

Setting the rightIcon attribute can customize expand/collapse icons, and you can also completely customize the title area through slots.

Custom Arrow Icons

Using Slots to Customize Icons

Custom Title Content

Show CodeArrow
CopyGitHub

Collapse Component API

TCollapseGroup Attributes

AttributeDescriptionTypeAccepted ValuesDefault
modelValueCurrently active panels (two-way binding)array/string[]
accordionWhether accordion modebooleanfalse
borderWhether to show borderbooleantrue
before-changeCallback function before panel switchingfunction

TCollapse Attributes

AttributeDescriptionTypeAccepted ValuesDefault
valueUnique identifierstring/numberIndex value
titlePanel titlestring
disabledWhether disabledbooleanfalse
rightIconCustom iconstringarrow-right

Events

Event NameDescriptionCallback Parameters
changeTriggered when active panels change(activeNames: array/string)

Slots

Slot NameDescriptionScope Parameters
defaultTCollapseGroup content
titleCustom title content
iconCustom icon{ isActive: boolean }

Methods

Method NameDescriptionParameters
toggleItemToggle expand/collapse state of specified panel(value: string/number)

Style Variables

Collapse component uses the following style variables, which can be customized through SCSS variables:

Variable NameDescription
$border-color-defaultDefault border color
$bg-color-defaultDefault background color
$bg-color-hoverHover background color
$text-color-defaultDefault text color
$opacity-disabledDisabled state opacity
$font-size-defaultDefault font size

Released under the MIT License