Socket
Socket
Sign inDemoInstall

ink-text-input

Package Overview
Dependencies
2
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ink-text-input

Text input component for Ink


Version published
Weekly downloads
99K
decreased by-14.2%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

ink-text-input Build Status

Text input component for Ink.

Install

$ npm install --save ink-text-input

Usage

const {h, Component} = require('ink');
const TextInput = require('ink-text-input');

class SearchQuery extends Component {
	constructor() {
		super();

		this.state = {
			query: ''
		};

		this.handleChange = this.handleChange.bind(this);
		this.handleSubmit = this.handleSubmit.bind(this);
	}

	render(props, state) {
		return (
			<div>
				Enter your query:

				<TextInput
					value={state.query}
					onChange={this.handleChange}
					onSubmit={this.handleSubmit}
				/>
			</div>
		);
	}

	handleChange(value) {
		this.setState({
			query: value
		});
	}

	handleSubmit(value) {
		// query submitted
	}
}

mount(<SearchQuery/>);

Note: For <TextInput> to be able to receive keypress events, process.stdin must be in raw mode. As a result, default behavior like Ctrl+C is disabled, so you must handle that manually.

Use this snippet to enable keypress events:

readline.emitKeypressEvents(process.stdin);
process.stdin.setRawMode(true);

Props

value

Type: string

Value to display in a text input.

placeholder

Type: string

Text to display when value is empty.

onChange

Type: function

Function to call when value updates.

onSubmit

Type: function

Function to call when user presses Enter.

License

MIT © Vadim Demedes

Keywords

FAQs

Last updated on 09 Jul 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc