Skip to content

Textarea

Overview

The Textarea component provides a multi-line text input field for users. It's equipped with various configurations such as an integrated counter, error display, and more, to suit a wide range of use cases.

Storybook

Props

PropTypeDefaultDescription
modelValueString''The current value of the textarea.
nameString''Name attribute for the textarea.
errorBooleanfalseIndicates if the textarea has an error.
readonlyBooleanfalseIf true, the textarea will be read-only.
disabledBooleanfalseIf true, the textarea will be disabled.
counterBooleanfalseIf true, a character counter will be displayed.
shadowBooleanfalseIf true, a shadow will be added to the textarea.
colsString, NumberundefinedNumber of columns for the textarea.
rowsString, NumberundefinedNumber of rows for the textarea.
labelString''Label for the textarea.
wrapperClassString''Class to be applied to the component wrapper.
inputClassString''Class to be applied to the textarea element.
labelClassString''Class to be applied to the label.
hideErrorBooleanfalseIf true, hides the error message even if there's an error.
hintString''Hint or help text displayed below the textarea.
errorMessageString''Error message displayed when there's a validation error related to the textarea.
idString''ID attribute for the textarea. If not provided, the name prop will be used as the ID.

Events

EventPayload TypeDescription
update:modelValueStringEmits the current value of the textarea.

Methods

MethodDescription
focusFocuses the textarea element. Can be used programmatically from the parent component.

Slots

SlotPropsDescription
default{}Default slot, useful if you want to insert content inside the textarea's wrapper but outside the textarea itself.
hint{}Custom hint content. If not provided, the hint prop will be used.
error{}Custom error content. If not provided, the errorMessage prop will be used.
counter{ count: number }Custom counter content. count provides the current number of characters in the textarea. Defaults to character count.

Usage

To use the Textarea component:

  1. Import the component.
  2. Bind the necessary props.
  3. Optionally, use the slots for custom content.
vue
<script setup lang="ts">
import {ref} from 'vue';
import {Textarea} from '@morpheme/forms';

const userInput = ref('');
</script>

<template>
  <Textarea
    v-model="userInput"
    label="Feedback"
    counter
    hint="Let us know how we can improve."
    :rows="5"
  />
</template>
<script setup lang="ts">
import {ref} from 'vue';
import {Textarea} from '@morpheme/forms';

const userInput = ref('');
</script>

<template>
  <Textarea
    v-model="userInput"
    label="Feedback"
    counter
    hint="Let us know how we can improve."
    :rows="5"
  />
</template>

This will render a textarea with a label "Feedback", a character counter, a hint message, and 5 rows for user input. The text entered by the user will be bound to the userInput ref.