Forms & Inputs
Textarea
A <nana-textarea> element.
Preview
Section titled “Preview”<nana-textarea
label="Message"
placeholder="Write something…"
rows="3"
style="min-width: 18rem"
></nana-textarea> Seen only by your team.
0 / 200Tell the tenant why.
<script lang="ts">
import { NanaTextarea } from '$lib/components/ui/textarea';
let notes = $state('');
</script>
<div class="flex w-full max-w-md flex-col gap-5">
<NanaTextarea
label="Notes"
bind:value={notes}
maxlength={200}
showCount
helperText="Seen only by your team."
/>
<NanaTextarea label="Reason" required invalid errorMessage="Tell the tenant why." rows={3} />
</div> Installation
Section titled “Installation”Install the package for a versioned dependency:
npm install @nana-tec/ui-componentsOr copy the source in and own it:
npx @nana-tec/ui add textarea --framework web-componentsnpx @nana-tec/ui add textarea --framework svelteLands in src/lib/components/ui/textarea/ as NanaTextarea.svelte, styled with Tailwind
classes that resolve to the design tokens. Requires Tailwind v4.
Import
Section titled “Import”
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.
Basic usage
Section titled “Basic usage”<nana-textarea label="Message" placeholder="Write something…" rows="3" style="min-width:18rem"></nana-textarea>States
Section titled “States”<nana-textarea
label="Disabled"
placeholder="Cannot edit"
disabled
style="min-width: 20rem"
></nana-textarea>
<nana-textarea
label="Readonly"
value="Read-only content"
readonly
style="min-width: 20rem"
></nana-textarea>
<nana-textarea
label="Invalid"
value="bad value"
invalid
error-message="Please fix this field"
style="min-width: 20rem"
></nana-textarea> Properties
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
autocomplete | autocomplete | HTMLTextAreaElement['autocomplete'] | 'off' | Passed to the inner control as the native autocomplete hint. |
autoGrow | auto-grow | boolean | false | Grows the field with its content instead of scrolling. |
disabled | disabled | boolean | false | Blocks interaction and leaves the value out of form submission. |
errorMessage | error-message | string | '' | Error under the field while it is invalid, in the error part with role="alert". |
helperText | helper-text | string | '' | Text under the field, in the help part. |
inputId | inputId | — | — | Id of the inner control. Generated when not set. |
invalid | invalid | boolean | false | Marks the field invalid and shows error-message in place of the helper text. |
label | label | string | '' | Visible label for the field. |
maxHeight | max-height | number | undefined | — | Height in pixels at which auto-grow stops and the field scrolls. |
maxlength | maxlength | number | undefined | — | Most characters the field accepts. |
minlength | minlength | number | undefined | — | Fewest characters the field accepts before it is valid. |
name | name | string | '' | Name the value is submitted under in a form. |
placeholder | placeholder | string | '' | Hint text shown while the field is empty. |
readonly | readonly | boolean | false | The value can be read and copied but not changed. |
required | required | boolean | false | The form will not submit while this has no value. |
resize | resize | 'none' | 'vertical' | 'vertical' | How the reader can resize the field. Auto-grow sizes it instead, so it turns this off. |
rows | rows | number | 4 | Visible lines of text before the field scrolls or grows. |
showWordCount | show-word-count | boolean | false | Shows a live word count under the field. |
spellcheck | spellcheck | boolean | false | Lets the browser check spelling. |
success | success | boolean | false | Marks the value as accepted and shows a confirmation under the field. |
value | value | string | '' | The current value. |
wrap | wrap | HTMLTextAreaElement['wrap'] | undefined | — | How lines wrap when submitted, as on <textarea>. |
Methods
| Method | Description |
|---|---|
blur(): void | Remove focus from the text area |
focus(options?: FocusOptions): void | Focus the text area |
Events
| Event | Description |
|---|---|
nana-input | Fired on every keystroke (detail.value) |
nana-change | Fired when the value is committed (detail.value) |
nana-focus | Fired when the field gains focus |
nana-blur | Fired when the field loses focus |
Slots
| Slot | Description |
|---|---|
label | Replaces the label attribute with rich content |
CSS parts
| Part | Description |
|---|---|
::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
| Property | Description |
|---|---|
--nana-input-radius | Corner radius, shared with the other form fields |
--nana-textarea-min-height | Minimum height before auto-grow takes over |
NanaTextarea
| Prop | Type | Default |
|---|---|---|
valuebind: | string | '' |
label | string | |
helperText | string | |
errorMessage | string | |
invalid | boolean | false |
resize | 'none' | 'vertical' | 'vertical' |
autoGrow | boolean | false |
showCount | boolean | false |
showWordCount | boolean | false |
onValueChange | (value: string) => void |
Also accepts Omit<HTMLTextareaAttributes, 'class' | 'value'>.