Skip to content

TextInput

Full readline-style single-line text input with kill ring, word movement, and all standard shortcuts. Built on the useReadline hook.

Import

tsx
import { TextInput } 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 when Enter is pressed
onEOF() => void--Called on Ctrl+D with empty input
placeholderstring""Placeholder text when empty
isActiveboolean--Whether input is focused/active (overrides focus system)
promptstring""Prompt prefix (e.g., "$ " or "> ")
promptColorstring"$control"Prompt color
colorstring--Text color
cursorStyle"block" | "underline""block"Cursor style
showUnderlinebooleanfalseShow underline below input
underlineWidthnumber40Underline width
maskstring--Mask character for passwords
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: TextInputHandle

ts
interface TextInputHandle {
  clear: () => void
  getValue: () => string
  setValue: (value: string) => void
  getKillRing: () => string[]
}

Keyboard Shortcuts

KeyAction
Ctrl+A / HomeBeginning of line
Ctrl+E / EndEnd of line
Ctrl+B / LeftMove cursor left
Ctrl+F / RightMove cursor right
Alt+BMove word backwards
Alt+FMove word forwards
Ctrl+W / Alt+BackspaceDelete word backwards (kill)
Alt+DDelete word forwards (kill)
Ctrl+UDelete to beginning (kill)
Ctrl+KDelete to end (kill)
Ctrl+YYank (paste from kill ring)
Alt+YCycle kill ring
Ctrl+TTranspose characters

Usage

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

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

// With border and prompt
<TextInput
  value={query}
  onChange={setQuery}
  prompt="/ "
  borderStyle="round"
  placeholder="Search..."
/>

// Password input
<TextInput value={password} onChange={setPassword} mask="*" />

See Also

Released under the MIT License.