nb-collapse

This is a collapsible component for Vue.js 3+.

This component is also the primitive used internally by NbAccordion.

Loading component...

Installation

Yarn
yarn add @vlalg-nimbus/nb-navigation
NPM
npm install @vlalg-nimbus/nb-navigation

Usage

Vue 3
import { createApp } from 'vue'
import App from './App.vue'

import NbNavigationComponents from '@vlalg-nimbus/nb-navigation'
import "@vlalg-nimbus/nb-navigation/dist/style.css";

const app = createApp(App)
app.use(NbNavigationComponents)
app.mount('#app')
Nuxt 3
import NbNavigationComponents from '@vlalg-nimbus/nb-navigation'
import "@vlalg-nimbus/nb-navigation/dist/style.css";

export default defineNuxtPlugin(context => {
  context.vueApp.use(NbNavigationComponents)
})

To use, simply call the component, in this case it will be NbCollapse or nb-collapse.

Basic
<template>
  <NbCollapse
    nb-id="collapse-1"
    title="Open Collapsible"
  >
    <template #content>
      <p>Collapsible content here.</p>
    </template>
  </NbCollapse>
</template>
Custom slots
<template>
  <NbCollapse nb-id="collapse-2" theme="dark">
    <template #title="{ title, isActive }">
      <strong :class="{ active: isActive }">{{ title }}</strong>
    </template>

    <template #title-icon="{ isActive }">
      <i :class="isActive ? 'icon-up' : 'icon-down'" />
    </template>

    <template #content>
      <p>Custom content...</p>
    </template>
  </NbCollapse>
</template>
Controlled
<template>
  <NbCollapse
    nb-id="collapse-3"
    :opened="isOpen"
    @clicked="isOpen = !isOpen"
  >
    <template #content><p>Controlled by parent.</p></template>
  </NbCollapse>
</template>

<script setup>
import { ref } from 'vue'
const isOpen = ref(false)
</script>

Preview & Playground

Select the component you want to edit/test

Loading Sandbox...

Props

Items with an (*) mean they are required

Core

nameValue typeDefaultDescription
nbId (*)StringSets the id attribute to differentiate from other components
displayString'b'Component display. Accepts 'b' (block) or 'ib' (inline-block)
themeString'light'Defines theme. Accepts light and dark
titleString'Open Collapsible'Default title text shown in the header
openedBooleanfalseControls the open/closed state externally
disabledBooleanfalseDisables the component
blockClickBooleanfalseBlocks toggle on click when true
blockRightClickBooleanfalsePrevents the browser's context menu over the component
tabIndexNumber0Keyboard tab index for the header
hasTabIndexEnterBooleantrueEnables toggle with Enter key
hasTabIndexSpaceBooleantrueEnables toggle with Space key
ariaLabelString'Collapse'aria-label value for accessibility
ariaAttrsObject{}Additional aria attributes (auto-prefixed with aria-)
textAlignString'left'Text alignment. Accepts left, center, right
activeTextStyleString'normal'Title style when active. Accepts normal, italic, oblique
ellipsisTextBooleantrueTruncates the title with ellipsis when overflowing
isScrollClassBooleanfalseEnables scrollClass to be applied on the content area when true
scrollClassString''Custom CSS class applied to the scrollable content area (only applied when isScrollClass is true)

Title

nameValue typeDefaultDescription
titleGapNumber0.5Gap (rem) between title label and trailing icon
titlePaddingXNumber0.7Horizontal padding (rem) of the header
titlePaddingYNumber0.7Vertical padding (rem) of the header
titleBorderRadiusString'5px 5px 5px 5px'Header border-radius when closed
titleBorderRadiusActiveString'5px 5px 0px 0px'Header border-radius when open
titleFontFamilyString"'Lato', sans-serif"Title font-family
titleFontSizeString'1.6em'Title font-size
titleFontWeightNumber500Title font-weight
titleIconWidthString'2.4rem'Fixed width of the trailing icon area
titleIconFontFamilyString"'Lato', sans-serif"Trailing icon font-family
titleIconFontSizeString'2em'Trailing icon font-size
titleIconFontWeightNumber700Trailing icon font-weight

Content

nameValue typeDefaultDescription
contentPaddingXNumber1Horizontal padding (rem) of the content area
contentPaddingYNumber1Vertical padding (rem) of the content area
contentFontFamilyString"'Lato', sans-serif"Content font-family
contentFontSizeString'1.6em'Content font-size
contentFontWeightNumber500Content font-weight
contentBorderRadiusActiveString'0px 0px 5px 5px'Content border-radius when open
contentHasBorderBooleantrueDraws side and bottom borders when open
contentMaxHeightNumber200Maximum height (px) of the content area. When the content exceeds it, vertical scroll is enabled automatically

Theme Colors (Light)

Default palette uses Tailwind-like neutral grays with blue as the active accent. Designed for light surfaces.

nameValue typeDefaultDescription
lightTitleColorString#1f2937Title text color
lightTitleColorActiveString#1d4ed8Title color when open
lightTitleColorHoverString#111827Title color on hover
lightTitleIconColorString#6b7280Trailing icon color
lightTitleIconColorActiveString#1d4ed8Trailing icon color when open
lightTitleIconColorHoverString#374151Trailing icon color on hover
lightButtonBgColorString#f3f4f6Header background color
lightButtonBgColorActiveString#e0e7ffHeader background color when open
lightButtonBgColorHoverString#e5e7ebHeader background color on hover
lightContentColorString#1f2937Content text color
lightContentBgColorString#ffffffContent background color
lightContentBorderColorString#e5e7ebContent border color when open

Theme Colors (Dark)

Same color roles as light, tuned for dark surfaces.

nameValue typeDefaultDescription
darkTitleColorString#e5e7ebTitle text color
darkTitleColorActiveString#60a5faTitle color when open
darkTitleColorHoverString#f9fafbTitle color on hover
darkTitleIconColorString#9ca3afTrailing icon color
darkTitleIconColorActiveString#60a5faTrailing icon color when open
darkTitleIconColorHoverString#d1d5dbTrailing icon color on hover
darkButtonBgColorString#1f2937Header background color
darkButtonBgColorActiveString#1e3a8aHeader background color when open
darkButtonBgColorHoverString#374151Header background color on hover
darkContentColorString#e5e7ebContent text color
darkContentBgColorString#111827Content background color
darkContentBorderColorString#374151Content border color when open

Slots

All slots receive title, is-active and disabled as slot props so the consumer can adapt the rendering based on the current state.

nameSlot propsDescription
title{ title, isActive, disabled }Title content. Defaults to title prop value
title-icon{ title, isActive, disabled }Trailing icon. Defaults to + when closed and โˆ’ when open
content{ title, isActive, disabled }Body content shown when the component is open

Events

nameReturn typeDescription
clickedโ€”Fired when the header is clicked or activated by Enter/Space
focusedโ€”Fired when the header receives focus
blurredโ€”Fired when the header loses focus
outside-clickedEventFired when the user clicks outside the component
resized{ event, width, height }Fired when the viewport is resized; reports current wrapper size

Notes

  • opened is a one-way input: emitting clicked and updating it from the parent gives you full control of the state.
  • For accessibility, use the ariaAttrs prop to pass extras like controls or expanded when needed.
  • Use blockRightClick to prevent the native context menu (e.g. inside a custom right-click flow).
  • The *Color, *BgColor and *BorderColor props accept any valid CSS color (hex, rgb, hsl, named, etc.).