summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrancesco Cioria <firefelix@gmail.com>2017-04-20 11:09:42 +0200
committerFrancesco Cioria <firefelix@gmail.com>2017-04-20 11:09:42 +0200
commit561d10840b21cfa7f30a62f958eb01284c9f01f7 (patch)
tree73c143045835ccadbb8e6da135e21f3f5a152e0a
parentaf6ef90615af0e6e44f0b04b25e52cdb5ac43d66 (diff)
downloadreact-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.md23
1 files changed, 23 insertions, 0 deletions
diff --git a/README.md b/README.md
index cc716b5..3b19fe6 100644
--- a/README.md
+++ b/README.md
@@ -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 |
| ------------- | ------------- | ----- | ------ | ------- |