Skip to content
Nana UI

Forms & Inputs

Textarea

A <nana-textarea> element.

View .md Download

Seen only by your team.

0 / 200

Install the package for a versioned dependency:

npm install @nana-tec/ui-components

Or copy the source in and own it:

npx @nana-tec/ui add textarea --framework web-components
npx @nana-tec/ui add textarea --framework svelte

Lands in src/lib/components/ui/textarea/ as NanaTextarea.svelte, styled with Tailwind classes that resolve to the design tokens. Requires Tailwind v4.

Import the autoloader once, in your app's entry point. Every <nana-*> tag then works anywhere, and each component downloads only the first time a page uses it:

import "@nana-tec/ui-components/autoloader";
import "@nana-tec/ui-components/theme";

The second line gives every component the Nana look and the design tokens behind it. Leave it out to style the components entirely yourself.

Import a component directly when it must be ready at once: on screen at first paint, or when you call its methods straight away. The two mix freely:

import "@nana-tec/ui-components/textarea";

Copied in with npx @nana-tec/ui add textarea? Import your project's own @/lib/nana-ui/autoloader.js once instead; the CLI keeps it up to date.

<script lang="ts">
import { NanaTextarea } from '$lib/components/ui/textarea';
let notes = $state('');
</script>
<NanaTextarea label="Notes" bind:value={notes} maxlength={200} showCount />

A real <textarea> with its label, help and error wired the same way as Input. autoGrow lets it grow with its text; showWordCount counts words instead of characters. value is $bindable.

<nana-textarea label="Message" placeholder="Write something…" rows="3" style="min-width:18rem"></nana-textarea>

Properties

PropertyAttributeTypeDefaultDescription
autocompleteautocompleteHTMLTextAreaElement['autocomplete']'off'Passed to the inner control as the native autocomplete hint.
autoGrowauto-growbooleanfalseGrows the field with its content instead of scrolling.
disableddisabledbooleanfalseBlocks interaction and leaves the value out of form submission.
errorMessageerror-messagestring''Error under the field while it is invalid, in the error part with role="alert".
helperTexthelper-textstring''Text under the field, in the help part.
inputIdinputId——Id of the inner control. Generated when not set.
invalidinvalidbooleanfalseMarks the field invalid and shows error-message in place of the helper text.
labellabelstring''Visible label for the field.
maxHeightmax-heightnumber | undefined—Height in pixels at which auto-grow stops and the field scrolls.
maxlengthmaxlengthnumber | undefined—Most characters the field accepts.
minlengthminlengthnumber | undefined—Fewest characters the field accepts before it is valid.
namenamestring''Name the value is submitted under in a form.
placeholderplaceholderstring''Hint text shown while the field is empty.
readonlyreadonlybooleanfalseThe value can be read and copied but not changed.
requiredrequiredbooleanfalseThe form will not submit while this has no value.
resizeresize'none' | 'vertical''vertical'How the reader can resize the field. Auto-grow sizes it instead, so it turns this off.
rowsrowsnumber4Visible lines of text before the field scrolls or grows.
showWordCountshow-word-countbooleanfalseShows a live word count under the field.
spellcheckspellcheckbooleanfalseLets the browser check spelling.
successsuccessbooleanfalseMarks the value as accepted and shows a confirmation under the field.
valuevaluestring''The current value.
wrapwrapHTMLTextAreaElement['wrap'] | undefined—How lines wrap when submitted, as on <textarea>.

Methods

MethodDescription
blur(): voidRemove focus from the text area
focus(options?: FocusOptions): voidFocus the text area

Events

EventDescription
nana-inputFired on every keystroke (detail.value)
nana-changeFired when the value is committed (detail.value)
nana-focusFired when the field gains focus
nana-blurFired when the field loses focus

Slots

SlotDescription
labelReplaces the label attribute with rich content

CSS parts

PartDescription
::part(textarea)The underlying <textarea> element; carries invalid, grow, resize-none, success, warning
::part(counter)The character / word counter
::part(footer)The row under the field holding the message and the counters
::part(field)The field
::part(label-row)The label row
::part(field-label)The field label
::part(required-badge)The required badge
::part(message)The line under the field; carries error, success or help
::part(error)The error message
::part(help)The helper text
::part(counts)The counts
::part(word-count)The word count

CSS custom properties

PropertyDescription
--nana-input-radiusCorner radius, shared with the other form fields
--nana-textarea-min-heightMinimum height before auto-grow takes over

NanaTextarea

PropTypeDefault
valuebind:string''
labelstring
helperTextstring
errorMessagestring
invalidbooleanfalse
resize'none' | 'vertical''vertical'
autoGrowbooleanfalse
showCountbooleanfalse
showWordCountbooleanfalse
onValueChange(value: string) => void

Also accepts Omit<HTMLTextareaAttributes, 'class' | 'value'>.