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

Yarn
yarn add @vlalg-nimbus/nb-inputs
NPM
npm install @vlalg-nimbus/nb-inputs

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

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' }
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
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.
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
fontSizeString'1.6em'Defines the font-size
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

Events

nameReturn typeDescription
clickednothingFired when the component container is clicked.
changedarrayFired when the chip list changes, returns the current chip list.
removedstringFired when a chip is removed, returns the removed chip value.
addedstringFired when a chip is added, returns the added chip value.
input-changedstringFired when the input value changes, returns the current input value.
focusednothingFired when the input receives focus.
blurrednothingFired when the input loses focus.

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>