({
inputState,
children,
terminalFocus,
invert,
hidePlaceholderText,
...props
}: BaseTextInputComponentProps)
| 20 | * A base component for text inputs that handles rendering and basic input |
| 21 | */ |
| 22 | export function BaseTextInput({ |
| 23 | inputState, |
| 24 | children, |
| 25 | terminalFocus, |
| 26 | invert, |
| 27 | hidePlaceholderText, |
| 28 | ...props |
| 29 | }: BaseTextInputComponentProps): React.ReactNode { |
| 30 | const { onInput, renderedValue, cursorLine, cursorColumn } = inputState; |
| 31 | |
| 32 | // Park the native terminal cursor at the input caret. Terminal emulators |
| 33 | // position IME preedit text at the physical cursor, and screen readers / |
| 34 | // screen magnifiers track it — so parking here makes CJK input appear |
| 35 | // inline and lets accessibility tools follow the input. The Box ref below |
| 36 | // is the yoga layout origin; (cursorLine, cursorColumn) is relative to it. |
| 37 | // Only active when the input is focused, showing its cursor, and the |
| 38 | // terminal itself has focus. |
| 39 | const cursorRef = useDeclaredCursor({ |
| 40 | line: cursorLine, |
| 41 | column: cursorColumn, |
| 42 | active: Boolean(props.focus && props.showCursor && terminalFocus), |
| 43 | }); |
| 44 | |
| 45 | const { wrappedOnInput, isPasting } = usePasteHandler({ |
| 46 | onPaste: props.onPaste, |
| 47 | onInput: (input, key) => { |
| 48 | // Prevent Enter key from triggering submission during paste |
| 49 | if (isPasting && key.return) { |
| 50 | return; |
| 51 | } |
| 52 | onInput(input, key); |
| 53 | }, |
| 54 | onImagePaste: props.onImagePaste, |
| 55 | }); |
| 56 | |
| 57 | // Notify parent when paste state changes |
| 58 | const { onIsPastingChange } = props; |
| 59 | React.useEffect(() => { |
| 60 | if (onIsPastingChange) { |
| 61 | onIsPastingChange(isPasting); |
| 62 | } |
| 63 | }, [isPasting, onIsPastingChange]); |
| 64 | |
| 65 | const { showPlaceholder, renderedPlaceholder } = renderPlaceholder({ |
| 66 | placeholder: props.placeholder, |
| 67 | value: props.value, |
| 68 | showCursor: props.showCursor, |
| 69 | focus: props.focus, |
| 70 | terminalFocus, |
| 71 | invert, |
| 72 | hidePlaceholderText, |
| 73 | }); |
| 74 | |
| 75 | useInput(wrappedOnInput, { isActive: props.focus }); |
| 76 | |
| 77 | // Show argument hint only when we have a value and the hint is provided |
| 78 | // Only show the argument hint when: |
| 79 | // 1. We have a hint to show |
nothing calls this directly
no test coverage detected