Textarea

Multi-line text input with cursor, selection, and rich keybindings.

Basic usage

Renderable API

import { TextareaRenderable, createCliRenderer } from "@opentui/core"

const renderer = await createCliRenderer()

const textarea = new TextareaRenderable(renderer, {
  id: "notes",
  width: 50,
  height: 6,
  placeholder: "Type notes here...",
  backgroundColor: "#1a1a1a",
  focusedBackgroundColor: "#222222",
  textColor: "#FFFFFF",
  cursorColor: "#00FF88",
})

renderer.root.add(textarea)
textarea.focus()

Submit handling

Bind a submit action and listen for onSubmit:

import { TextareaRenderable } from "@opentui/core"

const textarea = new TextareaRenderable(renderer, {
  width: 50,
  height: 6,
  onSubmit: () => {
    console.log("Submitted:", textarea.plainText)
  },
  keyBindings: [{ name: "return", ctrl: true, action: "submit" }],
})

Placeholder styling

const textarea = new TextareaRenderable(renderer, {
  width: 40,
  height: 4,
  placeholder: "Type here",
  placeholderColor: "#666666",
})

Construct API

Not available yet. Use TextareaRenderable for now.

Properties

PropertyTypeDefaultDescription
widthnumber or string-Width in characters or percentage
heightnumber or string-Height in rows or percentage
initialValuestring""Initial text content
placeholderstring, StyledText, or nullnullPlaceholder content
placeholderColorstring or RGBA#666666Placeholder color
backgroundColorstring or RGBAtransparentBackground when unfocused
textColorstring or RGBA#FFFFFFText color when unfocused
focusedBackgroundColorstring or RGBAtransparentBackground when focused
focusedTextColorstring or RGBA#FFFFFFText color when focused
wrapMode"none", "char", or "word""word"Line wrapping mode
selectionBgstring or RGBA-Selection background
selectionFgstring or RGBA-Selection foreground
cursorColorstring or RGBA#FFFFFFCursor color
cursorStyleCursorStyleOptions-Cursor style and blinking
keyBindingsKeyBinding[]-Custom keybindings
keyAliasMapKeyAliasMap-Key alias mapping
onSubmit(event: SubmitEvent) => void-Submit handler
onContentChange(event: ContentChangeEvent) => void-Fired on content changes
onCursorChange(event: CursorChangeEvent) => void-Fired on cursor movement

Useful properties

PropertyTypeDescription
plainTextstringCurrent text content
cursorOffsetnumberCursor offset in the buffer