Added TextAreaInput for textarea resizing

Signed-off-by: Florian Bouillon <florian.bouillon@delta-wings.net>
This commit is contained in:
Florian Bouillon 2020-07-21 11:33:46 +02:00
parent 267aba9c8f
commit c8d71bb516

View File

@ -0,0 +1,24 @@
import InputIdentity from "./Interfaces/InputIdentity"
import DefaultInput from "./DefaultInput"
import FormManager from "../FormManager"
export default class TextAreaInput extends DefaultInput {
public constructor(element: HTMLElement, form: FormManager) {
super(element, form)
element.style.resize = 'none'
const event = () => {
element.style.minHeight = "5px"
element.style.minHeight = `calc(2em + ${element.scrollHeight+5}px)`
}
;(element as HTMLTextAreaElement).addEventListener('keydown', event)
;(element as HTMLTextAreaElement).addEventListener('keypress', event)
}
public static identity: InputIdentity = {
input: TextAreaInput,
tagName: 'textarea',
attributes: 'data-autoresize'
}
}