• Stars
    star
    2,009
  • Rank 22,172 (Top 0.5 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 11 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

<textarea /> component for React which grows with content

npm version npm

react-textarea-autosize

Drop-in replacement for the textarea component which automatically resizes textarea as content changes. A native React version of the popular jQuery Autosize! Weighs around 1.3KB (minified & gzipped).

This module supports IE9 and above.

import TextareaAutosize from 'react-textarea-autosize';

// If you use CommonJS syntax:
// var TextareaAutosize = require('react-textarea-autosize').default;

React.renderComponent(
  <div>
    <TextareaAutosize />
  </div>,
  document.getElementById('element'),
);

Install

npm install react-textarea-autosize

Demo

https://andarist.github.io/react-textarea-autosize/

Props

Special props:

prop type description
maxRows number Maximum number of rows up to which the textarea can grow
minRows number Minimum number of rows to show for textarea
onHeightChange func Function invoked on textarea height change, with height as first argument. The second function argument is an object containing additional information that might be useful for custom behaviors. Current options include { rowHeight: number }.
cacheMeasurements boolean Reuse previously computed measurements when computing height of textarea. Default: false

Apart from these, the component accepts all props that are accepted by <textarea/>, like style, onChange, value, etc.

FAQ

How to focus

Get a ref to inner textarea:

<TextareaAutosize ref={(tag) => (this.textarea = tag)} />

And then call a focus on that ref:

this.textarea.focus();

To autofocus:

<TextareaAutosize autoFocus />

(all HTML attributes are passed to inner textarea)

How to test it with jest and react-test-renderer if you need ref

Because jest provides polyfills for DOM objects by requiring jsdom and react-test-renderer doesn't provide refs for rendered components out of the box (calling ref callbacks with null), you need to supply a mocked ref in your tests in you need it for your tests. You can do it like this (more can be read here):

const tree = renderer
  .create(<TextareaAutosize />, {
    createNodeMock: () => document.createElement('textarea'),
  })
  .toJSON();

More Repositories

1

use-onclickoutside

React hook for listening for clicks outside of an element.
TypeScript
496
star
2

use-constant

JavaScript
202
star
3

babel-plugin-jsx-adopt

JavaScript
94
star
4

babel-plugin-annotate-pure-calls

This plugins helps with annotating top level functions calls with #__PURE__ comment.
JavaScript
91
star
5

react-selector-hooks

Collection of hook-based memoized selector factories for declarations outside of render.
JavaScript
85
star
6

cherry-pick

πŸ’β›πŸ“¦ Build tool to generate proxy directories.
JavaScript
54
star
7

data-uri.macro

🎣 Convert files to data-uris at build time.
JavaScript
45
star
8

use-smooth-scroll

React hook which gives a smooth scrolling function.
JavaScript
41
star
9

regexgen.macro

🎣 Convert your set of strings to optimized RegExps at build time.
JavaScript
38
star
10

lerna-alias

Get aliases for your lerna packages for the other tools
JavaScript
36
star
11

pipeline.macro

🎣 A babel macro which works similarly to the pipeline operator.
JavaScript
35
star
12

use-callbag

πŸ‘œ Use callbag as React hook.
JavaScript
34
star
13

rollup-plugin-dotenv

JavaScript
29
star
14

use-isomorphic-layout-effect

TypeScript
24
star
15

stylis-plugin-extra-scope

Stylis plugin which adds extra scope to each produced CSS rule.
JavaScript
21
star
16

use-latest

TypeScript
17
star
17

use-composed-ref

TypeScript
16
star
18

nanoclone-comparisons

JavaScript
9
star
19

are-passive-events-supported

JavaScript
9
star
20

callbag-pull-when

πŸ‘œ Callbag operator that pulls from source when provided listenable emits.
JavaScript
7
star
21

use-previous

JavaScript
7
star
22

memory-web-storage

Memory storage with WebStorage API. Can be used as drop-in replacement when latter is not available.
TypeScript
6
star
23

use-value-callbag

JavaScript
5
star
24

callbag-to-promise

πŸ‘œ Callbag operator which converts source to a promise containing last emitted value.
JavaScript
5
star
25

callbag-of

πŸ‘œ Callbag source factory that emits values specified as arguments.
JavaScript
5
star
26

callbag-exhaust-map

πŸ‘œ Callbag operator that maps to inner source and ignores other values until that source completes.
JavaScript
5
star
27

copy-mjs

πŸ›  Build tool to copy .js files from input directory to corresponding .mjs files in output directory.
JavaScript
4
star
28

callbag-retry

πŸ‘œ Callbag operator which resubscribes to the source given amount of times.
JavaScript
4
star
29

react-hooks-with-lazy-inputs

4
star
30

npm-self-link

A CLI tool which links the package in which it is run (if it's not already linked).
JavaScript
4
star
31

are-hook-inputs-equal

A comparator function for previous and current React hook inputs.
JavaScript
4
star
32

callbag-timestamp

πŸ‘œ Callbag operator that attaches a timestamp to each emitted value.
JavaScript
3
star
33

callbag-default-if-empty

πŸ‘œ Callbag operator which emits a given value when source completes without emitting any value.
JavaScript
3
star
34

callbag-take-while

πŸ‘œ Callbag operator which emits values emitted by the source as long as each value satisfies the given predicate, and then completes as soon as predicate is not satisfied.
JavaScript
3
star
35

callbag-sample-when

πŸ‘œ Callbag operator that samples from source when provided listenable emits.
JavaScript
3
star
36

callbag-remember

πŸ‘œ Callbag operator that remembers last event, so that a newly added listener will immediately receive that memorised event.
JavaScript
3
star
37

callbag-ms-elapsed

πŸ‘œ Callbag listenable source which emits milliseconds elapsed since the subscription (using requestAnimationFrame) - useful for animations.
JavaScript
3
star
38

callbag-last-element

πŸ‘œ Callbag operator that emits only the last item emitted by the source.
JavaScript
2
star
39

callbag-drop-until

Starts emitting the input stream when another stream emits a value.
JavaScript
2
star
40

callbag-buffer-time

πŸ‘œ Callbag operator which buffers source values until provided time has passed.
JavaScript
2
star
41

callbag-buffer

πŸ‘œ Callbag operator which buffers source values until separator stream emits.
JavaScript
2
star
42

get-lerna-packages

JavaScript
2
star
43

callbag-never

πŸ‘œ Callbag source that never completes and emits no data.
JavaScript
2
star
44

create-commit-status-action

A simple GitHub action that create a commit status using the GitHub API.
TypeScript
2
star
45

callbag-loop

πŸ‘œ Callbag operator that accumulates results using a feedback loop that emits one value and feeds back another to be used in the next iteration.
JavaScript
2
star
46

callbag-element-at

πŸ‘œ Callbag operator that emits the single value at the specified index.
JavaScript
2
star
47

callbag-time-interval

πŸ‘œ Callbag operator which emits the value with time elapsed since last emission.
JavaScript
2
star
48

callbag-timeout

πŸ‘œ Callbag operator which errors if source does not emit before specified duration.
JavaScript
2
star
49

callbag-defer

πŸ‘œ Callbag which creates a source from a given factory when sink subscribes.
JavaScript
2
star
50

callbag-concat-map

πŸ‘œ Callbag operator that maps to inner source, subscribe and emit in order.
JavaScript
2
star
51

callbag-timer

πŸ‘œ Callbag source that after given duration emits numbers in sequence every specified duration.
JavaScript
2
star
52

callbag-duration-progress

πŸ‘œ Callbag listenable source which emits value describing time progress (number between 0 an 1) since the subscription (using requestAnimationFrame) - useful for animations.
JavaScript
2
star
53

webpack-reexported-namespace-test

JavaScript
1
star
54

babel-check-duplicated-nodes

🐠 Babel helper module for transforms authors to check the AST against duplicated nodes.
JavaScript
1
star
55

callbag-from-event-pattern

πŸ‘œ Callbag source factory from addHandler and removeHandler pair.
JavaScript
1
star
56

xstate-intro-slides

Programming Application Flows With Statecharts (XState) and The Actor Model
1
star
57

log-action

A simple GitHub action that log its input for debugging purposes.
TypeScript
1
star
58

callbag-pluck

πŸ‘œ Callbag operator that maps to object properties.
JavaScript
1
star
59

mapped-type-emit-loses-modifiers-bug

TypeScript
1
star
60

rtk-query-types-issue

1
star
61

react-redux-tree-shaking-playground

JavaScript
1
star
62

berry-ancestor-breaking-chain-repro

JavaScript
1
star
63

tabbable-tree-shaking-issue-demo

JavaScript
1
star
64

callbag-drop-after

πŸ‘œ Callbag operator that drops all events after the first event for which predicate returns true.
JavaScript
1
star
65

module-scope-plugin-repro

HTML
1
star
66

bundlers-import-condition-test

JavaScript
1
star
67

parcel-sideeffects-flag-bug-repro

JavaScript
1
star
68

callbag-buffer-count

1
star
69

callbag-partition

πŸ‘œ Callbag operator that splits the source into two, based on predicate function.
JavaScript
1
star
70

callbag-tap-up

πŸ‘œ Callbag operator which performs a side effect for every upwards emission (from sink to source), but other than that it acts as noop.
JavaScript
1
star
71

xstate-codegen-pnpm-demo

1
star
72

callbag-throw-error

πŸ‘œ Callbag source factory that immediately emits an error.
JavaScript
1
star
73

callbag-distinct-until-changed

πŸ‘œ Callbag operator that drops consecutive duplicate values
JavaScript
1
star
74

callbag-empty

πŸ‘œ Callbag source that emits no data and completes immediately.
JavaScript
1
star
75

xstate-1622-test

TypeScript
1
star
76

callbag-concat-with

πŸ‘œ Callbag operator that emits items given it as arguments after it finishes emitting items emitted by source.
JavaScript
1
star
77

callbag-pairwise

πŸ‘œ Callbag operator that groups pairs of consecutive emissions together and emits them as an array of two values.
JavaScript
1
star