nb-textarea

This is a textarea component for Vue.js 3+.

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 NbTextarea or nb-textarea.

Mode 1
<template>
  <NbTextarea />
</template>
Mode 2
<template>
  <nb-textarea />
</template>
Mode 3
<template>
  <nb-textarea></nb-textarea>
</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''Defines the initial textarea value. Accepts String.

Other props

nameValue typeDefaultDescription
nbId (*)StringSets the id attribute to differentiate from other components
inputName (*)StringSets the name attribute for the textarea element
displayString'b'Defines the display type. Accepts ib and b.
tabIndexNumber0Defines the tab index. Set this property to make the textarea focusable by the keyboard.
hasTabIndexEnterBooleantrueDefines if pressing Enter should trigger the entered event.
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' }
themeString'light'Defines the theme. Accepts light and dark.
disabledBooleanfalseDefines if the textarea is disabled
requiredBooleanfalseDefines if the textarea is required
inputReadonlyBooleanfalseDefines if the textarea is readonly
inputTextString''Defines the initial textarea value.
inputPlaceholderString''Defines the placeholder text for the textarea.
hasTrimBooleanfalseDefines if the textarea value should be trimmed (spaces removed from start and end).
fontFamilyString"'Lato', sans-serif"Defines the font-family for the textarea
fontSizeStringnull (default: 1.4em)Defines the font-size for the textarea. If null, uses 1.4em as default size. Pass a string with the font-size and the unit (e.g., "1.2em").
fontWeightNumber400Defines the font-weight for the textarea
textColorString'#ffffff'Defines the text color for the textarea
caretColorString''Defines the caret (cursor) color. If empty, uses theme default.
selectionBgColorString''Defines the background color for selected text. If empty, uses theme default.
selectionTextColorString''Defines the text color for selected text. If empty, uses theme default.
hasBorderRadiusBooleanfalseDefines if the textarea should have border radius
borderRadiusNumber0.5Defines the border radius in rem units. Only applies if hasBorderRadius is true and inputStyle is not 'line'.
inputWidthNumber200Defines the textarea width in pixels. Only applies when display is not 'b'.
inputStyleString'background'Defines the textarea style. Accepts background, line, and border.
activeTextStyleString'normal'Defines the text style when textarea is active. Accepts normal, italic, and oblique.
inputUppercaseBooleanfalseDefines if the textarea text should be displayed in uppercase
inputAutocompleteString'on'Defines the autocomplete attribute. Accepts on and off.
textAlignString'left'Defines the text alignment. Accepts left, center, and right.
rowsNumber2Defines the number of visible text lines (height). Must be greater than 0.
colsNumber20Defines the visible width in average character widths. Must be greater than 0.
maxlengthNumbernullDefines the maximum number of characters allowed. If null, there is no limit.
minlengthNumbernullDefines the minimum number of characters required. If null, there is no minimum.
wrapString'soft'Defines how the text should be wrapped. Accepts soft (automatic line breaks, visual only), hard (forced line breaks, included in form submission), and off (no line breaks).
spellcheckBoolean/String'default'Defines if spell checking is enabled. Accepts true, false, or 'default' (browser default).
autofocusBooleanfalseDefines if the textarea should automatically receive focus when the page loads.
resizeString'vertical'Defines how the textarea can be resized. Accepts none (not resizable), both (resizable in both directions), vertical (resizable vertically only), and horizontal (resizable horizontally only).
autoResizeBooleanfalseDefines if the textarea should automatically resize based on content. When enabled, the textarea grows/shrinks with the content.
minRowsNumbernullDefines the minimum number of rows when autoResize is enabled. If null, uses the rows value.
maxRowsNumbernullDefines the maximum number of rows when autoResize is enabled. If null, there is no limit.
showLabelBooleanfalseDefines if the label should be displayed
labelString'Label text'Defines the label text
labelBackgroundString'transparent'Defines the background color for the label when active (floating)
labelPaddingString'1px 5px'Defines the padding for the label when active (floating)
labelBorderRadiusNumber0Defines the border radius for the label when active (floating)
labelLeftNumber5Defines the left position of the label when inactive (inside textarea)
inputLabelMarginActiveNumber15Defines the top margin of the textarea when label is active (floating)
labelActiveTopNumber-13Defines the top position of the label when active (floating)
labelActiveLeftNumber-10Defines the left position of the label when active (floating)
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 (floating)
fontWeightLabelNumber400Defines the font-weight for the label
lightTextColorLabelString'#333333'Defines the text color for the label in light theme
lightTextColorLabelActiveString'#333333'Defines the text color for the label when active in light theme
darkTextColorLabelString'#ffffff'Defines the text color for the label in dark theme
darkTextColorLabelActiveString'#ffffff'Defines the text color for the label when active in dark theme
lightBgColorString'#f8f8f2'Defines the background color for the textarea in light theme
lightBgColorFocusString'#eaeaea'Defines the background color for the textarea when focused in light theme
lightDisabledBgColorString'#dfdfd9'Defines the background color for the textarea when disabled in light theme
lightTextColorString'#000000'Defines the text color for the textarea in light theme
darkBgColorString'#353734'Defines the background color for the textarea in dark theme
darkBgColorFocusString'#272936'Defines the background color for the textarea when focused in dark theme
darkDisabledBgColorString'rgba(40, 42, 54, 1)'Defines the background color for the textarea when disabled in dark theme
darkTextColorString'#000000'Defines the text color for the textarea in dark theme
fontFamilyMsgString"'Lato', sans-serif"Defines the font-family for the message
fontSizeMsgString'1em'Defines the font-size for the message
fontWeightMsgNumber400Defines the font-weight for the message
textMessageColorString'#f15574'Defines the text color for the message
showMsgBooleanfalseDefines if the message should be displayed
hasMsgBooleanfalseDefines if there is a message to display
messageString'Default message text'Defines the message text
hasCustomMsgBooleanfalseDefines if the message uses custom styling
tabindexString/Number0Defines the tabindex attribute for the textarea

