Skip to content

Accordion

👑Pioneer

TuiAccordion is an interactive content display component. Unlike traditional vertical folding panels, it typically exists in the form of horizontal or vertical slides. By default, it displays a group of collapsed tabs; hovering (or clicking) expands the current item while collapsing others, making it ideal for displaying side-by-side graphic information or galleries.

Basic Usage

Default Mode

The most basic usage, suitable for displaying text or custom DOM content.

  • direction: Defaults to h (horizontal).
  • itemMinSize: Sets the width of items in their collapsed state (in pixels).
html
<script setup>
const items = [
  { title: 'Workbench', icon: 'tui-icon ti-star', type: 'primary' },
  { title: 'Messages', icon: 'tui-icon ti-message', type: 'success' },
  { title: 'Settings', icon: 'tui-icon ti-settings', type: 'warning' }
];
</script>

<template>
  <TuiAccordion :height="300">
    <TuiAccordionItem 
      v-for="(item, index) in items" 
      :key="index"
      :index="index"
      :title="item.title"
      :icon="item.icon"
      :type="item.type"
    >
      <div class="content">
        Detailed content area after expansion...
      </div>
    </TuiAccordionItem>
  </TuiAccordion>
</template>

Setting contentType="image" enables a dedicated image display mode. In this mode, the component automatically optimizes the layout, rendering the image attribute as a background and using an overlay to display the title and description.

html
<template>
  <TuiAccordion contentType="image" :height="400">
    <TuiAccordionItem 
      v-for="(img, index) in images" 
      :key="index"
      :index="index"
      :image="img.src"
      :title="img.title"
      description="Detailed description text for the image..."
      :hasLinkButton="true"
      @navigateTo="handleViewDetail(index)"
    />
  </TuiAccordion>
</template>

Direction and Layout

Vertical Accordion

Set direction="v" to switch to a vertical layout.

Note: In vertical mode, itemMinSize controls the height of the collapsed state.

html
<TuiAccordion direction="v" :height="500">
</TuiAccordion>

Visual and Color Customization

TuiAccordion deeply integrates the TuiTyped component, providing powerful color management capabilities.

Semantic Colors

By setting the type attribute directly on the TuiAccordionItem (primary, success, danger, etc.), the component will automatically apply the corresponding theme color bar or background.

Custom Colors (TypeColor)

If preset semantic colors do not meet requirements, any CSS color value can be passed through the typeColor attribute.

html
<TuiAccordionItem 
  :index="0" 
  title="Custom Purple" 
  typeColor="#722ed1" 
/>

Global Appearance Configuration (TypedConfig)

The typedConfig attribute allows unified control over the appearance of internal color bars (e.g., using the line style or background style).

html
<template>
  <TuiAccordion 
    :typedConfig="{ appearance: 'line', tone: 'base' }"
  >
    ...
  </TuiAccordion>
</template>

Interaction Configuration

  • trigger: Trigger method; defaults to 'hover', can be changed to 'click'.
  • autoplay: Whether to enable automatic carousel.
  • interval: Automatic carousel interval in milliseconds.
  • pauseOnHover: Whether to pause the carousel when the mouse hovers over the content area.
  • motionBlur: Whether to enable motion blur effects during switching (to enhance the sense of speed).
html
<TuiAccordion 
  trigger="click" 
  autoplay 
  :interval="5000" 
  :motionBlur="false"
>
  ...
</TuiAccordion>

API Reference

TuiAccordion Props

PropertyTypeDefaultDescription
directionString'h'Layout direction. Options: h (horizontal), v (vertical).
contentTypeString'default'Content rendering mode. Options: default, image.
heightNumber/String-Container height.
widthNumber/String-Container width.
itemMinSizeNumber40Collapsed item width/height (px).
initialIndexNumber0Initial expanded index.
autoplayBooleantrueWhether to auto-play.
intervalNumber3000Auto-play interval (ms).
triggerString'hover'Expansion trigger method. Options: hover, click.
motionBlurBooleantrueWhether to enable motion blur.
activeShowTitleBooleantrueWhether the expanded item retains the title bar.
typedConfigObject-Configuration passed to internal TuiTyped (e.g., appearance, tone).
resizeObserverString'global'Size monitoring strategy.

TuiAccordionItem Props

PropertyTypeDefaultDescription
indexNumberRequiredRequired. Index of the current item.
titleString-Title text.
descriptionString-Description text.
iconString-Icon class name.
imageString-Image URL (only valid when contentType="image").
typeString'default'Semantic color type. Options: primary, success, warning, danger, etc.
typeColorString-Custom color value (overrides type).
hasLinkButtonBooleanfalseWhether to show a navigation button.

TuiAccordionItem Events

Event NameDescriptionCallback Parameters
navigateToTriggered when the navigation button is clicked.-

Released under the MIT License.