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$ ###.###.###,##). Emits the masked string in changed / current-value. Template: input-mask. |
| 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, returns the current value. |
| changed | value | Fired when the input value changes, returns the 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 the Enter key is pressed, returns the current value. |
| 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). |
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. changedandcurrent-valueemit 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-maskmay sort patterns in place;NbInputalready 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):
| 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.
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$ .
