# ink-text-input

> Text input component for Ink

Latest version **6.0.0** (published 2024-05-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install ink-text-input
pnpm add ink-text-input
yarn add ink-text-input
bun add ink-text-input
```

## Health

**Score 28/100 (F)** — status: abandoned.

Positive: has types package; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 6.0.0 |
| Published | 2024-05-14 |
| First published | 2017-07-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/ink-text-input) |
| Module format | ESM |
| Node | >=18 |
| Dependencies | 2 |
| Unpacked size | 14.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 183 |
| Author | Vadim Demedes |
| Maintainers | vdemedes |
| Keywords | ink, text, input, component, jsx, react, stdin, keypress, search, query |

## Links

- npm: https://www.npmjs.com/package/ink-text-input
- Repository: https://github.com/vadimdemedes/ink-text-input
- Homepage: https://github.com/vadimdemedes/ink-text-input#readme
- Issues: https://github.com/vadimdemedes/ink-text-input/issues
- npm.io page: https://npm.io/package/ink-text-input

## Dependencies (2)

- [chalk](https://npm.io/package/chalk.md) ^5.3.0
- [type-fest](https://npm.io/package/type-fest.md) ^4.18.2

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 6.0.0 (latest) — 2024-05-14
- 4.0.0-1 (next) — 2020-06-23
- 5.0.1 — 2023-04-02
- 5.0.0 — 2023-03-01
- 4.0.3 — 2022-02-03
- 4.0.2 — 2021-11-13
- 4.0.1 — 2020-09-19
- 4.0.0 — 2020-07-26
- 4.0.0-0 — 2020-06-23
- 3.3.0 — 2020-06-21
- 3.2.2 — 2020-01-12
- 3.2.1 — 2019-07-28
- 3.2.0 — 2019-06-01
- 3.1.1 — 2019-04-15
- 3.1.0 — 2019-03-23
- … 7 more at https://npm.io/package/ink-text-input/versions

## README

# ink-text-input ![test](https://github.com/vadimdemedes/ink-text-input/workflows/test/badge.svg)

> Text input component for [Ink](https://github.com/vadimdemedes/ink).

## Install

```sh
npm install ink-text-input
```

## Usage

```jsx
import React, {useState} from 'react';
import {render, Box, Text} from 'ink';
import TextInput from 'ink-text-input';

const SearchQuery = () => {
	const [query, setQuery] = useState('');

	return (
		<Box>
			<Box marginRight={1}>
				<Text>Enter your query:</Text>
			</Box>

			<TextInput value={query} onChange={setQuery} />
		</Box>
	);
};

render(<SearchQuery />);
```

<img src="media/demo.gif" width="556">

## Props

### value

Type: `string`

Value to display in a text input.

### placeholder

Type: `string`

Text to display when `value` is empty.

### focus

Type: `boolean` \
Default: `true`

Listen to user's input. Useful in case there are multiple input components at the same time and input must be "routed" to a specific component.

### showCursor

Type: `boolean`\
Default: `true`

Whether to show cursor and allow navigation inside text input with arrow keys.

### highlightPastedText

Type: `boolean`\
Default: `false`

Highlight pasted text.

### mask

Type: `string`

Replace all chars and mask the value. Useful for password inputs.

```jsx
<TextInput value="Hello" mask="*" />
//=> "*****"
```

### onChange

Type: `Function`

Function to call when value updates.

### onSubmit

Type: `Function`

Function to call when `Enter` is pressed, where first argument is a value of the input.

## Uncontrolled usage

This component also exposes an [uncontrolled](https://reactjs.org/docs/uncontrolled-components.html) version, which handles `value` changes for you. To receive the final input value, use `onSubmit` prop.
Initial value can be specified via `initialValue` prop, which is supported only in `UncontrolledTextInput` component.

```jsx
import React from 'react';
import {render, Box, Text} from 'ink';
import {UncontrolledTextInput} from 'ink-text-input';

const SearchQuery = () => {
	const handleSubmit = query => {
		// Do something with query
	};

	return (
		<Box>
			<Box marginRight={1}>
				<Text>Enter your query:</Text>
			</Box>

			<UncontrolledTextInput onSubmit={handleSubmit} />
		</Box>
	);
};

render(<SearchQuery />);
```

---
_Source: https://npm.io/package/ink-text-input · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