Events

changed

Fired when the textarea value changes.

Returns: String - The current textarea value

Example:

@changed="onTextareaChanged"

const onTextareaChanged = (value) => {
  console.log('Textarea value:', value)
}

current-value

Fired whenever the textarea value changes (same as changed but with a different name for compatibility). Returns the same format as changed.

Returns: String - The current textarea value

Example:

@current-value="onCurrentValue"

const onCurrentValue = (value) => {
  console.log('Current value:', value)
}

focused

Fired when the textarea receives focus.

Returns: No return value

Example:

@focused="onTextareaFocused"

const onTextareaFocused = () => {
  console.log('Textarea focused')
}

blurred

Fired when the textarea loses focus.

Returns: No return value

Example:

@blurred="onTextareaBlurred"

const onTextareaBlurred = () => {
  console.log('Textarea blurred')
}

clicked

Fired when the textarea or its container is clicked.

Returns: No return value

Example:

@clicked="onTextareaClicked"

const onTextareaClicked = () => {
  console.log('Textarea clicked')
}

entered

Fired when the user presses Enter while the textarea is focused. Only fires if hasTabIndexEnter is true and the textarea is not disabled or readonly.

Returns: The current textarea value (same format as changed)

Example:

@entered="onEnterPressed"

const onEnterPressed = (value) => {
  console.log('Enter pressed with value:', value)
}

Slots

message

Custom slot for the message area. Allows custom HTML/content to be displayed as the message.

Example:

<nb-textarea nb-id="textarea-1" input-name="description">
  <template #message>
    <span>Custom error message</span>
  </template>
</nb-textarea>

Examples

Basic Textarea

<template>
  <NbTextarea
    nb-id="textarea-basic"
    input-name="description"
    @changed="onTextareaChanged"
  />
</template>

<script setup>
const onTextareaChanged = (value) => {
  console.log('Textarea value:', value)
}
</script>

Textarea with Label

<template>
  <NbTextarea
    nb-id="textarea-label"
    input-name="description"
    :show-label="true"
    label="Enter your description"
    @changed="onTextareaChanged"
  />
</template>

<script setup>
const onTextareaChanged = (value) => {
  console.log('Textarea value:', value)
}
</script>

Textarea with Placeholder

<template>
  <NbTextarea
    nb-id="textarea-placeholder"
    input-name="description"
    input-placeholder="Enter your description here..."
    @changed="onTextareaChanged"
  />
