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). Custom tokens (input-mask-tokens) are the same as on NbInput — see Custom mask tokens (input-mask-tokens).
yarn add @vlalg-nimbus/nb-inputs vue-the-mask@0.11.1
Usage
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')
To use, simply call the component, in this case it will be NbInputChip or nb-input-chip.
<template>
<NbInputChip nb-id="chip1" input-name="tags" />
</template>
Preview & Playground
Select the component you want to edit/test
Props
Items with an (*) mean they are required
To set initial value, use the currentList prop.
| name | Value type | Default | Description |
|---|---|---|---|
| currentList | Array | Defines the initial list of chips. Accepts Array of strings. |
Other props
| name | Value type | Default | Description |
|---|---|---|---|
| nbId (*) | String | Sets the id attribute to differentiate from other components | |
| display | String | 'b' | Defines the display type. Accepts ib and b. |
| tabIndex | Number | 0 | Defines the tab index. Set this property to make the input focusable by the keyboard. |
| hasTabIndexEnter | Boolean | true | Enables the input to be activated with the Enter key when focused. |
| ariaLabel | String | 'Input Chip' | Defines the aria-label attribute for screen readers. |
| ariaAttrs | Object | {} | Allows passing custom aria attributes as an object. Keys will automatically receive the aria- prefix. Example: { 'describedby': 'help-id', 'invalid': 'false' } |
| title | String | '' | Tooltip text shown when hovering over the component. |
| caretColor | String | '' | Defines the caret (cursor) color. Accepts Color name and Hex. If empty, uses default browser color. |
| selectionBgColor | String | '' | Defines the background color of selected text. Accepts Color name and Hex. If empty, uses default browser color. |
| selectionTextColor | String | '' | Defines the text color of selected text. Accepts Color name and Hex. If empty, uses default browser color. |
| width | Number | 185 | Defines the component width in pixels. Minimum value is 185. |
| textColor | String | '#ffffff' | Defines the text color. Accepts Color name and Hex |
| paddingX | Number | 0.2 | Defines the horizontal padding in rem units. |
| paddingY | Number | 0.2 | Defines the vertical padding in rem units. |
| hasBorderRadius | Boolean | false | Defines if the component should have border-radius. |
| borderRadius | Number | 0.375 | Defines border-radius in rem units. |
| disabled | Boolean | false | Defines if the component is disabled |
| required | Boolean | false | Defines if the input is required |
| inputReadonly | Boolean | false | Defines if the input is readonly |
| blockPaste | Boolean | false | When set to true, prevents pasting content into the input field. |
| inputName | String | '' | Sets the name attribute for the input element |
| inputPlaceholder | String | 'Type and press Enter' | Defines the input placeholder text |
| inputUppercase | Boolean | false | Defines if the input text should be uppercase. |
| inputAutocomplete | String | 'on' | Defines the autocomplete attribute. Accepts on and off. |
| inputMask | String | Array | null | Optional 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. |
| inputMaskEmit | String | 'masked' | Only when input-mask is set. Same modes as NbInput: applies to input-changed, added, and removed (chip / list). added-complete / removed-complete always use { masked, clean }. |
| inputMaskTokens | Object | null | Only when input-mask is set. Same merge rules and semantics as NbInput input-mask-tokens. Template: input-mask-tokens. |
| currentList | Array | Defines the initial list of chips. | |
| allowDuplicates | Boolean | false | Defines if duplicate chips are allowed. |
| minChips | Number | 0 | Defines the minimum number of chips allowed. |
| maxChips | Number | 10 | Defines the maximum number of chips allowed. |
| inputPosition | String | 'bottom' | Defines the input position. Accepts top and bottom. |
| textAlign | String | 'left' | Defines the text alignment. Accepts left, center, right. |
| activeTextStyle | String | 'normal' | Defines the text style when input is active/focused. Accepts normal, italic, oblique. |
| theme | String | 'light' | Defines the theme. Accepts light and dark. |
| inputStyle | String | 'background' | Defines the input style. Accepts background, line, border. |
| fontFamily | String | "'Lato', sans-serif" | Defines the font-family |
| fontSize | String | null (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"). |
| fontWeight | Number | 400 | Defines the font-weight |
| lightBgColor | String | '#f8f8f2' | Defines the background color for light theme |
| lightBgColorFocus | String | '#eaeaea' | Defines the background color when focused for light theme |
| lightBorderColor | String | '#353734' | Defines the border color for light theme |
| lightBorderColorFocus | String | '#272936' | Defines the border color when focused for light theme |
| lightDisabledBgColor | String | '#dfdfd9' | Defines the disabled background color for light theme |
| lightTextColor | String | '#000000' | Defines the text color for light theme |
| lightChipBgColor | String | '#e0e0e0' | Defines the chip background color for light theme |
| lightChipTextColor | String | '#000000' | Defines the chip text color for light theme |
| lightChipRemoveColor | String | '#f44336' | Defines the chip remove button color for light theme |
| lightDisabledBorderColor | String | 'rgba(53, 55, 52, 0.3)' | Defines the disabled border color for light theme |
| darkBgColor | String | '#353734' | Defines the background color for dark theme |
| darkBgColorFocus | String | '#272936' | Defines the background color when focused for dark theme |
| darkBorderColor | String | '#44475a' | Defines the border color for dark theme |
| darkBorderColorFocus | String | 'rgba(68, 71, 90, 0.4)' | Defines the border color when focused for dark theme |
| darkDisabledBgColor | String | 'rgba(40, 42, 54, 1)' | Defines the disabled background color for dark theme |
| darkTextColor | String | '#ffffff' | Defines the text color for dark theme |
| darkChipBgColor | String | '#44475a' | Defines the chip background color for dark theme |
| darkChipTextColor | String | '#ffffff' | Defines the chip text color for dark theme |
| darkChipRemoveColor | String | '#f44336' | Defines the chip remove button color for dark theme |
| darkDisabledBorderColor | String | 'rgba(68, 71, 90, 0.3)' | Defines the disabled border color for dark theme |
| showLabel | Boolean | false | Defines 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. |
| label | String | 'Label text' | Defines the label text displayed above the input. |
| labelBackground | String | 'transparent' | Defines the background color of the label when active. Accepts Color name and Hex. |
| labelPadding | String | '1px 5px' | Defines the padding of the label when active. Must be space-separated values (e.g., "1px 5px"). |
| labelBorderRadius | Number | 0 | Defines the border-radius of the label when active in rem units. |
| labelLeft | Number | 5 | Defines the left position of the label when inactive in pixels. |
| inputLabelMarginActive | Number | 15 | Defines the top margin of the component when the label is active in pixels. This creates space for the label above the component. |
| labelActiveTop | Number | -13 | Defines the top position of the label when active in pixels. Negative values move the label above the component. |
| labelActiveLeft | Number | 5 | Defines the left position of the label when active in pixels. |
| labelBreakOnActive | Boolean | true | Defines if the label text should break or use ellipsis when active |
| fontFamilyChip | String | "'Lato', sans-serif" | Defines the font-family for the chips |
| fontSizeChip | String | '1.2em' | Defines the font-size for the chips |
| fontWeightChip | Number | 400 | Defines the font-weight for the chips |
| fontFamilyLabel | String | "'Lato', sans-serif" | Defines the font-family for the label |
| fontSizeLabel | String | '1em' | Defines the font-size for the label when inactive |
| fontSizeLabelActive | String | '0.8em' | Defines the font-size for the label when active |
| fontWeightLabel | Number | 400 | Defines the font-weight for the label |
| lightTextColorLabel | String | '#333333' | Defines the label text color for light theme when inactive |
| lightTextColorLabelActive | String | '#333333' | Defines the label text color for light theme when active |
| darkTextColorLabel | String | '#ffffff' | Defines the label text color for dark theme when inactive |
| darkTextColorLabelActive | String | '#ffffff' | Defines the label text color for dark theme when active |
Events
| name | Return type | Description |
|---|---|---|
| clicked | MouseEvent | KeyboardEvent | Fired 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). |
| added | { chip, index, list } | Fired when a chip is added. With input-mask, shape follows input-mask-emit: masked — string with mask; clean — token-only string; both — { masked, clean } per chip / list item. Without mask, plain strings. |
| added-complete | { chip, index, list } | Same timing as added; chip and each list item are always { masked, clean }. Use list.map(p => p.masked) to sync current-list for display. |
| removed | { chip, index, list } | Fired when a chip is removed. Same shape rules as added (including input-mask-emit). index is the chip position before removal (stable with allow-duplicates: removal is by index, not by value). |
| removed-complete | { chip, index, list } | Same timing as removed; payload shape matches added-complete. |
| input-changed | { value } | Fired when the input value changes. Shape depends on input-mask and input-mask-emit (same options as NbInput). |
| focused | nothing | Fired when the input receives focus. |
| blurred | nothing | Fired when the input loses focus. |
| paste | string | Fired 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). |
| mask-error | { reason, masked, clean, requiredTokenCount, filledTokenCount, activePattern } | Only with input-mask. Fired when the user presses Enter with a non-empty value that does not fill every mask token slot (chip is not added). reason is 'incomplete'. masked is the trimmed field value; clean comes from vue-the-mask (masker with masked: false). requiredTokenCount / filledTokenCount count token placeholders (#, X, …). activePattern is the pattern string used for that value (for an array mask, the one chosen by the same rules as vue-the-mask dynamic masks). |
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)index: Position of this chip in the list (number) — use withremoveChipso duplicates (allow-duplicates) remove only the clicked itemchips: The complete chip list (array)removeChip:(index: number) => void— removes the chip at that index
<template>
<NbInputChip
nb-id="chip1"
input-name="tags"
>
<template #chip="{ chip, index, removeChip }">
<span class="chip-text">{{ chip }}</span>
<span class="chip-remove" @click="removeChip(index)">×</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).
Chips in the UI store the masked string when the user confirms with Enter. added / removed use the same input-mask-emit rules as NbInput for chip and list (masked, clean, or both). added-complete / removed-complete always use { masked, clean } per chip — sync current-list from *-complete.list mapped to .masked when the parent drives the list.
input-mask-tokens (prop inputMaskTokens) is supported on NbInputChip as well: use it when you need custom vue-the-mask tokens (merged with the library defaults). Full explanation, merge rules, and the signed-integer example pattern are in NbInput — Custom mask tokens (input-mask-tokens).
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"
@added-complete="onCpfAddedComplete"
/>
</template>
<script setup>
import { ref } from 'vue'
const initialCpfs = ref([])
function onCpfAdded({ chip, list }) {
console.log('API (no mask):', chip, list)
}
function onCpfAddedComplete({ list }) {
initialCpfs.value = list.map(p => p.masked)
}
</script>
Example — multiple patterns (landline / mobile)
<NbInputChip
nb-id="chip-phone"
input-name="phones"
:input-mask="['(##) ####-####', '(##) #####-####']"
input-placeholder="Phone, then Enter"
/>
Example — signed integer per chip (custom token)
Same token definition as NbInput: mask N### with N = minus or digit, then three digits.
<script setup>
const signedIntMaskTokens = {
N: { pattern: /[-0-9]/ },
}
</script>
<template>
<NbInputChip
nb-id="chip-signed-int"
input-name="signed-ints"
input-mask="N###"
:input-mask-tokens="signedIntMaskTokens"
input-placeholder="-42 then Enter"
/>
</template>
