Textarea.js 1.02 KB
import template from "./Textarea.html";
import style from "antd/lib/input/style/index.css";

class Textarea {
    useModules = ["esNgAntd"];

    state = {
        value: this.props.value,
        count: 0,
        maxLength: this.props.maxLength || "off",
    };

    constructor() {
        esNgAntd.createStyle("ant-input", style);
    }

    handleKeyup(event) {
        if (!this.event) {
            this.event = event;
        }
        if (this.state.maxLength === "off") {
            return;
        }
        let target = event.target;
        this.state.count = target.value.length;
    }

    handleClick(event) {
        if (!this.event) {
            this.event = event;
        }
    }

    handleChange() {
        this.props.onChange({
            event: this.event,
        });
    }

    render() {
        return template;
    }
}

Textarea.propTypes = {
    value: PropTypes.string,
    placeholder: PropTypes.string,
    showCount: PropTypes.boolean,
    maxLength: PropTypes.number,
    onChange: PropTypes.function,
};