---
title: "Textarea"
description: "Textarea with accessible presentation and local state."
---

# Textarea

Textarea with accessible presentation and local state.

## Installation

Install the shared package once in your Exact app. This version is a beta.

```sh
bun add --exact @rightui/ui@0.4.0-beta.4
```

Or choose another package manager:

```sh
npm install --save-exact @rightui/ui@0.4.0-beta.4
pnpm add --save-exact @rightui/ui@0.4.0-beta.4
yarn add --exact @rightui/ui@0.4.0-beta.4
```

Exact compilation uses Bun 1.4.2. Register Geist and Newsreader, declare the font marker and add the root provider using [Installation](/docs/installation).

### Manual source setup

Install an editable copy of the complete package:

```sh
mkdir -p vendor/rightui vendor/rightui-ui
npm pack @rightui/ui@0.4.0-beta.4 --pack-destination vendor/rightui
tar -xzf ./vendor/rightui/rightui-ui-0.4.0-beta.4.tgz -C vendor/rightui-ui --strip-components=1
bun add file:./vendor/rightui-ui
```

Keep package.json, the Contract files, ui.tamber, assets and licenses together.

### Import

```contract
use Textarea from "@rightui/ui"
```

## Usage

Import Textarea from @rightui/ui. Store its value in state and update it through the provided action callback.

## Example

```contract
use FontWeights from "@rightui/ui"
use uiFontFamily, Textarea, Field, Button from "@rightui/ui"

component Demo
  props
    width: number
    reduced: bool
  inject
    uiWeights: FontWeights
    uiFont: string
  derive narrow = width < 600
  state notes = ""
  action editNotes(v: string)
    notes = v
  state savedBrief = ""
  action saveBrief
    savedBrief = notes == "" ? "Add a brief first." : "Brief saved locally."
  view
    column gap="ui.space-16" min-width=0 max-width="100%"
      Textarea(id="catalog-notes", label="Notes", value=notes, placeholder="Describe your project…", error="", disabled=false, edit=editNotes)
      Textarea(id="catalog-textarea-invalid", label="Invalid textarea", value=notes, placeholder="Required", error="This field is required.", disabled=false, edit=editNotes)
      Textarea(id="catalog-textarea-disabled", label="Disabled textarea", value="Read only preview", placeholder="", error="", disabled=true, edit=editNotes)
      text "Field description and submit action" font-size="ui.text-sm" font-weight=uiWeights.semibold font-family=uiFontFamily(uiFont) data-rightui-font="body"
      Field(id="variation-textarea-field", description="Include timing and delivery preferences.", error="")
        Textarea(id="variation-textarea-described", label="Project brief", value=notes, placeholder="Your brief", error="", disabled=false, edit=editNotes)
      Button(id="variation-textarea-submit", label="Save brief", variant="outline", disabled=false, press=saveBrief)
      text savedBrief role="status" font-family=uiFontFamily(uiFont) data-rightui-font="body"

```

## API Reference

| Property | Type |
| --- | --- |
| Textarea.id | string |
| Textarea.label | string |
| Textarea.value | string |
| Textarea.placeholder | string |
| Textarea.error | string |
| Textarea.disabled | bool |
| Textarea.edit | action |

## Source

File: packages/ui/forms.contract

