nb-segmented-button
This is a Segmented control component for Vue.js 3+.
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')
Use the component as NbSegmentedButton or nb-segmented-button.
Basic
<template>
<NbSegmentedButton
nb-id="segmented-1"
:options="['Browser', 'Network', 'Security']"
:selected="1"
/>
</template>
Preview & Playground
Select the component you want to edit/test
Loading Sandbox...
Props
Items with an (*) are required
| name | Value type | Default | Description |
|---|---|---|---|
| nbId (*) | String | id of the root segment container | |
| options | Array | [] | List of option labels (strings) |
| selected | Number | 0 | Active option index (0-based) |
| display | String | 'b' | Wrapper display: b (block) or ib (inline-block) |
| disabled | Boolean | false | Disables the whole control |
| theme | String | 'light' | Theme: light or dark |
| tabIndex | Number | 0 | tabindex for the bar and each segment (when keyboard is enabled) |
| hasTabIndexEnter | Boolean | true | Allow activating a segment with Enter (when not disabled) |
| hasTabIndexSpace | Boolean | true | Allow activating a segment with Space (when not disabled) |
| ariaLabel | String | 'Segmented Button' | aria-label on the control |
| ariaAttrs | Object | {} | Extra ARIA fields (keys are auto-prefixed with aria-) |
| gap | Number | 0.5 | Horizontal gap between segments (rem) |
| padding | Number | 0.25 | Inner padding of the bar (rem) |
| hasBorderRadius | Boolean | false | Rounds the outer bar |
| borderRadius | Number | 0.375 | Bar corner radius (rem) when hasBorderRadius is true |
| fontFamily | String | 'Lato', sans-serif | Font family |
| fontSize | String | '1.6em' | Font size |
| fontWeight | Number | 400 | Base font weight |
| fontStrongActive | Boolean | true | Bolder label on the active segment when true |
| hasScroll | Boolean | false | Horizontal overflow: enables native horizontal scroll and mouse drag-to-scroll (same idea as NbTabs with isScrollClass) |
| isScrollClass | Boolean | false | Applies scrollClass to the bar (e.g. custom scrollbar styling) |
| scrollClass | String | '' | CSS class name used when isScrollClass is true |
| hasSelectedAnimation | Boolean | false | Sliding “pill” indicator behind the active segment (position follows layout and scroll) |
| hasSelectedBorderRadius | Boolean | false | Rounds the active pill / segment corners |
| selectedBorderRadius | Number | 0.375 | Corner radius (rem) when hasSelectedBorderRadius is true |
| optionsPaddingX | Number | 0.25 | Horizontal padding inside each segment (rem) |
| optionsPaddingY | Number | 0.7 | Vertical padding inside each segment (rem) |
| optionsOpacityDisabled | Number | 0.3 | Opacity for disabled options |
| opacityDisabled | Number | 0.4 | Opacity when the whole control is disabled |
| selectedsDisabled | Array | [] | Disabled segment indexes (numbers) |
Theme colors (light)
| name | Value type | Default | Description |
|---|---|---|---|
| lightBackground | String | #f8f8f2 | Track / bar background (igual lightBgColor do NbInput) |
| lightBackgroundFocus | String | #eaeaea | Segmento ativo / pill (#eaeaea, igual lightBgColorFocus do NbInput) |
| lightColor | String | #333333 | Cor do texto inativo (alinhado a lightTextColorLabel) |
| lightColorFocus | String | #000000 | Cor do texto ativo (alinhado a lightTextColor) |
Theme colors (dark)
| name | Value type | Default | Description |
|---|---|---|---|
| darkBackground | String | #353734 | Track / bar background (base igual darkBgColor do NbInput) |
| darkBackgroundFocus | String | #5f5f5f | Segmento ativo / pill — cinza médio, mais claro que a trilha (#353734) |
| darkColor | String | #c8c8c8 | Texto dos segmentos inativos (contraste suave) |
| darkColorFocus | String | #ffffff | Texto 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.
| name | Scope | Description |
|---|---|---|
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
| name | Payload | Description |
|---|---|---|
| clicked | { index: Number, value: String } | Fired when the user selects another enabled segment (index in options, value is the label string) |
Notes
optionsmust be an array of strings; each entry is rendered as one segment (default) or replaced per index viaoption-{index}slots.- Use
v-model-style updates from the parent: pass:selectedand 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/resizekeep it aligned when the layout changes. - The current styles target the filled / background look. Register globally with the
nb-navigationplugin, or importNbSegmentedButtonfrom@vlalg-nimbus/nb-navigationif your build re-exports the package components.
