UNPKG

@scidian/osui

Version:

Lightweight JavaScript UI library.

43 lines (32 loc) 1.05 kB
import { Element } from '../core/Element.js'; /** Multi-line editable text box */ class TextArea extends Element { constructor() { super(document.createElement('textarea')); this.setClass('osui-text-area'); this.dom.spellcheck = false; this.dom.setAttribute('autocomplete', 'off'); // Events function onKeyDown(event) { event.stopPropagation(); if (event.key === 'Tab') { event.preventDefault(); const cursor = this.selectionStart; this.value = this.value.substring(0, cursor) + '\t' + this.value.substring(cursor); this.selectionStart = cursor + 1; this.selectionEnd = this.selectionStart; } } this.onKeyDown(onKeyDown); } getValue() { if (!this.dom) return null; return this.dom.value; } setValue(value) { if (!this.dom) return this; this.dom.value = value; return this; } } export { TextArea };