```contract
use FontWeights from "./typography-context.contract"
use uiFontFamily from "./typography-context.contract"
use Control, Field as FieldStyle from "./styles.contract"
component Label
  props
    id: string
    text: string
    required: bool
  inject
    uiWeights: FontWeights
    uiFont: string
  view
    text (text + (required ? " *" : "")) id=id font-size="ui.text-sm" font-weight=uiWeights.medium color="ui.foreground" font-family=uiFontFamily(uiFont) data-rightui-font="body"

component Field
  props
    id: string
    description: string
    error: string
  inject
    uiFont: string
  slot
  view
    column gap="ui.space-8" min-width="0px" role="group" aria-describedby=(id + "-hint")
      children
      text (error != "" ? error : description) id=(id + "-hint") testId=(id + "-hint") font-size="ui.text-xs" line-height="ui.leading-normal" color=(error != "" ? "ui.danger" : "ui.muted-foreground") font-family=uiFontFamily(uiFont) data-rightui-font="body"

component Textarea
  props
    id: string
    label: string
    value: string
    placeholder: string
    error: string
    disabled: bool
    edit: action
  inject
    uiFont: string
  view
    column gap="ui.space-8" min-width="0px"
      Label(id=id + "-label", text=label, required=false)
      TextareaControl(id=id, label=label, value=value, placeholder=placeholder, error=error, descriptionId=id + "-error", disabled=disabled, edit=edit)
      text error id=(id + "-error") font-size="ui.text-xs" color="ui.danger" display=(error == "" ? "none" : "block") font-family=uiFontFamily(uiFont) data-rightui-font="body"

component RadioGroup
  props
    id: string
    label: string
    options: string[]
    value: string
    disabled: bool
    required: bool
    descriptionId: string
    change: action
  view
    RadioGroupAdvanced(id=id, label=label, options=options, value=value, disabled=disabled, required=required, descriptionId=descriptionId, change=change, variant="default")

component RadioGroupAdvanced
  props
    id: string
    label: string
    options: string[]
    value: string
    disabled: bool
    required: bool
    descriptionId: string
    change: action
    variant: string
  inject
    uiWeights: FontWeights
    uiFont: string
  action pick(i: number)
    if not disabled
      match options.at(i)
        case some(v)
          change(v)
          focus(id + "-" + i.toString())
        case none
          preventDefault()
  action keys(k: string)
    if not disabled and options.length > 0 and (k == "ArrowDown" or k == "ArrowRight" or k == "ArrowUp" or k == "ArrowLeft" or k == "Home" or k == "End")
      preventDefault()
      let index = max(0, options.indexOf(value))
      pick(k == "Home" ? 0 : k == "End" ? options.length - 1 : (index + (k == "ArrowDown" or k == "ArrowRight" ? 1 : options.length - 1)) % options.length)
  view
    view id=id testId=id role="radiogroup" aria-label=label aria-required=required aria-describedby=descriptionId
      display="flex" flex-direction=(variant == "segmented" ? "row" : "column") flex-wrap=(variant == "segmented" ? "wrap" : "nowrap") min-width="0px"
      gap=(variant == "segmented" ? "ui.space-4" : "ui.space-12") padding=(variant == "segmented" ? "ui.space-4" : "0px")
      border-radius=(variant == "segmented" ? "ui.radius-control" : "0px") background-color=(variant == "segmented" ? "ui.muted" : "transparent")
      for option, i in options key=option
        button id=(id + "-" + i.toString()) testId=(id + "-" + i.toString()) class=Control font-weight=uiWeights.medium role="radio" aria-checked=(value == option)
          tabindex=(value == option or (options.indexOf(value) == -1 and i == 0) ? 0 : -1) disabled=disabled press=pick(i) key=keys
          display="flex" align-items="center" justify-content=(variant == "segmented" ? "center" : "flex-start") gap="ui.space-8" flex=(variant == "segmented" ? "1 1 auto" : "0 1 auto")
          padding=(variant == "segmented" ? "ui.space-6 ui.space-8" : "0px") min-height=(variant == "segmented" ? "ui.control-sm" : "ui.space-20")
          border-width=(variant == "segmented" ? "ui.border-width" : "0px") border-style="solid" border-color=(variant == "segmented" and value == option ? "ui.tab-active-border" : "transparent")
          background-color=(variant == "segmented" and value == option ? "ui.tab-active" : "transparent") color="ui.foreground" box-shadow=(variant == "segmented" and value == option ? "ui.shadow-control" : "none")
          if variant != "segmented"
            RadioIndicator(checked=(value == option))
          text option font-size=(variant == "segmented" ? "ui.text-xs" : "ui.text-sm") text-align=(variant == "segmented" ? "center" : "left") font-family=uiFontFamily(uiFont) data-rightui-font="body"

component Toggle
  props
    id: string
    label: string
    pressed: bool
    disabled: bool
    reduced: bool
    change: action
  inject
    uiWeights: FontWeights
    uiFont: string
  action toggle
    if not disabled
      change(not pressed)
  view
    button id=id testId=id class=Control font-weight=uiWeights.medium aria-pressed=pressed disabled=disabled press=toggle
      padding="0px ui.space-8" min-width="ui.space-36" height="ui.space-36" border-width="ui.border-width" border-style="solid" border-color="ui.border" background-color=(pressed ? "ui.muted" : "transparent") color="ui.foreground"
      transition=(reduced ? "none" : "background-color ui.duration-fast ui.easing")
      text label font-family=uiFontFamily(uiFont) data-rightui-font="body"

component ToggleGroup
  props
    id: string
    label: string
    options: string[]
    selected: string[]
    disabled: bool
    reduced: bool
    change: action
  inject
    uiWeights: FontWeights
    uiFont: string
  action toggle(value: string)
    if not disabled
      change(selected.includes(value) ? selected.filter(item => item != value) : selected.concat([value]))
  action keys(i: number, k: string)
    if k == "Enter" or k == " "
      preventDefault()
      match options.at(i)
        case some(v)
          toggle(v)
        case none
          preventDefault()
    else if k == "ArrowRight" or k == "ArrowLeft" or k == "Home" or k == "End"
      preventDefault()
      let next = (k == "Home" ? 0 : k == "End" ? options.length - 1 : (i + (k == "ArrowRight" ? 1 : options.length - 1)) % max(1, options.length))
      focus(id + "-" + next.toString())
  view
    row id=id testId=id role="group" aria-label=label gap="ui.space-4" flex-wrap="wrap"
      for option, i in options key=option
        button id=(id + "-" + i.toString()) testId=(id + "-" + i.toString()) class=Control font-weight=uiWeights.medium aria-pressed=selected.includes(option) disabled=disabled press=toggle(option) key=keys(i)
          padding="0px ui.space-8" min-width="ui.space-36" height="ui.space-36" border-width="ui.border-width" border-style="solid" border-color="ui.border" background-color=(selected.includes(option) ? "ui.muted" : "transparent") color="ui.foreground"
          transition=(reduced ? "none" : "background-color ui.duration-fast ui.easing")
          text option font-family=uiFontFamily(uiFont) data-rightui-font="body"

component TextareaControl
  props
    id: string
    label: string
    value: string
    placeholder: string
    error: string
    descriptionId: string
    disabled: bool
    edit: action
  inject
    uiFont: string
  view
    textarea id=id testId=id class=FieldStyle value=value input=edit placeholder=placeholder disabled=disabled font-family=uiFontFamily(uiFont) data-rightui-font="body"
      aria-label=label aria-invalid=(error != "") aria-describedby=descriptionId
      min-height="ui.space-64" max-height="20rem" resize="vertical"

component RadioControl
  props
    id: string
    label: string
    checked: bool
    disabled: bool
    tabIndex: number
    press: action
    keys: action
  inject
    uiWeights: FontWeights
  view
    button id=id testId=id class=Control font-weight=uiWeights.medium role="radio" aria-label=label aria-checked=checked tabindex=tabIndex disabled=disabled press=press key=keys
      display="flex" align-items="center" justify-content="center" padding="0px" min-height="ui.touch-target" min-width="ui.touch-target" border="0" background-color="transparent" color="ui.foreground"
      RadioIndicator(checked=checked)

component RadioIndicator
  props
    checked: bool
  view
    view width="ui.space-16" height="ui.space-16" flex-shrink=0 border-radius="ui.radius-full" border-width="ui.border-width" border-style="solid" border-color=(checked ? "ui.primary" : "ui.border") display="flex" align-items="center" justify-content="center" aria-hidden=true
      if checked
        view width="ui.space-8" height="ui.space-8" border-radius="ui.radius-full" background-color="ui.primary"

```
