aboutsummaryrefslogtreecommitdiff
path: root/vnext/src/components/MessageInput.js
blob: 15d36309e3e802fde136ea7125d378f7de4486b0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import React from 'react';

import { MessageType } from './Types';

export default class MessageInput extends React.Component {
    constructor(props) {
        super(props)
        this.resize = this.resize.bind(this);
        this.textarea = React.createRef();
    }
    componentDidMount() {
        this.resize()
    }
    resize() {
        const el = this.textarea.current;
        const offset = el.offsetHeight - el.clientHeight;
        const height = el.scrollHeight + offset;
        el.style.height = `${height + offset}px`;
    }
    render() {
        const msg = this.props.data;
        return (
            <form className="msg-comment-target">
                <input type="hidden" name="mid" value={msg.mid} />
                <div className="msg-comment">
                    <div className="ta-wrapper">
                        <textarea name="body" onChange={this.resize}
                            ref={this.textarea} style={textInputStyle}
                            rows="3" placeholder="Write a comment..." />
                    </div>
                </div>
            </form>
        )
    }
}

const textInputStyle = {
    overflow: 'hidden',
    resize: 'none',
    display: 'block',
    boxSizing: 'border-box'
}

MessageInput.propTypes = {
    data: MessageType
};