Andarist / react-textarea-autosize

<textarea /> component for React which grows with content

Home Page:http://andarist.github.io/react-textarea-autosize/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to manually trigger a resize?

karlingen opened this issue · comments

We're using custom fonts in our app that might take a bit for them to load. When they've successfully been rendered, react-textarea-autosize does not automatically resize.

In version 7, we could simply call _resizeComponent() to force an update. This is no longer possible in version 8.

// Version 8.3.2
import TextareaAutosize from 'react-textarea-autosize'; 
import React = require('react');

class NoteComponent extends React.Component {
    private _contentTextArea: HTMLTextAreaElement;

    constructor(props) {
        super(props);
    }

    componentDidMount() {
        // Wait for the fonts to finish rendering and then trigger a resize.
        setTimeout(() => {
            this._contentTextArea._resizeComponent(); // Not working.
        }, 500);
    }

    render () {
        return <TextareaAutosize ref={n => this._contentTextArea = n} />
    }
}

What's the official way of triggering an update / resize?

You could trigger a rerender with a new key

Ahh, of course! Thank you!

But it is not the same. If we change key focus will be lost.