Expandable

A group of collapsible items with shared styling and customizable content.

Install

Run the following command to install the expandable component:

npx acc-nuxt add Expandable

Basic

Pass an items array to render a group. Each item contains trigger text and content.

Group and Item Slots

Pass items to render a group with one border and dividers. Multiple answers can be open together; v-model is an array of booleans in item order.

Each item renders its trigger and content text by default. A numbered trigger or content slot replaces that text for the corresponding item. For example, trigger-1 and content-1 replace the first item's trigger and answer. Slots receive item, index (zero-based), and isExpanded.

This replaces the first item's content.

The wrapper provides default group styling. The documented CSS variables are available for optional customization.

For one expandable, pass an array with one item. Use trigger-1 and content-1 to supply its markup through slots.

Default Open

Install the component and pass your items.

Without Icon

Disable Trigger

As div

Persistent State (via useCookie)

Store the boolean array in a cookie to remember the group state across page reloads.

Install the component and pass your items.

Expand/Collapse All

Set every entry in the group model to true to expand all answers, or false to collapse them all.

Custom Icon Example

Use icon-1 to replace only the first item's icon. Other items keep the default chevron. The slot receives isExpanded for state-dependent icons.

To use the same custom icon for every item, generate a numbered icon slot for each entry with v-for. Each slot uses its own isExpanded state to rotate the icon.

Props

items:readonly AccExpandableItem[]
Items with optional trigger and content text. Include an empty object when both are supplied through numbered slots. Shared props apply to every item.
hideIcon:boolean— optional
default:false
Hides the default icon slot rendering when true.
disableTrigger:boolean— optional
default:false
Disables the trigger element, making the expandable only toggleable via v-model.
isDiv:boolean— optional
default:false
Renders the expandable as a div instead of a button.

Bindings

v-model:boolean[]
A boolean array in item order, such as [true, false]. Omit v-model to use internal state. State follows item positions when reordered.

Emits

@update:modelValue
Emitted when the expanded state changes.

Slots

The expandable component provides the following slots for customization.

#trigger-1, trigger-2, ...="{ item, index, isExpanded }"
Replaces the corresponding item trigger text. Slot numbers start at 1; index is zero-based.
#content-1, content-2, ...="{ item, index, isExpanded }"
Replaces the corresponding item content text.
#icon-1, icon-2, ...="{ item, index, isExpanded }"
Replaces the corresponding default chevron. Use v-for to generate numbered slots for the same icon on all items. Hidden when hideIcon is true.

CSS Variables

The expandable component can be customized using the following CSS variables.

--lev-expandable-divider
default:1px solid #c3c6c7
Border separating group items. Set to none to remove dividers.
--lev-expandable-border-radius
default:4px
Border radius of the expandable container.
--lev-expandable-border
default:1px solid #c3c6c7
Border style of the expandable container.
--lev-expandable-width
default:100%
Width of the expandable container.
--lev-expandable-trigger-display
default:flex
Display property of the trigger element.
--lev-expandable-trigger-gap
default:16px
Gap between trigger content elements. This is only relevant when more than 2 elements are present in the trigger slot
--lev-expandable-trigger-padding
default:16px
Padding inside the trigger element.
--lev-expandable-trigger-justify-content
default:space-between
Justify content property of the trigger element.
--lev-expandable-trigger-align-items
default:center
Align items property of the trigger element.
--lev-expandable-trigger-cursor
default:pointer
Cursor style when hovering over the trigger.
--lev-expandable-trigger-width
default:100%
Width of the trigger element.
--lev-expandable-trigger-transition
default:background-color 100ms ease-out
Transition effect for the trigger element.
--lev-expandable-trigger-border-radius
default:0px
Border radius of the trigger element.
--lev-expandable-trigger-bg
default:#fff
Background color of the trigger element (default/collapsed state).
--lev-expandable-trigger-hover-bg
default:#f7f9fa
Background color of the trigger on hover.
--lev-expandable-trigger-expanded-bg
default:#f7f9fa
Background color of the trigger when expanded.
--lev-expandable-trigger-text-gap
default:12px
Gap between elements within the trigger slot content.
--lev-expandable-content-overflow
default:hidden
Overflow property of the content container.
--lev-expandable-content-width
default:100%
Width of the content container.
--lev-expandable-inner-padding
default:16px
Padding inside the expandable content area.
--lev-expandable-inner-bg
default:#ffffff
Background color of the expandable content area.
--lev-expandable-transition-enter
default:height 0.2s ease-out
Transition effect when expanding.
--lev-expandable-transition-leave
default:height 0.15s ease-out
Transition effect when collapsing.
--lev-expandable-icon-color
default:#858787
Color of the expand/collapse icon.
--lev-expandable-icon-transition
default:transform 0.2s ease
Transition effect for the icon rotation.
--lev-expandable-icon-rotate
default:180deg
Rotation angle of the icon when expanded.