</template>

<script setup>
const onTextareaChanged = (value) => {
  console.log('Textarea value:', value)
}
</script>

Textarea with Character Limit

<template>
  <NbTextarea
    nb-id="textarea-limit"
    input-name="description"
    :maxlength="500"
    :minlength="10"
    @changed="onTextareaChanged"
  />
</template>

<script setup>
const onTextareaChanged = (value) => {
  console.log('Textarea value:', value)
}
</script>

Auto-Resizing Textarea

<template>
  <NbTextarea
    nb-id="textarea-autoresize"
    input-name="description"
    :auto-resize="true"
    :min-rows="3"
    :max-rows="10"
    @changed="onTextareaChanged"
  />
</template>

<script setup>
const onTextareaChanged = (value) => {
  console.log('Textarea value:', value)
}
</script>

Textarea with Custom Size

<template>
  <NbTextarea
    nb-id="textarea-size"
    input-name="description"
    :rows="5"
    :cols="50"
    @changed="onTextareaChanged"
  />
</template>

<script setup>
const onTextareaChanged = (value) => {
  console.log('Textarea value:', value)
}
</script>

Textarea with Wrap Options

<template>
  <NbTextarea
    nb-id="textarea-wrap"
    input-name="description"
    wrap="hard"
    @changed="onTextareaChanged"
  />
</template>

<script setup>
const onTextareaChanged = (value) => {
  console.log('Textarea value:', value)
}
</script>

Textarea with Resize Options

<template>
  <NbTextarea
    nb-id="textarea-resize"
    input-name="description"
    resize="both"
    @changed="onTextareaChanged"
  />
</template>

<script setup>
const onTextareaChanged = (value) => {
  console.log('Textarea value:', value)
}
</script>

Dark Theme Textarea

<template>
  <NbTextarea
    nb-id="textarea-dark"
    input-name="description"
    theme="dark"
    :input-width="400"
    @changed="onTextareaChanged"
  />
</template>

<script setup>
const onTextareaChanged = (value) => {
  console.log('Textarea value:', value)
}
</script>

Textarea with Custom Styling

<template>
  <NbTextarea
    nb-id="textarea-custom"
    input-name="description"
    :has-border-radius="true"
    :border-radius="0.8"
    input-style="border"
    :input-width="300"
    text-align="center"
    @changed="onTextareaChanged"
  />
</template>

<script setup>
const onTextareaChanged = (value) => {
  console.log('Textarea value:', value)
}
</script>

Textarea with Message

<template>
  <NbTextarea
    nb-id="textarea-message"
    input-name="description"
    :show-msg="true"
    :has-msg="true"
    message="Please enter a valid description"
    @changed="onTextareaChanged"
  />
</template>

<script setup>
const onTextareaChanged = (value) => {
  console.log('Textarea value:', value)
}
</script>

Readonly Textarea

<template>
  <NbTextarea
    nb-id="textarea-readonly"
    input-name="description"
    :input-readonly="true"
    input-text="This text cannot be edited"
    @changed="onTextareaChanged"
  />
</template>

<script setup>
const onTextareaChanged = (value) => {
  console.log('Textarea value:', value)
}
</script>

Disabled Textarea

<template>
  <NbTextarea
    nb-id="textarea-disabled"
    input-name="description"
    :disabled="true"
    input-text="This textarea is disabled"
    @changed="onTextareaChanged"
  />
</template>

<script setup>
const onTextareaChanged = (value) => {
  console.log('Textarea value:', value)
}
</script>

Textarea with Spellcheck

<template>
  <NbTextarea
    nb-id="textarea-spellcheck"
    input-name="description"
    :spellcheck="true"
    @changed="onTextareaChanged"
  />
</template>

<script setup>
const onTextareaChanged = (value) => {
  console.log('Textarea value:', value)
}
</script>

Textarea with Autofocus

<template>
  <NbTextarea
    nb-id="textarea-autofocus"
    input-name="description"
    :autofocus="true"
    @changed="onTextareaChanged"
  />
</template>

<script setup>
const onTextareaChanged = (value) => {
  console.log('Textarea value:', value)
}
</script>