nb-input-chip

This is an input chip component for Vue.js 3+. It allows users to add and remove chips (tags) by typing and pressing Enter.

Loading component...

Installation

NbInputChip masks (input-mask) use the same peer dependency as NbInput: vue-the-mask@0.11.1. Tokens and behaviour are documented under Input mask (input-mask).

Yarn
yarn add @vlalg-nimbus/nb-inputs vue-the-mask@0.11.1
NPM
npm install @vlalg-nimbus/nb-inputs vue-the-mask@0.11.1

Usage

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

import NbInputComponents from '@vlalg-nimbus/nb-inputs'
import "@vlalg-nimbus/nb-inputs/dist/style.css";

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

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

To use, simply call the component, in this case it will be NbInputChip or nb-input-chip.

Mode 1
<template>
  <NbInputChip nb-id="chip1" input-name="tags" />
</template>
Mode 2
<template>
  <nb-input-chip nb-id="chip1" input-name="tags" />
</template>
Mode 3
<template>
  <nb-input-chip nb-id="chip1" input-name="tags"></nb-input-chip>
</template>

Preview & Playground

Select the component you want to edit/test

Loading Sandbox...

Props

Items with an (*) mean they are required

To set initial value, use the currentList prop.

nameValue typeDefaultDescription
currentListArrayDefines the initial list of chips. Accepts Array of strings.

Other props

nameValue typeDefaultDescription
nbId (*)StringSets the id attribute to differentiate from other components
displayString'b'Defines the display type. Accepts ib and b.
tabIndexNumber0Defines the tab index. Set this property to make the input focusable by the keyboard.
hasTabIndexEnterBooleantrueEnables the input to be activated with the Enter key when focused.
ariaLabelString'Input Chip'Defines the aria-label attribute for screen readers.
ariaAttrsObject{}Allows passing custom aria attributes as an object. Keys will automatically receive the aria- prefix. Example: { 'describedby': 'help-id', 'invalid': 'false' }
titleString''Tooltip text shown when hovering over the component.
caretColorString''Defines the caret (cursor) color. Accepts Color name and Hex. If empty, uses default browser color.
selectionBgColorString''Defines the background color of selected text. Accepts Color name and Hex. If empty, uses default browser color.
selectionTextColorString''Defines the text color of selected text. Accepts Color name and Hex. If empty, uses default browser color.
widthNumber185Defines the component width in pixels. Minimum value is 185.
textColorString'#ffffff'Defines the text color. Accepts Color name and Hex
paddingXNumber0.2Defines the horizontal padding in rem units.
paddingYNumber0.2Defines the vertical padding in rem units.
hasBorderRadiusBooleanfalseDefines if the component should have border-radius.
borderRadiusNumber0.375Defines border-radius in rem units.
disabledBooleanfalseDefines if the component is disabled
requiredBooleanfalseDefines if the input is required
inputReadonlyBooleanfalseDefines if the input is readonly
blockPasteBooleanfalseWhen set to true, prevents pasting content into the input field.
inputNameString''Sets the name attribute for the input element
inputPlaceholderString'Type and press Enter'Defines the input placeholder text
inputUppercaseBooleanfalseDefines if the input text should be uppercase.
inputAutocompleteString'on'Defines the autocomplete attribute. Accepts on and off.
inputMaskString | ArraynullOptional vue-the-mask@0.11.1 pattern for the chip text field (always type="text"). String or array of strings — same API as NbInput input-mask.
currentListArrayDefines the initial list of chips.
allowDuplicatesBooleanfalseDefines if duplicate chips are allowed.
minChipsNumber0Defines the minimum number of chips allowed.
maxChipsNumber10Defines the maximum number of chips allowed.
inputPositionString'bottom'Defines the input position. Accepts top and bottom.
textAlignString'left'Defines the text alignment. Accepts left, center, right.
activeTextStyleString'normal'Defines the text style when input is active/focused. Accepts normal, italic, oblique.
themeString'light'Defines the theme. Accepts light and dark.
inputStyleString'background'Defines the input style. Accepts background, line, border.
fontFamilyString"'Lato', sans-serif"Defines the font-family
fontSizeStringnull (default: 1.4em)Defines the font-size for the input. If null, uses 1.4em as default size. Pass a string with the font-size and the unit (e.g., "1.2em").
fontWeightNumber400Defines the font-weight
lightBgColorString'#f8f8f2'Defines the background color for light theme
lightBgColorFocusString'#eaeaea'Defines the background color when focused for light theme
lightBorderColorString'#353734'Defines the border color for light theme
lightBorderColorFocusString'#272936'Defines the border color when focused for light theme
lightDisabledBgColorString'#dfdfd9'Defines the disabled background color for light theme
lightTextColorString'#000000'Defines the text color for light theme
lightChipBgColorString'#e0e0e0'Defines the chip background color for light theme
lightChipTextColorString'#000000'Defines the chip text color for light theme
lightChipRemoveColorString'#f44336'Defines the chip remove button color for light theme
lightDisabledBorderColorString'rgba(53, 55, 52, 0.3)'Defines the disabled border color for light theme
darkBgColorString'#353734'Defines the background color for dark theme
darkBgColorFocusString'#272936'Defines the background color when focused for dark theme
darkBorderColorString'#44475a'Defines the border color for dark theme
darkBorderColorFocusString'rgba(68, 71, 90, 0.4)'Defines the border color when focused for dark theme
darkDisabledBgColorString'rgba(40, 42, 54, 1)'Defines the disabled background color for dark theme
darkTextColorString'#ffffff'Defines the text color for dark theme
darkChipBgColorString'#44475a'Defines the chip background color for dark theme
darkChipTextColorString'#ffffff'Defines the chip text color for dark theme
darkChipRemoveColorString'#f44336'Defines the chip remove button color for dark theme
darkDisabledBorderColorString'rgba(68, 71, 90, 0.3)'Defines the disabled border color for dark theme
showLabelBooleanfalseDefines if the label should be displayed. When true, shows a floating label that moves to the top when the input is active, has content, or has chips.
labelString'Label text'Defines the label text displayed above the input.
labelBackgroundString'transparent'Defines the background color of the label when active. Accepts Color name and Hex.
labelPaddingString'1px 5px'Defines the padding of the label when active. Must be space-separated values (e.g., "1px 5px").
labelBorderRadiusNumber0Defines the border-radius of the label when active in rem units.
labelLeftNumber5Defines the left position of the label when inactive in pixels.
inputLabelMarginActiveNumber15Defines the top margin of the component when the label is active in pixels. This creates space for the label above the component.
labelActiveTopNumber-13Defines the top position of the label when active in pixels. Negative values move the label above the component.
labelActiveLeftNumber5Defines the left position of the label when active in pixels.
labelBreakOnActiveBooleantrueDefines if the label text should break or use ellipsis when active
fontFamilyChipString"'Lato', sans-serif"Defines the font-family for the chips
fontSizeChipString'1.2em'Defines the font-size for the chips
fontWeightChipNumber400Defines the font-weight for the chips
fontFamilyLabelString"'Lato', sans-serif"Defines the font-family for the label
fontSizeLabelString'1em'Defines the font-size for the label when inactive
fontSizeLabelActiveString'0.8em'Defines the font-size for the label when active
fontWeightLabelNumber400Defines the font-weight for the label
lightTextColorLabelString'#333333'Defines the label text color for light theme when inactive
lightTextColorLabelActiveString'#333333'Defines the label text color for light theme when active
darkTextColorLabelString'#ffffff'Defines the label text color for dark theme when inactive
darkTextColorLabelActiveString'#ffffff'Defines the label text color for dark theme when active

