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.
<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>We usually reply within a day.
import { Textarea } from "@/components/vin/textarea";
export function TextareaBasic() {
return <Textarea label="Message" rows={3} placeholder="How can we help?" hint="We usually reply within a day." style={{ width: "100%", maxWidth: 360 }} />;
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import Textarea from "@/components/vin/textarea.vue";
</script>
<template>
<Textarea label="Message" :rows="3" placeholder="How can we help?" hint="We usually reply within a day." style="width: 100%; max-width: 360px" />
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Textarea from "$lib/components/vin/textarea.svelte";
</script>
<Textarea label="Message" rows={3} placeholder="How can we help?" hint="We usually reply within a day." style="width: 100%; max-width: 360px" />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
<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>Shown on your profile.
32 / 160
import { Textarea } from "@/components/vin/textarea";
export function TextareaCount() {
return (
<Textarea
label="Bio"
rows={3}
maxLength={160}
defaultValue="Designer and developer in Delhi."
hint="Shown on your profile."
style={{ width: "100%", maxWidth: 360 }}
/>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import Textarea from "@/components/vin/textarea.vue";
</script>
<template>
<Textarea
label="Bio"
:rows="3"
:maxlength="160"
default-value="Designer and developer in Delhi."
hint="Shown on your profile."
style="width: 100%; max-width: 360px"
/>
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Textarea from "$lib/components/vin/textarea.svelte";
</script>
<Textarea
label="Bio"
rows={3}
maxlength={160}
value="Designer and developer in Delhi."
hint="Shown on your profile."
style="width: 100%; max-width: 360px"
/>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.
<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>Grows as you type.
import { Textarea } from "@/components/vin/textarea";
export function TextareaAuto() {
return <Textarea label="Notes" rows={2} autoResize placeholder="Start typing…" hint="Grows as you type." style={{ width: "100%", maxWidth: 360 }} />;
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import Textarea from "@/components/vin/textarea.vue";
</script>
<template>
<Textarea label="Notes" :rows="2" auto-resize placeholder="Start typing…" hint="Grows as you type." style="width: 100%; max-width: 360px" />
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Textarea from "$lib/components/vin/textarea.svelte";
</script>
<Textarea label="Notes" rows={2} autoResize placeholder="Start typing…" hint="Grows as you type." style="width: 100%; max-width: 360px" />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:
npx @vinish/ui add textareaimport { Textarea } from "@/components/vin/textarea";import Textarea from "@/components/vin/textarea.vue";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.
| Prop | Values | Default | In HTML |
|---|---|---|---|
labelVisible label. Without it, pass an aria-label. | ReactNode | — | <label class="vin-label" for="…"> |
hintHelp text under the field. | ReactNode | — | <p class="vin-hint"> inside .vin-textarea__foot |
errorAn error message. Also marks the textarea invalid. | ReactNode | — | <p class="vin-error"> + aria-invalid="true" |
maxLengthLimit, shown as a count under the field. | number | — | maxlength + data-vin-textarea="<count id>" + vinui.js |
showCountShow the count. On by default when maxLength is set. | boolean | — | <p class="vin-textarea__count"> |
autoResizeGrow with the text, up to 260px, then scroll. | boolean | false | vin-textarea--auto |
disabled | boolean | false | disabled attribute |
Parts
| React, Vue, Svelte | HTML 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.
Customize
Saved in this browser. Style and accent are in the header.