Socket
Socket
Sign inDemoInstall

react-input-autosize

Package Overview
Dependencies
7
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-input-autosize

Auto-resizing Input Component for React


Version published
Maintainers
1
Install size
2.93 MB
Created

Package description

What is react-input-autosize?

The react-input-autosize package is a React component that automatically adjusts the width of the input field to fit the content typed by the user. This is particularly useful for tags input and other dynamic text inputs where the size of the content can change.

What are react-input-autosize's main functionalities?

Autosizing input field

This feature allows the input field to automatically resize based on the input content. The width of the input will grow or shrink as the user types or deletes content.

{"import AutosizeInput from 'react-input-autosize';\n\nfunction MyComponent() {\n  const [value, setValue] = useState('');\n\n  return (\n    <AutosizeInput\n      value={value}\n      onChange={(e) => setValue(e.target.value)}\n    />\n  );\n}"}

Other packages similar to react-input-autosize

Changelog

Source

v1.2.0 / 2017-09-12

  • added; inputRef prop (function, passed the reference to the input node)
  • fixed; resize issues in IE11, thanks Constantine
  • fixed; copyInputStyles() never running, thanks Michael Elsdörfer

Readme

Source

React-Input-Autosize

A text input for React that resizes itself to the current content.

Demo & Examples

Live demo: jedwatson.github.io/react-input-autosize

To run the examples locally, run:

npm install
npm dev

Then open localhost:8000 in a browser.

Installation

The easiest way to use React-Input-Autosize is to install it from NPM and include it in your own React build process (using Browserify, rollup, webpack, etc).

You can also use the umd build by including dist/AutosizeInput.js in your page. If you use this, make sure you have already included a umd React build.

npm install react-input-autosize --save

Usage

React-Input-Autosize generates an input field, wrapped in a <div> tag so it can detect the size of its value. Otherwise it behaves very similarly to a standard React input.

var AutosizeInput = require('react-input-autosize');

<AutosizeInput
	name="form-field-name"
	value={inputValue}
	onChange={function(event) {
		// event.target.value contains the new value
	}}
/>

Gotchas

Custom font sizes

If your input uses custom font sizes, you will need to provide the custom size to AutosizeInput.

<AutosizeInput
	name="form-field-name"
	value={inputValue}
	style={{ fontSize: 36 }}
	onChange={function(event) {
		// event.target.value contains the new value
	}}
/>

Uncontrolled input

AutosizeInput is a controlled input and depends on the value prop to work as intended. It does not support being used as an uncontrolled input.

License

Copyright (c) 2017 Jed Watson. MIT License.

Keywords

FAQs

Last updated on 12 Sep 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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc