DemocracyOS/app

View on GitHub
lib/site/topic-layout/topic-article/comments/form/autogrow-textarea.js

Summary

Maintainability
A
0 mins
Test Coverage
import React, { Component } from 'react'

export default class AutoGrowTextarea extends Component {
  componentDidMount () {
    this.recomputeSize()
  }

  componentDidUpdate () {
    this.recomputeSize()
  }

  handleChange = () => {
    this.recomputeSize()
  }

  recomputeSize = () => {
    const node = this.refs.textarea
    node.style.minHeight = 'auto'
    node.style.minHeight = `${node.scrollHeight}px`
  }

  render () {
    return (
      <textarea onChange={this.handleChange} {...this.props} ref='textarea' />
    )
  }
}