Textarea
A labeled multiline field that grows with its rows.
31 of 200 characters
Source
<script lang="ts">
import 'portal-bits/styles.css';
import 'portal-bits/tokens.css';
import type { Snippet } from 'svelte';
let { children }: { children: Snippet } = $props();
</script>
{@render children()}
<script lang="ts">
import TextareaExample from './TextareaExample.svelte';
</script>
<TextareaExample invalid={false} disabled={false} required={false} />
<script lang="ts">
import { Alert, Textarea } from 'portal-bits';
let {
invalid = false,
disabled = false,
required = false,
}: { invalid?: boolean; disabled?: boolean; required?: boolean } = $props();
let note = $state('Pick up the prints on Thursday.');
</script>
<div class="field">
<Textarea
label="Project note"
placeholder="What should the team know?"
bind:value={note}
{invalid}
{disabled}
{required}
maxlength={200}
aria-describedby={invalid ? 'note-error' : 'note-count'}
/>
{#if invalid}
<Alert id="note-error" message="Keep the note under 200 characters." />
{:else}
<p id="note-count">{note.length} of 200 characters</p>
{/if}
</div>
<style>
.field {
width: 360px;
max-width: 100%;
}
p {
margin: 8px 0 0;
color: var(--portal-muted);
font-size: 13px;
font-variant-numeric: tabular-nums;
}
</style>
API reference
These tables list the props and snippets that Textarea declares. Attributes passed through to an element or primitive are listed under Forwarded attributes, not here.
Props
| Name | Type | Default | Required | Binding | Description |
|---|---|---|---|---|---|
label | string | None | Yes | One-way | The visible label, tied to the field with `for`. |
hideLabel | boolean | false | No | One-way | Keeps the label for assistive technology only. |
invalid | boolean | false | No | One-way | Sets `aria-invalid`. Render the error text yourself. |
value | string | "" | No | Bindable | The field value. |
rows | number | 4 | No | One-way | Visible text lines before the field scrolls. |
id | string | Generated id | No | One-way | The textarea id. A stable id is generated when you omit it. |
class | string | "" | No | One-way | Extra classes, added after the component classes. |
Forwarded attributes
- Native textarea attributes except `value`: `name`, `placeholder`, `maxlength`, `disabled`, `required`, `aria-*`, and handlers. They land on the `textarea` element.
No data attributes are documented as stable.
Limits
- The 16px corner and 96px minimum height are an adaptation. Single-line fields keep the measured 32px pill.
- The field resizes vertically only. It does not grow with its content.