diff options
author | Francesco Cioria <firefelix@gmail.com> | 2017-04-20 11:09:42 +0200 |
---|---|---|
committer | Francesco Cioria <firefelix@gmail.com> | 2017-04-20 11:09:42 +0200 |
commit | 561d10840b21cfa7f30a62f958eb01284c9f01f7 (patch) | |
tree | 73c143045835ccadbb8e6da135e21f3f5a152e0a | |
parent | af6ef90615af0e6e44f0b04b25e52cdb5ac43d66 (diff) | |
download | react-autosize-textarea-561d10840b21cfa7f30a62f958eb01284c9f01f7.zip react-autosize-textarea-561d10840b21cfa7f30a62f958eb01284c9f01f7.tar.gz react-autosize-textarea-561d10840b21cfa7f30a62f958eb01284c9f01f7.tar.bz2 |
Update README.md with chapter about "refs to DOM nodes"
-rw-r--r-- | README.md | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -53,6 +53,29 @@ In addition to `minHeight`, you can force `TextareaAutosize` to have a minimum n <TextareaAutosize rows={3} /> // minimun height is three rows ``` +#### Refs to DOM nodes +In order to manually call `textarea`'s DOM element functions like `focus()` or `blur()`, you need a ref to the DOM node. + +You get one by using the prop `ref` and `ReactDOM.findDOMNode` as shown in the example below. + +NOTE: As `TextareaAutosize` is not a native React component (`input`, `div`, `textarea` ...), `ref` will return you the instance of the class. You have to use `ReactDOM.findDOMNode` to get a pointer to the DOM element. + +```jsx +class Form extends React.Component { + componentDidMount() { + this.textarea.focus(); + } + + render() { + return ( + <TextareaAutosize + ref={(ref) => { this.textarea = ReactDOM.findDOMNode(ref); }} + /> + ); + } +} +``` + ## Browser Compatibility | Chrome | Firefox | IE | Safari | Android | | ------------- | ------------- | ----- | ------ | ------- | |