nb-segmented-button

This is a Segmented control component for Vue.js 3+.

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)
})

Use the component as NbSegmentedButton or nb-segmented-button.

Basic
<template>
  <NbSegmentedButton
    nb-id="segmented-1"
    :options="['Browser', 'Network', 'Security']"
    :selected="1"
  />
</template>
With animation & scroll
<template>
  <NbSegmentedButton
    nb-id="segmented-2"
    :options="['A', 'B', 'C', 'D']"
    :selected="0"
    has-scroll
    has-selected-animation
    theme="light"
  />
</template>
Custom segment content (slots)
<template>
  <NbSegmentedButton
    nb-id="segmented-3"
    :options="['Alpha', 'Beta', 'Gamma']"
    :selected="0"
  >
    <template #option-0="{ option }">
      <span class="emoji">🔍 {{ option }}</span>
    </template>
    <template #option-1="{ option, index }">
      {{ index }} — {{ option }}
    </template>
  </NbSegmentedButton>
</template>

Preview & Playground

Select the component you want to edit/test

Loading Sandbox...

Props

Items with an (*) are required

nameValue typeDefaultDescription
nbId (*)Stringid of the root segment container
optionsArray[]List of option labels (strings)
selectedNumber0Active option index (0-based)
displayString'b'Wrapper display: b (block) or ib (inline-block)
disabledBooleanfalseDisables the whole control
themeString'light'Theme: light or dark
tabIndexNumber0tabindex for the bar and each segment (when keyboard is enabled)
hasTabIndexEnterBooleantrueAllow activating a segment with Enter (when not disabled)
hasTabIndexSpaceBooleantrueAllow activating a segment with Space (when not disabled)
ariaLabelString'Segmented Button'aria-label on the control
ariaAttrsObject{}Extra ARIA fields (keys are auto-prefixed with aria-)
gapNumber0.5Horizontal gap between segments (rem)
paddingNumber0.25Inner padding of the bar (rem)
hasBorderRadiusBooleanfalseRounds the outer bar
borderRadiusNumber0.375Bar corner radius (rem) when hasBorderRadius is true
fontFamilyString'Lato', sans-serifFont family
fontSizeString'1.6em'Font size
fontWeightNumber400Base font weight
fontStrongActiveBooleantrueBolder label on the active segment when true
hasScrollBooleanfalseHorizontal overflow: enables native horizontal scroll and mouse drag-to-scroll (same idea as NbTabs with isScrollClass)
isScrollClassBooleanfalseApplies scrollClass to the bar (e.g. custom scrollbar styling)
scrollClassString''CSS class name used when isScrollClass is true
hasSelectedAnimationBooleanfalseSliding “pill” indicator behind the active segment (position follows layout and scroll)
hasSelectedBorderRadiusBooleanfalseRounds the active pill / segment corners
selectedBorderRadiusNumber0.375Corner radius (rem) when hasSelectedBorderRadius is true
optionsPaddingXNumber0.25Horizontal padding inside each segment (rem)
optionsPaddingYNumber0.7Vertical padding inside each segment (rem)
optionsOpacityDisabledNumber0.3Opacity for disabled options
opacityDisabledNumber0.4Opacity when the whole control is disabled
selectedsDisabledArray[]Disabled segment indexes (numbers)

Theme colors (light)

nameValue typeDefaultDescription
lightBackgroundString#f8f8f2Track / bar background (igual lightBgColor do NbInput)
lightBackgroundFocusString#eaeaeaSegmento ativo / pill (#eaeaea, igual lightBgColorFocus do NbInput)
lightColorString#333333Cor do texto inativo (alinhado a lightTextColorLabel)
lightColorFocusString#000000Cor do texto ativo (alinhado a lightTextColor)

Theme colors (dark)

nameValue typeDefaultDescription
darkBackgroundString#353734Track / bar background (base igual darkBgColor do NbInput)
darkBackgroundFocusString#5f5f5fSegmento ativo / pill — cinza médio, mais claro que a trilha (#353734)
darkColorString#c8c8c8Texto dos segmentos inativos (contraste suave)
darkColorFocusString#ffffffTexto do segmento ativo

Slots

Named slots follow the pattern option-{index} (0-based), one slot name per segment — for example option-0, option-1, option-2.

nameScopeDescription
option-{index}{ option, index, options }option — label string for that segment; index — segment index; options — full array of labels (currentOptions). If the slot is omitted for an index, the default content is the plain label ({{ option }}).

Events

namePayloadDescription
clicked{ index: Number, value: String }Fired when the user selects another enabled segment (index in options, value is the label string)

Notes

  • options must be an array of strings; each entry is rendered as one segment (default) or replaced per index via option-{index} slots.
  • Use v-model-style updates from the parent: pass :selected and listen to @clicked (or watch your own state) to update the bound index.
  • With hasScroll, segments stay on one row (nowrap); narrow viewports scroll horizontally. Dragging with the mouse pans the scroll position; clicks after a drag beyond a small threshold are ignored so you do not accidentally change selection while scrolling.
  • With hasSelectedAnimation, the highlight is a separate layer; ResizeObserver / resize keep it aligned when the layout changes.
  • The current styles target the filled / background look. Register globally with the nb-navigation plugin, or import NbSegmentedButton from @vlalg-nimbus/nb-navigation if your build re-exports the package components.