{"id":13850428,"url":"https://github.com/buildo/react-autosize-textarea","last_synced_at":"2025-07-12T22:30:27.971Z","repository":{"id":33490069,"uuid":"37135867","full_name":"buildo/react-autosize-textarea","owner":"buildo","description":"A textarea perfectly compatible with ReactJS default one which auto resizes its height based on user input.","archived":true,"fork":false,"pushed_at":"2021-06-22T12:56:14.000Z","size":493,"stargazers_count":487,"open_issues_count":19,"forks_count":82,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-05-29T18:39:30.885Z","etag":null,"topics":["react"],"latest_commit_sha":null,"homepage":"http://react-components.buildo.io/#textareaautosize","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/buildo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-06-09T14:08:26.000Z","updated_at":"2024-03-01T12:08:59.000Z","dependencies_parsed_at":"2022-09-04T07:30:28.778Z","dependency_job_id":null,"html_url":"https://github.com/buildo/react-autosize-textarea","commit_stats":null,"previous_names":[],"tags_count":39,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/buildo%2Freact-autosize-textarea","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/buildo%2Freact-autosize-textarea/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/buildo%2Freact-autosize-textarea/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/buildo%2Freact-autosize-textarea/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/buildo","download_url":"https://codeload.github.com/buildo/react-autosize-textarea/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224506021,"owners_count":17322722,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["react"],"created_at":"2024-08-04T20:01:11.909Z","updated_at":"2024-11-22T03:31:22.994Z","avatar_url":"https://github.com/buildo.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# React Autosize Textarea\nA light replacement for built-in `\u003ctextarea /\u003e` component which automatically adjusts its height to match the content.\n\n**NB: It does not require any polyfill**\n\n```jsx\nimport ReactDOM from 'react-dom';\nimport TextareaAutosize from 'react-autosize-textarea';\n\nReactDOM.renderComponent(\n  \u003cTextareaAutosize {...textareaProps} onResize={(e) =\u003e {}} /\u003e,\n  document.body\n);\n```\n\n## Install\n```\nnpm install --save react-autosize-textarea\n```\n```\nyarn add react-autosize-textarea\n```\n\n## Demo\n[Live Examples](http://react-components.buildo.io/#textareaautosize)\n\n## Usage\n`TextareaAutosize` is perfectly compatible with ReactJS default one, so to get started you can simply replace any `\u003ctextarea\u003e\u003c/textarea\u003e` with `\u003cTextareaAutosize\u003e\u003c/TextareaAutosize\u003e`. It's that easy :)\n\n### Props\nYou can pass any prop you're allowed to use with the default React `textarea` (`valueLink` too).\n\nIn addition to them, `TextareaAutosize` comes with some optional custom `props` to facilitate its usage:\n\n|Name|Type|Default|Description|\n|----|----|-------|-----------|\n| **onResize** | \u003ccode\u003eFunction\u003c/code\u003e |  | *optional*. Called whenever the textarea resizes |\n| **rows** | \u003ccode\u003eNumber\u003c/code\u003e |  | *optional*. Minimum number of visible rows |\n| **maxRows** | \u003ccode\u003eNumber\u003c/code\u003e |  | *optional*. Maximum number of visible rows |\n| **async** | \u003ccode\u003eBoolean\u003c/code\u003e | \u003ccode\u003efalse\u003c/code\u003e | *optional*. Initialize `autosize` asynchronously. Enable it if you are using StyledComponents. This is forced to true when `maxRows` is set. Async initialization will make your page \"jump\" when the component appears, as it will first be rendered with the normal size, then resized to content.\n| **ref** | \u003ccode\u003eFunction\u003c/code\u003e |  | *optional*. Ref to the DOM node |\n\n\n#### `onResize`\n\nSometimes you may need to react any time `TextareaAutosize` resizes itself. To do so, you should use the optional callback **onResize** which will be triggered at any resize with the `autosize:resized` event object:\n\n```jsx\nfunction onResize(event) {\n  console.log(event.type); // -\u003e \"autosize:resized\"\n}\n\n\u003cTextareaAutosize onResize={onResize} /\u003e\n```\n\n#### Set min/max height\nYou can set `minHeight` and `maxHeight` through CSS or inline-style as usual:\n\n```jsx\n\u003cTextareaAutosize style={{ minHeight: 20, maxHeight: 80 }} /\u003e // min-height: 20px; max-height: 80px;\n```\n\n**NB:** you may need to take into account borders and/or padding.\n\n\nIn addition to `minHeight`, you can force `TextareaAutosize` to have a minimum number of rows by passing the prop `rows`:\n\n```jsx\n\u003cTextareaAutosize rows={3} /\u003e // minimun height is three rows\n```\n\nIn addition to `maxHeight`, you can force `TextareaAutosize` to have a maximum number of rows by passing the prop `maxRows`:\n\n```jsx\n\u003cTextareaAutosize maxRows={3} /\u003e // maximum height is three rows\n```\n\n#### Refs to DOM nodes\nIn order to manually call `textarea`'s DOM element functions like `focus()` or `blur()`, you need a ref to the DOM node.\n\nYou get one by using the prop `ref` as shown in the example below:\n\n```jsx\nclass Form extends React.Component {\n  constructor() {\n    this.textarea = React.createRef()\n  }\n  \n  componentDidMount() {\n    this.textarea.current.focus();\n  }\n\n  render() {\n    return (\n      \u003cTextareaAutosize ref={this.textarea} /\u003e\n    );\n  }\n}\n```\n\n## Browser Compatibility\n| Chrome        | Firefox       | IE    | Safari | Android |\n| ------------- | ------------- | ----- | ------ | ------- |\n| Yes           | Yes           | 9+    | Yes    | 4+      |\n\n\n## Credits\nThis module is based on the very popular autosize script written by [Jack Moore](https://github.com/jackmoore).\n\nCheck out his [repo](https://github.com/jackmoore/autosize) or [website](http://www.jacklmoore.com/autosize/) for more documentation.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbuildo%2Freact-autosize-textarea","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbuildo%2Freact-autosize-textarea","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbuildo%2Freact-autosize-textarea/lists"}