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 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 NbInput or nb-input.
<template>
<NbInput />
</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 inputText prop.
| name | Value type | Default | Description |
|---|---|---|---|
| inputText | String, Number | null | Defines the initial input value. Accepts String or Number. |
Other props
| name | Value type | Default | Description |
|---|---|---|---|
| nbId (*) | String | Sets the id attribute to differentiate from other components | |
| inputName (*) | String | Sets the name attribute for the input element | |
| 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 | 'Alternate Text Button' | 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. |
| textColor | String | '#ffffff' | Defines the text color. Accepts Color name and Hex |
| 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. |
| theme | String | 'light' | Defines the theme. Accepts light and dark. |
| hasBorderRadius | Boolean | false | Defines if the input should have border-radius. |
| borderRadius | Number | 0.5 | Defines border-radius. |
| disabled | Boolean | false | Defines if the input 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. |
| inputText | String, Number | null | Defines the initial input value. Accepts String or Number. |
| inputType | String | 'text' | Defines the input type. Accepts text, number, email, password. |
| min | String | '' | Defines the minimum value. Only applies when inputType="number". |
| max | String | '' | Defines the maximum value. Only applies when inputType="number". |
| step | String, Number | '' | Defines the step value. Only applies when inputType="number". Accepts a number or the string "any" to allow any value. |
| inputMask | String, Array | null | Input 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$ ###.###.###,##). Template: input-mask. |
| inputMaskEmit | String | 'masked' | Only when input-mask is set (input-type="text"). Controls the payload of changed, current-value, and entered: masked — masked string; clean — token-only string; both — { masked, clean }. Template: input-mask-emit. |
| inputMaskTokens | Object | null | Only when input-mask is set (input-type="text"). Optional extra vue-the-mask tokens merged (shallow) over the library defaults. When the object has at least one key, the directive receives { mask, tokens } so behaviour matches input-mask-emit (clean / both) and mask-error. Template: input-mask-tokens. See Custom mask tokens (input-mask-tokens). |
| inputPlaceholder | String | '' | Defines the input placeholder text |
| inputWidth | Number | 200 | Defines the input width in pixels |
| inputStyle | String | 'background' | Defines the input style. Accepts background, line, border. |
| inputUppercase | Boolean | false | Defines if the input text should be uppercase. |
| inputAutocomplete | String | 'on' | Defines the autocomplete attribute. Accepts on and off. |
| hasTrim | Boolean | false | Defines if the input value should be trimmed on blur. |
| showInputEye | Boolean | false | Defines 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. |
| inputEyeIcon | String | '🫣' | Defines the icon shown when password is visible. |
| inputEyeIconHidden | String | '😎' | Defines the icon shown when password is hidden. |
| inputEyeCustomIcon | Boolean | false | Defines if custom icons should be used via slots instead of emoji. |
| activeTextStyle | String | 'normal' | Defines the text style when input is active/focused. Accepts normal, italic, oblique. |
| sizeMediaQuery | String | 'sm' | Defines the responsive size. Accepts xs, sm, md, lg. |
| showMsg | Boolean | false | Defines if the message should be displayed. |
| hasMsg | Boolean | false | Defines if there is a message to show. |
| message | String | 'Default message text' | Defines the message text. |
| hasCustomMsg | Boolean | false | Defines if a custom message slot should be used. |
| extraContendAbsolute | Boolean | false | Controls 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.) |
| textAlign | String | 'left' | Defines the text alignment. Accepts left, center, right. |
| fontFamily | String | "'Lato', sans-serif" | Defines the font-family |
| fontSize | String | null (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. |
| fontWeight | Number | 400 | Defines the font-weight |
| fontFamilyMsg | String | "'Lato', sans-serif" | Defines the message font-family |
| fontSizeMsg | String | '1em' | Defines the message font-size |
| fontWeightMsg | Number | 400 | Defines the message font-weight |
| textMessageColor | String | '#f15574' | Defines the message text color |
| lightBgColor | String | '#f8f8f2' | Defines the background color for light theme |
| lightBgColorFocus | String | '#eaeaea' | Defines the background color when focused for light theme |
| lightEyeBgColor | String | '#353734' | Defines the eye icon background color for light theme |
| lightEyeBgColorActive | String | '#272936' | Defines the eye icon background color when active for light theme |
| lightDisabledBgColor | String | '#dfdfd9' | Defines the disabled background color for light theme |
| lightTextColor | String | '#000000' | Defines the text 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 |
| darkEyeBgColor | String | '#353734' | Defines the eye icon background color for dark theme |
| darkEyeBgColorActive | String | '#272936' | Defines the eye icon background color when active for dark theme |
| darkDisabledBgColor | String | 'rgba(40, 42, 54, 1)' | Defines the disabled background color for dark theme |
| darkTextColor | String | '#000000' | Defines the text color for dark theme |
| darkDisabledEyeBgColor | String | 'rgba(68, 71, 90, 0.3)' | Defines the disabled eye icon background color for dark theme |
| lightDisabledEyeBgColor | String | 'rgba(53, 55, 52, 0.3)' | Defines the disabled eye icon background color for light theme |
| hasIcon | Boolean | false | Defines if a custom icon should be displayed. When true, shows an icon slot on the left or right side of the input. |
| iconWidth | Number | 32 | Defines the icon width in pixels |
| iconDirection | String | 'left' | Defines the icon position. Accepts left and right. |
| iconPadding | String | '5px 10px' | Defines the icon padding. Must be two space-separated values (e.g., "5px 10px"). |
| iconPaddingInput | Number | 35 | Defines the input padding when icon is present. Adds padding to the side where the icon is positioned. |
| iconMargin | String | '0' | Defines the icon margin |
| iconLightTextColor | String | '#f8f8f2' | Defines the icon text color for light theme |
| iconDarkTextColor | String | '#f8f8f2' | Defines the icon text color for dark theme |
| iconLightBgColor | String | '#353734' | Defines the icon background color for light theme |
| iconLightBgColorActive | String | '#272936' | Defines the icon background color when active for light theme |
| iconDarkBgColor | String | '#353734' | Defines the icon background color for dark theme |
| iconDarkBgColorActive | String | '#272936' | Defines the icon background color when active for dark theme |
| iconDarkDisabledBgColor | String | 'rgba(68, 71, 90, 0.3)' | Defines the disabled icon background color for dark theme |
| iconLightDisabledBgColor | String | 'rgba(53, 55, 52, 0.3)' | Defines the disabled icon background color for light theme |
| iconBorderRadius | Number | 0 | Defines the border-radius for the icon |
| iconSize | Number | 1 | Defines the icon size multiplier |
| 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 or has content. |
| 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. |
| labelRight | Number | 0 | Defines the right position of the label when inactive in pixels. |
| inputLabelMarginActive | Number | 15 | Defines the top margin of the input when the label is active in pixels. This creates space for the label above the input. |
| labelActiveTop | Number | -13 | Defines the top position of the label when active in pixels. Negative values move the label above the input. |
| labelActiveLeft | Number | 5 | Defines the left position of the label when active in pixels. |
| labelActiveRight | Number | 0 | Defines the right position of the label when active in pixels. |
| labelBreakOnActive | Boolean | true | Defines if the label text should break or use ellipsis when active |
| 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 |
|---|---|---|
| current-value | value | Fired when the input value changes. With input-mask, shape follows input-mask-emit (see prop table). Otherwise the raw value (and number typing rules apply). |
| changed | value | Same payload semantics as current-value. |
| focused | nothing | Fired when the input receives focus. |
| blurred | nothing | Fired when the input loses focus. |
| show-input-eye | boolean | Fired when the password visibility toggle is clicked, returns the visibility state. |
| clicked | MouseEvent | KeyboardEvent | Fired when the input container is clicked. Receives the native DOM event as first argument. |
| entered | value | Fired when Enter is pressed in the field and the value is accepted. Same payload rules as changed / current-value (including input-mask + input-mask-emit). With input-mask, if the trimmed value is non-empty but does not fill every mask token slot, entered is not fired — see mask-error. |
| paste | value | 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, trigger, masked, clean, requiredTokenCount, filledTokenCount, activePattern } | Only with input-mask (input-type="text"). Fired when the trimmed value is non-empty but does not fill every mask token slot: on every changed (trigger: 'changed') and when Enter is pressed (trigger: 'enter'). Same extra fields as NbInputChip mask-error, plus trigger. entered is not emitted when Enter would fire only mask-error (trigger: 'enter'). |
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-typemust betext—input-maskis ignored fornumber,email, andpassword.- In templates, use the kebab-case attribute
input-mask, which maps to theinputMaskprop. - With
input-mask, the shape of values inchanged,current-value, andenteredfollowsinput-mask-emit:masked(default),clean, orboth({ masked, clean }). See the prop table and the subsection below. - Optional
input-mask-tokens: merge extravue-the-masktokens for patterns the defaults cannot express (e.g. optional leading minus). See Custom mask tokens (input-mask-tokens). - 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-maskmay sort patterns in place;NbInputalready passes a shallow copy of arrays to the directive, but keeping mutable arrays in your code is simpler.
Emit shape with mask (input-mask-emit)
Use the kebab-case attribute input-mask-emit on NbInput when input-mask is set:
| Value | changed / current-value / entered |
|---|---|
masked (default) | Masked string (what the user sees). |
clean | Unmasked / token-only string from vue-the-mask. |
both | Object { masked, clean }. |
Without input-mask, input-mask-emit has no effect.
Pattern tokens (vue-the-mask)
Common placeholders (see the package README for full list):
| Token | Meaning |
|---|---|
# | Digit (0-9) |
A | Letter (uppercase transform) |
a | Letter (lowercase transform) |
S | Letter (a-z, A-Z) |
X | Alphanumeric |
! | 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.
Custom mask tokens (input-mask-tokens)
The default tokens (#, X, S, …) cover many cases, but not everything — for example # only matches digits, so a optional leading minus for negative numbers is not expressible with the default set alone.
Use the inputMaskTokens prop (template: input-mask-tokens) to pass an object of extra token definitions. The component shallow-merges it onto vue-the-mask’s default token map: { ...defaultTokens, ...inputMaskTokens }.
| Topic | Detail |
|---|---|
| When to use | You need a new placeholder character in the mask string (e.g. N for “minus or digit”) or you intentionally override a default (see warning below). |
| Omit the prop | Omit it or use null / leave the object empty — behaviour stays the same as before: only input-mask is passed to the directive and the library uses its built-in tokens. |
| When the prop has keys | NbInput passes { mask, tokens } to vue-the-mask (same idea as its TheMask component). The masker used for input-mask-emit (clean / both) and for mask-error completion uses that same merged token map, so everything stays consistent. |
| Merge semantics | Shallow merge at the top level only. If you set a key that already exists in the defaults (e.g. #), your entry replaces the built-in digit token — usually you should use new symbols (N, _, …) instead of redefining #. |
| Token shape | Per the library: each key is one character used in the mask string; the value is { pattern: RegExp } and optionally transform. |
Example — signed integer (optional -, then up to three digits): use one custom slot N (minus or digit) and three normal digit slots #:
<script setup>
const signedIntMaskTokens = {
N: { pattern: /[-0-9]/ },
}
</script>
<template>
<NbInput
nb-id="signed-int"
input-name="signed-int"
input-type="text"
input-mask="N###"
:input-mask-tokens="signedIntMaskTokens"
label="Signed value"
:show-label="true"
/>
</template>
The same input-mask-tokens API exists on NbInputChip for the chip text field.
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$ .
Signed integer with custom token — see Custom mask tokens (input-mask-tokens) above.
