Skip to content

TextArea

Multi-line text input with word wrapping, scrolling, selection, and full readline-style editing. Built on the same kill ring and word movement as TextInput.

Import

tsx
import { TextArea } from "silvery"

Usage

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

<TextArea
  value={value}
  onChange={setValue}
  height={10}
  placeholder="Type here..."
/>

Props

PropTypeDefaultDescription
valuestringCurrent value (controlled mode)
defaultValuestring""Initial value (uncontrolled mode)
onChange(value: string) => voidCalled when value changes
onSubmit(value: string) => voidCalled on submit key combo
submitKey"ctrl+enter" | "enter" | "meta+enter""ctrl+enter"Key to trigger submit
placeholderstring""Placeholder text when empty
isActivebooleanOverride focus system for input capture
heightnumberrequiredVisible height in rows
cursorStyle"block" | "underline""block"Visual cursor style when unfocused
scrollMarginnumber1Context lines above/below cursor when scrolling
disabledbooleanIgnore input and dim text
maxLengthnumberMaximum characters allowed
borderStylestringBorder style (e.g., "round", "single")
borderColorstring"$border"Border color when unfocused
focusBorderColorstring"$focusborder"Border color when focused
testIDstringTest ID for focus system identification

Ref Handle (TextAreaHandle)

Access via useRef<TextAreaHandle>():

MethodTypeDescription
clear()() => voidClear the input
getValue()() => stringGet current value
setValue(value)(value: string) => voidSet value programmatically
getSelection()() => TextAreaSelection | nullGet current selection range

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 / Alt+FMove by word
Ctrl+W / Alt+BackspaceKill word backward
Alt+DKill word forward
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

Examples

Chat Input with Enter to Submit

tsx
<TextArea
  value={message}
  onChange={setMessage}
  onSubmit={sendMessage}
  submitKey="enter"
  height={3}
  placeholder="Type a message..."
/>

With submitKey="enter", pressing Enter submits. Use Shift+Enter or the default "ctrl+enter" for newlines.

Bordered Editor

tsx
<TextArea value={content} onChange={setContent} height={15} borderStyle="round" placeholder="Write your note..." />

Disabled State

tsx
<TextArea value={readOnlyContent} height={10} disabled />

When disabled, text is dimmed and all input is ignored.

Released under the MIT License.