Skip to content

Textarea

Multi-line text with a label, a character count and optional auto-grow. Same markup and props in every style: switch the style in the header to see it change.

Basic

A textarea with the Input classes plus vin-textarea, a label and a hint.

We usually reply within a day.

textarea-basic.html
<div class="vin-field" style="width: 100%; max-width: 360px">
  <label class="vin-label" for="message">Message</label>
  <textarea id="message" class="vin-input vin-textarea" rows="3" placeholder="How can we help?" aria-describedby="message-hint"></textarea>
  <div class="vin-textarea__foot">
    <p class="vin-hint" id="message-hint">We usually reply within a day.</p>
  </div>
</div>

Character count

Set maxLength and the count appears. It turns red when the limit is reached. In HTML, add data-vin-textarea with the count's id and include vinui.js.

Shown on your profile.

32 / 160

textarea-count.html
<div class="vin-field" style="width: 100%; max-width: 360px">
  <label class="vin-label" for="bio">Bio</label>
  <textarea id="bio" class="vin-input vin-textarea" rows="3" maxlength="160" data-vin-textarea="bio-count" aria-describedby="bio-hint bio-count">Designer and developer in Delhi.</textarea>
  <div class="vin-textarea__foot">
    <p class="vin-hint" id="bio-hint">Shown on your profile.</p>
    <p class="vin-textarea__count" id="bio-count">32 / 160</p>
  </div>
</div>

Auto-grow

Grows as you type instead of showing a scrollbar, then scrolls after 260px. Pure CSS in modern browsers, with a JavaScript fallback for the rest.

Grows as you type.

textarea-auto.html
<div class="vin-field" style="width: 100%; max-width: 360px">
  <label class="vin-label" for="notes">Notes</label>
  <textarea id="notes" class="vin-input vin-textarea vin-textarea--auto" rows="2" data-vin-textarea placeholder="Start typing…" aria-describedby="notes-hint"></textarea>
  <div class="vin-textarea__foot">
    <p class="vin-hint" id="notes-hint">Grows as you type.</p>
  </div>
</div>

Installation

React, Vue and Svelte: add the component to your project with the CLI. It reads your framework from vin.json and also copies any component this one needs. Then import it:

Terminal
npx @vinish/ui add textarea
React
import { Textarea } from "@/components/vin/textarea";
Vue
import Textarea from "@/components/vin/textarea.vue";
Svelte
import Textarea from "$lib/components/vin/textarea.svelte";

The import paths assume the default folders: @/components/vin (React and Vue, with the usual @ → src alias) and $lib/components/vin (SvelteKit). Use your own if you chose another folder in init. How the Vue and Svelte versions pass values and content is in Frameworks.

Plain HTML: the classes come with the style's stylesheet. This component also needs vinui.js for its keyboard and pointer behaviour.

API

From spec/textarea.json, which every framework version is tested against.

PropValuesDefaultIn HTML
label
Visible label. Without it, pass an aria-label.
ReactNode—<label class="vin-label" for="…">
hint
Help text under the field.
ReactNode—<p class="vin-hint"> inside .vin-textarea__foot
error
An error message. Also marks the textarea invalid.
ReactNode—<p class="vin-error"> + aria-invalid="true"
maxLength
Limit, shown as a count under the field.
number—maxlength + data-vin-textarea="<count id>" + vinui.js
showCount
Show the count. On by default when maxLength is set.
boolean—<p class="vin-textarea__count">
autoResize
Grow with the text, up to 260px, then scroll.
booleanfalsevin-textarea--auto
disabledbooleanfalsedisabled attribute

Parts

React, Vue, SvelteHTML classes
<Textarea>.vin-textarea.vin-textarea--auto.vin-textarea__foot.vin-textarea__count

Accessibility

  • Every textarea has a label: a <label for> or an aria-label.
  • Hint, error and count are linked with aria-describedby, so they are read with the field.
  • The count is not a live region, so screen readers aren't interrupted on every key; it is read when the field gets focus.
  • An error sets aria-invalid="true" and is shown as text.