Skip to content

TextArea API Reference

Props

PropTypeDefaultDescription
rowsNumber3Number of rows to display initially
noResizeBooleanfalseDisable manual resizing of the textarea
autoGrowBooleanfalseAutomatically grow the textarea to fit content
maxlengthNumber-Maximum number of characters allowed
minRowsNumber1Minimum number of rows to display
counterBooleanfalseShow character counter

Additionally, the component inherits all props from the BasicInput component, including:

Inherited PropTypeDefaultDescription
labelString-Label for the textarea
placeholderString-Placeholder text
clearableBooleanfalseAllow clearing the textarea
disabledBooleanfalseDisable the textarea
readonlyBooleanfalseMake the textarea read-only
modelValueString-v-model binding value
rulesArray[]Validation rules

Events

The component emits a comprehensive set of events:

EventPayloadDescription
update:modelValueStringEmitted when textarea value changes
prepend:clickEventEmitted when prepend button is clicked
prependInner:clickEventEmitted when inner prepend button is clicked
clear:clickEventEmitted when clear button is clicked
append:clickEventEmitted when append button is clicked
appendInner:clickEventEmitted when inner append button is clicked
validateBoolean, Value, MessageEmitted when validation occurs
focus, blur, input, changeEventStandard form events
keydown, keyup, keypressEventKeyboard events
click, dblclick, mousedown, etc.EventMouse events
copy, cut, pasteEventClipboard events
compositionstart, compositionupdate, compositionendEventInput composition events
dragenter, dragover, dragleave, dropEventDrag and drop events

Slots

The component forwards all slots from the BasicInput component:

SlotPropsDescription
prepend{ click }Content before the textarea
prependInner{ click }Content inside the textarea, at the beginning
appendInner{ click }Content inside the textarea, at the end
append{ click }Content after the textarea
details{ errorMessage, hint }Custom validation details

Methods

The component doesn't explicitly expose methods, but it inherits the following methods from BasicInput:

MethodDescription
validate()Manually trigger validation
setInternalValue(value)Set the textarea value programmatically

Example Usage

vue
<template>
  <OTextArea
    v-model="comments"
    label="Comments"
    placeholder="Enter your comments here"
    :rows="4"
    :autoGrow="true"
    :counter="true"
    :maxlength="500"
    :rules="[
      { rule: 'required', message: 'Please enter your comments' },
      { rule: 'min', value: 10, message: 'Comments must be at least 10 characters' }
    ]"
    @update:modelValue="handleInput"
    @focus="handleFocus"
  />
</template>

<script setup>
import { ref } from 'vue'
import { OTextArea } from 'your-component-library'

const comments = ref('')

const handleInput = (value) => {
  console.log('Input value:', value)
}

const handleFocus = (event) => {
  console.log('TextArea focused', event)
}
</script>

Auto-Growing Behavior

When autoGrow is set to true, the textarea will automatically adjust its height to fit the content as the user types. This is achieved by:

  1. Setting the height to 'auto' to calculate the scrollHeight
  2. Setting the height to the scrollHeight value

This ensures the textarea is always the right size for its content, eliminating the need for scrollbars in most cases.