WlTextarea

Multiline field. autoResize can adjust its height to content.
Components / Inputs v0.1.0

Change props to see the result: the example and code use the same settings. “Reset” restores the initial values.

Settings

rows

Row count.

placeholder

Placeholder.

maxRows
Not set

Maximum visible textarea rows when automatic resizing is enabled.

Error state.

Disables the field.

Adjust height to content.

Display the text length counter and connect it to the control description.

Props pt, size, density, models, handlers and slots can be edited in the SFC. See their descriptions in API.

Example

Focus: outside the example · pointer: outside the example

Explore the live example and copy its Vue SFC into your application. Settings on the left can be combined.

Code for your application

Vue SFC · current settings
<script setup lang="ts">
import { WlTextarea } from "legato-ui";
import { ref } from "vue";
const value = ref("Material description.\nThe next line is preserved.");
</script>

<template>
  <div class="wl-stack" data-space="md">
    <WlTextarea
      v-model="value"
      aria-label="Material description"
      :rows="3"
      auto-resize
      
    />
  </div>
</template>

Rows, height and error

Fixed height through rows or content height through autoResize. Shared model, adding rows, required comment and clearing.

Fixed rows and content height

Add lines: the height grows with the text.

Error and unavailable field

Add a comment.

Description length: 45 characters.

Vue SFC · additional example
<script setup lang="ts">
import { WlButton, WlField, WlTextarea } from "legato-ui";
import { ref } from "vue";
const text = ref("Briefly describe the task.\nAdd the next step.");
const comment = ref("");
</script>

<template>
  <div class="wl-stack" data-space="xl" data-input-example="WlTextarea">
    <section class="wl-stack" data-space="md">
      <h3 class="wl-text-title">{{ "Fixed rows and content height" }}</h3>
      <div class="wl-grid" data-space="lg">
        <WlField id="docs-textarea-fixed" v-slot="{ id }" label="Description, 4 rows">
          <WlTextarea :id="id" v-model="text" :rows="4" />
        </WlField>
        <WlField
          id="docs-textarea-grow"
          v-slot="{ id, ariaDescribedby }"
          label="Description with content height"
          hint="Add lines: the height grows with the text."
        ><WlTextarea
          :id="id"
          v-model="text"
          :rows="2"
          auto-resize
          :aria-describedby="ariaDescribedby"
        /></WlField>
      </div>
    </section>
    <section class="wl-stack" data-space="md">
      <h3 class="wl-text-title">{{ "Error and unavailable field" }}</h3>
      <div class="wl-grid" data-space="lg">
        <WlField
          id="docs-textarea-comment"
          v-slot="{ id, ariaDescribedby, invalid, required }"
          label="Comment"
          :error="comment.trim() ? undefined : 'Add a comment.'"
          required
        ><WlTextarea
          :id="id"
          v-model="comment"
          :invalid="invalid"
          :required="required"
          :aria-describedby="ariaDescribedby"
          placeholder="What needs clarification?"
        /></WlField>
        <WlField id="docs-textarea-disabled" v-slot="{ id }" label="Closed comment">
          <WlTextarea :id="id" model-value="Discussion completed." disabled />
        </WlField>
      </div>
      <div class="wl-inline" data-space="sm">
        <WlButton size="sm" @click="text += '\nAnother item.'">{{ "Add line" }}</WlButton>
        <WlButton size="sm" @click="text = ''; comment = ''">{{ "Clear text" }}</WlButton>
      </div>
      <p class="wl-text-small" role="status">{{
        "Description length:"
      }} {{
        text.length
      }} {{
        "characters."
      }}</p>
    </section>
  </div>
</template>