nb-input

This is an input component for Vue.js 3+.

Loading component...

Installation

NbInput masks (input-mask) use vue-the-mask@0.11.1 as a peer dependency (versรฃo fixada pelo nb-inputs; a lib nรฃo recebe releases novas). @vlalg-nimbus/magic-debounce (e.g. NbInputSearch) remains a normal dependency of the package and does not require a separate install.

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 NbInput or nb-input.

Mode 1
<template>
  <NbInput />
</template>
Mode 2
<template>
  <nb-input />
</template>
Mode 3
<template>
  <nb-input></nb-input>
</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 inputText prop.

nameValue typeDefaultDescription
inputTextString, NumbernullDefines the initial input value. Accepts String or Number.

Other props

nameValue typeDefaultDescription
nbId (*)StringSets the id attribute to differentiate from other components
inputName (*)StringSets the name attribute for the input element
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'Alternate Text Button'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.
textColorString'#ffffff'Defines the text color. Accepts Color name and Hex
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.
themeString'light'Defines the theme. Accepts light and dark.
hasBorderRadiusBooleanfalseDefines if the input should have border-radius.
borderRadiusNumber0.5Defines border-radius.
disabledBooleanfalseDefines if the input 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.
inputTextString, NumbernullDefines the initial input value. Accepts String or Number.
inputTypeString'text'Defines the input type. Accepts text, number, email, password.
minString''Defines the minimum value. Only applies when inputType="number".
maxString''Defines the maximum value. Only applies when inputType="number".
stepString, Number''Defines the step value. Only applies when inputType="number". Accepts a number or the string "any" to allow any value.
inputMaskString, ArraynullInput mask using vue-the-mask (same library as NbCreditCard in @vlalg-nimbus/nb-payments). Only when input-type="text" (ignored for number, email, password). String (e.g. CPF ###.###.###-##) or array of patterns for variable length (e.g. phone (##) ####-#### vs (##) #####-####, or BRL with growing groups like R$ #,## โ€ฆ R$ ###.###.###,##). Emits the masked string in changed / current-value. Template: input-mask.
inputPlaceholderString''Defines the input placeholder text
inputWidthNumber200Defines the input width in pixels
inputStyleString'background'Defines the input style. Accepts background, line, border.
inputUppercaseBooleanfalseDefines if the input text should be uppercase.
inputAutocompleteString'on'Defines the autocomplete attribute. Accepts on and off.
hasTrimBooleanfalseDefines if the input value should be trimmed on blur.
showInputEyeBooleanfalseDefines if the password visibility toggle (eye icon) should be shown. Only works with inputType="password". When inputType="password", the default browser password reveal icon is automatically hidden to allow using the custom eye icon.
inputEyeIconString'๐Ÿซฃ'Defines the icon shown when password is visible.
inputEyeIconHiddenString'๐Ÿ˜Ž'Defines the icon shown when password is hidden.
inputEyeCustomIconBooleanfalseDefines if custom icons should be used via slots instead of emoji.
activeTextStyleString'normal'Defines the text style when input is active/focused. Accepts normal, italic, oblique.
sizeMediaQueryString'sm'Defines the responsive size. Accepts xs, sm, md, lg.
showMsgBooleanfalseDefines if the message should be displayed.
hasMsgBooleanfalseDefines if there is a message to show.
messageString'Default message text'Defines the message text.
hasCustomMsgBooleanfalseDefines if a custom message slot should be used.
extraContendAbsoluteBooleanfalseControls whether the auxiliary message is laid out in normal flow (false, default) or with position: absolute under the field (true). In templates: extra-contend-absolute. (Prop name keeps the Contend spelling.)
textAlignString'left'Defines the text alignment. Accepts left, center, right.
fontFamilyString"'Lato', sans-serif"Defines the font-family
fontSizeStringnull (default: 1.2em for 'sm', 1.6em for 'md', 2em for 'lg' based on sizeMediaQuery)Defines the font-size for the input. If null, uses default sizes based on sizeMediaQuery: 1.2em for 'sm', 1.6em for 'md', 2em for 'lg'. Pass a string with the font-size and the unit (e.g., "1.2em") to override.
fontWeightNumber400Defines the font-weight
fontFamilyMsgString"'Lato', sans-serif"Defines the message font-family
fontSizeMsgString'1em'Defines the message font-size
fontWeightMsgNumber400Defines the message font-weight
textMessageColorString'#f15574'Defines the message text color
lightBgColorString'#f8f8f2'Defines the background color for light theme
lightBgColorFocusString'#eaeaea'Defines the background color when focused for light theme
lightEyeBgColorString'#353734'Defines the eye icon background color for light theme
lightEyeBgColorActiveString'#272936'Defines the eye icon background color when active for light theme
lightDisabledBgColorString'#dfdfd9'Defines the disabled background color for light theme
lightTextColorString'#000000'Defines the text color for light theme
darkBgColorString'#353734'Defines the background color for dark theme
darkBgColorFocusString'#272936'Defines the background color when focused for dark theme
darkEyeBgColorString'#353734'Defines the eye icon background color for dark theme
darkEyeBgColorActiveString'#272936'Defines the eye icon background color when active for dark theme
darkDisabledBgColorString'rgba(40, 42, 54, 1)'Defines the disabled background color for dark theme
darkTextColorString'#000000'Defines the text color for dark theme
darkDisabledEyeBgColorString'rgba(68, 71, 90, 0.3)'Defines the disabled eye icon background color for dark theme
lightDisabledEyeBgColorString'rgba(53, 55, 52, 0.3)'Defines the disabled eye icon background color for light theme
hasIconBooleanfalseDefines if a custom icon should be displayed. When true, shows an icon slot on the left or right side of the input.
iconWidthNumber32Defines the icon width in pixels
iconDirectionString'left'Defines the icon position. Accepts left and right.
iconPaddingString'5px 10px'Defines the icon padding. Must be two space-separated values (e.g., "5px 10px").
iconPaddingInputNumber35Defines the input padding when icon is present. Adds padding to the side where the icon is positioned.
iconMarginString'0'Defines the icon margin
iconLightTextColorString'#f8f8f2'Defines the icon text color for light theme
iconDarkTextColorString'#f8f8f2'Defines the icon text color for dark theme
iconLightBgColorString'#353734'Defines the icon background color for light theme
iconLightBgColorActiveString'#272936'Defines the icon background color when active for light theme
iconDarkBgColorString'#353734'Defines the icon background color for dark theme
iconDarkBgColorActiveString'#272936'Defines the icon background color when active for dark theme
iconDarkDisabledBgColorString'rgba(68, 71, 90, 0.3)'Defines the disabled icon background color for dark theme
iconLightDisabledBgColorString'rgba(53, 55, 52, 0.3)'Defines the disabled icon background color for light theme
iconBorderRadiusNumber0Defines the border-radius for the icon
iconSizeNumber1Defines the icon size multiplier
showLabelBooleanfalseDefines if the label should be displayed. When true, shows a floating label that moves to the top when the input is active or has content.
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.
labelRightNumber0Defines the right position of the label when inactive in pixels.
inputLabelMarginActiveNumber15Defines the top margin of the input when the label is active in pixels. This creates space for the label above the input.
labelActiveTopNumber-13Defines the top position of the label when active in pixels. Negative values move the label above the input.
labelActiveLeftNumber5Defines the left position of the label when active in pixels.
labelActiveRightNumber0Defines the right position of the label when active in pixels.
labelBreakOnActiveBooleantrueDefines if the label text should break or use ellipsis when active
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
current-valuevalueFired when the input value changes, returns the current value.
changedvalueFired when the input value changes, returns the current value.
focusednothingFired when the input receives focus.
blurrednothingFired when the input loses focus.
show-input-eyebooleanFired when the password visibility toggle is clicked, returns the visibility state.
clickedMouseEvent | KeyboardEventFired when the input container is clicked. Receives the native DOM event as first argument.
enteredvalueFired when the Enter key is pressed, returns the current value.
pastevalueFired 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:

message

Custom message slot for displaying validation messages or other information.

<template>
  <NbInput
    nb-id="input1"
    input-name="email"
    :show-msg="true"
    :has-msg="true"
    :has-custom-msg="true"
  >
    <template #message>
      <div class="custom-error">Please enter a valid email address</div>
    </template>
  </NbInput>
</template>

eye-icon-show

Custom icon slot for when password is visible (only when inputEyeCustomIcon is true).

<template>
  <NbInput
    nb-id="input1"
    input-name="password"
    input-type="password"
    :show-input-eye="true"
    :input-eye-custom-icon="true"
  >
    <template #eye-icon-show>
      <span>๐Ÿ‘๏ธ</span>
    </template>
    <template #eye-icon-hidden>
      <span>๐Ÿ™ˆ</span>
    </template>
  </NbInput>
</template>

eye-icon-hidden

Custom icon slot for when password is hidden (only when inputEyeCustomIcon is true).

icon

Custom icon slot for displaying an icon inside the input (only when hasIcon is true).

<template>
  <NbInput
    nb-id="input1"
    input-name="search"
    :has-icon="true"
    icon-direction="left"
    icon-padding="10px 15px"
    :icon-padding-input="40"
    icon-light-bg-color="#353734"
    icon-dark-bg-color="#353734"
  >
    <template #icon>
      <span>๐Ÿ”</span>
    </template>
  </NbInput>
</template>

Input mask (input-mask)

Masking uses vue-the-mask@0.11.1 as a peer dependency โ€” install it alongside @vlalg-nimbus/nb-inputs (see Installation). The NbInput module imports this package, so your bundler must be able to resolve vue-the-mask whenever you use NbInput, not only when input-mask is set.

Rules

  • input-type must be text โ€” input-mask is ignored for number, email, and password.
  • In templates, use the kebab-case attribute input-mask, which maps to the inputMask prop.
  • changed and current-value emit the masked string (e.g. "123.456.789-00" for CPF). To send a normalized value to an API (digits only, cents, etc.), parse in your app.
  • Pass a string for a fixed pattern, or an array of strings when the mask length should change (e.g. landline vs mobile phone). Avoid Object.freeze() on arrays you pass in โ€” vue-the-mask may sort patterns in place; NbInput already passes a shallow copy of arrays to the directive, but keeping mutable arrays in your code is simpler.

Pattern tokens (vue-the-mask)

Common placeholders (see the package README for full list):

TokenMeaning
#Digit (0-9)
ALetter (uppercase transform)
aLetter (lowercase transform)
SLetter (a-z, A-Z)
XAlphanumeric
!Escape next character (literal)

Literal characters in the pattern (e.g. ., -, (, space after R$) are not special unless you use ! where the library requires it.

Examples

CPF (fixed 11 digits)

<NbInput
  nb-id="doc-cpf"
  input-name="cpf"
  input-type="text"
  input-mask="###.###.###-##"
  label="CPF"
  :show-label="true"
/>

CEP

<NbInput
  nb-id="doc-cep"
  input-name="cep"
  input-type="text"
  input-mask="#####-###"
/>

Brazilian phone (dynamic mask)

<script setup>
const phoneMasks = ['(##) ####-####', '(##) #####-####']
</script>

<template>
  <NbInput
    nb-id="doc-phone"
    input-name="phone"
    input-type="text"
    :input-mask="phoneMasks"
    label="Phone"
    :show-label="true"
  />
</template>

Currency-style display (prefix + growing groups) โ€” still a string in emits; parse before persisting:

<script setup>
const brlMasks = [
  'R$ #,##',
  'R$ ##,##',
  'R$ ###,##',
  'R$ #.###,##',
  'R$ ##.###,##',
  'R$ ###.###,##',
]
</script>

<template>
  <NbInput
    nb-id="doc-money"
    input-name="amount"
    input-type="text"
    :input-mask="brlMasks"
    label="Amount"
    :show-label="true"
  />
</template>

For the same numeric layout with another prefix (e.g. S 1.000,00), use the same group progression with a leading S instead of R$ .