Variants
The variant prop controls how the label and messages are positioned relative to the field box.
Default
Label sits above the field, message below. Standard form layout.
Fluid
The label sits inside the field box. While the field is empty and idle it rests where a placeholder would be, and the moment the field has a value or focus it steps up and shrinks above the value. A placeholder shows only once the label has stepped aside. The message is an icon at the end of the value line. The field keeps the height of its size, as NbSelect, NbNumberInput and NbDatePicker do in fluid, so a row of them lines up.
At sm (32px), for a filter bar or a toolbar:
<NbTextInput v-model="name" variant="fluid" size="sm" label="Name" />A floated label and its value need two lines, which 24px cannot hold, so a fluid field draws xs at sm. The label moves on transform on the quick motion step, and with reduced motion it moves without travel.
<template>
<NbTextInput v-model="value" variant="fluid" label="Label" />
</template>Multiline
Set multiline to render a <textarea>. Use rows to control the initial height.
<template>
<NbTextInput v-model="value" label="Notes" multiline :rows="4" />
</template>Leading icon
The #leading slot puts an icon before the text, for a search field or a field whose kind an icon says faster than a label. The slot is padded to where the text would otherwise start, so the icon lines up with the placeholders of the fields above and below it, and the text follows the icon by 8px. A multiline field keeps the icon on its first line. Without the slot, nothing about the field changes.
For a full search control (clear on Escape, an expandable mode for toolbars) use NbSearch, which is built this way.
<NbTextInput
v-model="query"
label="Search the docs"
placeholder="Search docs"
size="lg"
>
<template #leading>
<NbIcon name="magnifying-glass" :size="20" />
</template>
</NbTextInput>Drop your own spacing
Before this release the slot had no padding, and the icon touched the field's left edge. If you added a margin to the icon to make up for it, remove it now, or the gap doubles.
Inline actions slot
Use the #actions slot to place buttons inside the field at the trailing edge (default variant only). An action is an icon-only NbButton, ghost, with a label: the label is its accessible name and its tooltip, so it never needs an aria-label or a tooltip of its own. Pass the icon as icon, never an NbIcon in the slot.
<template>
<NbTextInput v-model="value" label="AI Translate">
<template #actions>
<NbButton variant="ghost" size="sm" icon="sparkle" label="Translate" />
</template>
</NbTextInput>
</template>Clear and password reveal
clearable shows an x button once the field has a value. It empties the field, emits clear and keeps focus in the field, and Escape does the same. revealable on a type="password" field puts an eye at the far right that shows and hides the characters. Both buttons are named from the string catalogue (textInputClear, textInputShowPassword, textInputHidePassword).
Both variants have them. In fluid they sit at the trailing edge of the box and take the field's size, as in the default variant.
<template>
<NbTextInput v-model="name" label="Project name" clearable />
<NbTextInput
v-model="password"
label="Password"
type="password"
revealable
autocomplete="new-password"
/>
<NbTextInput v-model="name" variant="fluid" label="Project name" clearable />
</template>Suggestions
The #dropdown slot holds a popup anchored to the field. For autocomplete (an @mention, a reference, a tag) put an NbSuggestionList in it: it takes the keyboard from the field and makes it a combobox, so you only decide when it opens and what it offers.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
modelValue | string | number | '' | Bound value (v-model) |
variant | 'default' | 'fluid' | 'default' | Layout variant |
size | 'xs' | 'sm' | 'md' | 'lg' | 'md' | Field height: 24, 32, 40 or 48px, the same as NbButton |
type | string | 'text' | Native input type |
label | string | - | Label text |
placeholder | string | - | Input placeholder |
helper | string | - | Helper message (shown when no error or warning) |
error | string | - | Error message: highest priority |
warning | string | - | Warning message: priority over helper |
required | boolean | false | Marks field as required (adds asterisk) |
disabled | boolean | false | Disables the input |
readonly | boolean | false | Makes the input read-only |
multiline | boolean | false | Render a <textarea> instead of <input> |
rows | number | - | Initial textarea row count (multiline only) |
id | string | auto | Explicit input ID |
name | string | - | Native name attribute |
maxlength | number | - | Maximum character length |
showCount | boolean | false | Shows 12/200 under the field when maxlength is set |
clearable | boolean | false | A clear button while there is a value, and Escape clears |
revealable | boolean | false | With type="password", an eye button that shows the characters |
Events
| Event | Payload | Description |
|---|---|---|
update:modelValue | string | number | Emitted on every keystroke |
clear | - | The clear button or Escape emptied the field |
Slots
| Slot | Description |
|---|---|
label | Custom label content (replaces the label prop text) |
leading | An icon before the text, padded to where the text would start (default variant only) |
actions | Buttons or icons rendered at the trailing edge (default only) |
dropdown | A popup anchored to the field, such as an NbSuggestionList |
Exposed
| Name | Type | Description |
|---|---|---|
focus | () => void | Focuses the input |
blur | () => void | Blurs the input |
nativeEl | Ref<HTMLInputElement | HTMLTextAreaElement> | The native field, for the caret position |