Skip to content

TextArea

Multi-line text input with word wrapping, scrolling, selection, and cursor movement. Uses useContentRect for width-aware word wrapping and scroll tracking to keep the cursor visible. Built on the useTextArea hook.

Import

tsx
import { TextArea } from "silvery"

Props

PropTypeDefaultDescription
valuestring--Current value (controlled mode)
defaultValuestring""Initial value (uncontrolled mode)
onChange(value: string) => void--Called when value changes
onSubmit(value: string) => void--Called on submit
submitKey"ctrl+enter" | "enter" | "meta+enter""ctrl+enter"Key to trigger submit
placeholderstring""Placeholder text when empty
isActiveboolean--Whether input is focused/active (overrides focus system)
heightnumberrequiredVisible height in rows
cursorStyle"block" | "underline""block"Cursor style
scrollMarginnumber1Context lines above/below cursor when scrolling
disabledboolean--Ignore all input and dim text
maxLengthnumber--Maximum number of characters allowed
borderStylestring--Border style (wraps input in bordered Box)
borderColorstring"$border"Border color when unfocused
focusBorderColorstring"$focusborder"Border color when focused
testIDstring--Test ID for focus system identification

Ref: TextAreaHandle

ts
interface TextAreaHandle {
  clear: () => void
  getValue: () => string
  setValue: (value: string) => void
  getSelection: () => TextAreaSelection | null
}

type TextAreaSelection = { start: number; end: number }

Keyboard Shortcuts

KeyAction
Arrow keysMove cursor (clears selection)
Shift+ArrowExtend selection
Shift+Home/EndSelect to line boundaries
Ctrl+Shift+ArrowWord-wise selection
Ctrl+ASelect all text
Ctrl+EEnd of line
Home/EndBeginning/end of line
Alt+B/FMove by word (wraps across lines)
Ctrl+W / Alt+BackspaceDelete word backwards (kill ring)
Alt+DDelete word forwards (kill ring)
Ctrl+KKill to end of line
Ctrl+UKill to beginning of line
Ctrl+YYank (paste from kill ring)
Alt+YCycle kill ring
Ctrl+TTranspose characters
PageUp/PageDownScroll by viewport height

Usage

tsx
const [value, setValue] = useState('')

<TextArea
  value={value}
  onChange={setValue}
  onSubmit={(val) => console.log('Submitted:', val)}
  height={10}
  placeholder="Type here..."
/>

See Also

Released under the MIT License.