Events

nameReturn typeDescription
clickedMouseEvent | KeyboardEventFired when the component container is clicked. Receives the native DOM event as first argument.
changed{ list }Fired when the chip list changes, returns an object with the current chip list (list).
removed{ chip, index, list }Fired when a chip is removed, returns an object with the removed chip value (chip), its index (index), and the updated list (list).
added{ chip, index, list }Fired when a chip is added, returns an object with the added chip value (chip), its index (index), and the updated list (list).
input-changed{ value }Fired when the input value changes, returns an object containing the current input value (value).
focusednothingFired when the input receives focus.
blurrednothingFired when the input loses focus.
pastestringFired when content is pasted into the input, returns the pasted value as a string. Always fired, even when blockPaste is true (in which case the paste action is blocked but the event is still emitted).

Slots

The component has slots for custom content:

chip

Custom chip slot for displaying custom chip content. The slot receives the following props:

  • chip: The chip value (string)
  • chips: The complete chip list (array)
  • removeChip: Function to remove the chip (function)
<template>
  <NbInputChip
    nb-id="chip1"
    input-name="tags"
  >
    <template #chip="{ chip, removeChip }">
      <span class="chip-text">{{ chip }}</span>
      <span class="chip-remove" @click="removeChip(chip)">×</span>
    </template>
  </NbInputChip>
</template>

Input mask (input-mask)

The chip text field is always type="text". Use input-mask (kebab-case) for the same vue-the-mask@0.11.1 patterns as NbInput: string for a fixed pattern, or an array when length varies. Install the peer dependency (see Installation). Full rules, tokens, and more examples: Input mask (input-mask).

Each chip stores the masked string emitted when the user confirms with Enter (e.g. CPF including dots and hyphen).

Example — CPF per chip

<template>
  <NbInputChip
    nb-id="chip-cpf"
    input-name="cpf-tags"
    input-mask="###.###.###-##"
    input-placeholder="CPF, then Enter"
    :current-list="initialCpfs"
    @added="onCpfAdded"
  />
</template>

<script setup>
import { ref } from 'vue'

const initialCpfs = ref([])

function onCpfAdded({ chip, list }) {
  console.log('New chip:', chip, 'List:', list)
}
</script>

Example — multiple patterns (landline / mobile)

<NbInputChip
  nb-id="chip-phone"
  input-name="phones"
  :input-mask="['(##) ####-####', '(##) #####-####']"
  input-placeholder="Phone, then Enter"
/>