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
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')
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>
Preview & Playground
Select the component you want to edit/test
Loading Sandbox...
Props
Items with an (*) mean they are required
Core
| name | Value type | Default | Description |
|---|---|---|---|
| nbId (*) | String | Sets the id attribute to differentiate from other components | |
| display | String | 'b' | Component display. Accepts 'b' (block) or 'ib' (inline-block) |
| theme | String | 'light' | Defines theme. Accepts light and dark |
| title | String | 'Open Collapsible' | Default title text shown in the header |
| opened | Boolean | false | Controls the open/closed state externally |
| disabled | Boolean | false | Disables the component |
| blockClick | Boolean | false | Blocks toggle on click when true |
| blockRightClick | Boolean | false | Prevents the browser's context menu over the component |
| tabIndex | Number | 0 | Keyboard tab index for the header |
| hasTabIndexEnter | Boolean | true | Enables toggle with Enter key |
| hasTabIndexSpace | Boolean | true | Enables toggle with Space key |
| ariaLabel | String | 'Collapse' | aria-label value for accessibility |
| ariaAttrs | Object | {} | Additional aria attributes (auto-prefixed with aria-) |
| textAlign | String | 'left' | Text alignment. Accepts left, center, right |
| activeTextStyle | String | 'normal' | Title style when active. Accepts normal, italic, oblique |
| ellipsisText | Boolean | true | Truncates the title with ellipsis when overflowing |
| isScrollClass | Boolean | false | Enables scrollClass to be applied on the content area when true |
| scrollClass | String | '' | Custom CSS class applied to the scrollable content area (only applied when isScrollClass is true) |
Title
| name | Value type | Default | Description |
|---|---|---|---|
| titleGap | Number | 0.5 | Gap (rem) between title label and trailing icon |
| titlePaddingX | Number | 0.7 | Horizontal padding (rem) of the header |
| titlePaddingY | Number | 0.7 | Vertical padding (rem) of the header |
| titleBorderRadius | String | '5px 5px 5px 5px' | Header border-radius when closed |
| titleBorderRadiusActive | String | '5px 5px 0px 0px' | Header border-radius when open |
| titleFontFamily | String | "'Lato', sans-serif" | Title font-family |
| titleFontSize | String | '1.6em' | Title font-size |
| titleFontWeight | Number | 500 | Title font-weight |
| titleIconWidth | String | '2.4rem' | Fixed width of the trailing icon area |
| titleIconFontFamily | String | "'Lato', sans-serif" | Trailing icon font-family |
| titleIconFontSize | String | '2em' | Trailing icon font-size |
| titleIconFontWeight | Number | 700 | Trailing icon font-weight |
Content
| name | Value type | Default | Description |
|---|---|---|---|
| contentPaddingX | Number | 1 | Horizontal padding (rem) of the content area |
| contentPaddingY | Number | 1 | Vertical padding (rem) of the content area |
| contentFontFamily | String | "'Lato', sans-serif" | Content font-family |
| contentFontSize | String | '1.6em' | Content font-size |
| contentFontWeight | Number | 500 | Content font-weight |
| contentBorderRadiusActive | String | '0px 0px 5px 5px' | Content border-radius when open |
| contentHasBorder | Boolean | true | Draws side and bottom borders when open |
| contentMaxHeight | Number | 200 | Maximum 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.
| name | Value type | Default | Description |
|---|---|---|---|
| lightTitleColor | String | #1f2937 | Title text color |
| lightTitleColorActive | String | #1d4ed8 | Title color when open |
| lightTitleColorHover | String | #111827 | Title color on hover |
| lightTitleIconColor | String | #6b7280 | Trailing icon color |
| lightTitleIconColorActive | String | #1d4ed8 | Trailing icon color when open |
| lightTitleIconColorHover | String | #374151 | Trailing icon color on hover |
| lightButtonBgColor | String | #f3f4f6 | Header background color |
| lightButtonBgColorActive | String | #e0e7ff | Header background color when open |
| lightButtonBgColorHover | String | #e5e7eb | Header background color on hover |
| lightContentColor | String | #1f2937 | Content text color |
| lightContentBgColor | String | #ffffff | Content background color |
| lightContentBorderColor | String | #e5e7eb | Content border color when open |
Theme Colors (Dark)
Same color roles as light, tuned for dark surfaces.
| name | Value type | Default | Description |
|---|---|---|---|
| darkTitleColor | String | #e5e7eb | Title text color |
| darkTitleColorActive | String | #60a5fa | Title color when open |
| darkTitleColorHover | String | #f9fafb | Title color on hover |
| darkTitleIconColor | String | #9ca3af | Trailing icon color |
| darkTitleIconColorActive | String | #60a5fa | Trailing icon color when open |
| darkTitleIconColorHover | String | #d1d5db | Trailing icon color on hover |
| darkButtonBgColor | String | #1f2937 | Header background color |
| darkButtonBgColorActive | String | #1e3a8a | Header background color when open |
| darkButtonBgColorHover | String | #374151 | Header background color on hover |
| darkContentColor | String | #e5e7eb | Content text color |
| darkContentBgColor | String | #111827 | Content background color |
| darkContentBorderColor | String | #374151 | Content 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.
| name | Slot props | Description |
|---|---|---|
| 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
| name | Return type | Description |
|---|---|---|
| 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-clicked | Event | Fired when the user clicks outside the component |
| resized | { event, width, height } | Fired when the viewport is resized; reports current wrapper size |
Notes
openedis a one-way input: emittingclickedand updating it from the parent gives you full control of the state.- For accessibility, use the
ariaAttrsprop to pass extras likecontrolsorexpandedwhen needed. - Use
blockRightClickto prevent the native context menu (e.g. inside a custom right-click flow). - The
*Color,*BgColorand*BorderColorprops accept any valid CSS color (hex,rgb,hsl, named, etc.).
