Skip to content

TextInput

Full readline-style single-line text input with kill ring, word movement, cursor positioning, and password masking.

Import

tsx
import { TextInput } from "silvery"

Usage

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

<TextInput
  value={value}
  onChange={setValue}
  onSubmit={(val) => console.log("Submitted:", val)}
  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 when Enter is pressed
onEOF() => voidCalled on Ctrl+D with empty input
placeholderstring""Placeholder text when empty
isActivebooleanOverride focus system for input capture
promptstring""Prompt prefix (e.g., "$ " or "> ")
promptColorstring"$control"Prompt color
colorstringText color
cursorStyle"block" | "underline""block"Visual cursor style when unfocused
showUnderlinebooleanfalseShow underline decoration below input
underlineWidthnumber40Width of the underline decoration
maskstringMask character for passwords (e.g., "*")
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 (TextInputHandle)

Access via useRef<TextInputHandle>():

MethodTypeDescription
clear()() => voidClear the input
getValue()() => stringGet current value
setValue(value)(value: string) => voidSet value programmatically
getKillRing()() => string[]Get kill ring contents

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 backward
Alt+FMove word forward
Ctrl+W / Alt+BackspaceKill word backward
Alt+DKill word forward
Ctrl+UKill to beginning of line
Ctrl+KKill to end of line
Ctrl+YYank (paste from kill ring)
Alt+YCycle kill ring
Ctrl+TTranspose characters

Examples

With Border

tsx
<TextInput value={search} onChange={setSearch} placeholder="Search..." borderStyle="round" />

The border color automatically changes between borderColor and focusBorderColor based on focus state.

Password Input

tsx
<TextInput value={password} onChange={setPassword} onSubmit={handleLogin} mask="*" placeholder="Password" />

With Prompt

tsx
<TextInput value={command} onChange={setCommand} onSubmit={executeCommand} prompt="$ " promptColor="$success" />

Released under the MIT License.