UNPKG

mj-context-menu

Version:
76 lines 2.35 kB
import { AbstractVariableItem } from './abstract_variable_item.js'; import * as MenuUtil from './menu_util.js'; import { HtmlClasses } from './html_classes.js'; import { KEY } from './key_navigatable.js'; export class Combo extends AbstractVariableItem { static fromJson(_factory, { content: content, variable: variable, id: id }, menu) { return new this(menu, content, variable, id); } constructor(menu, content, variable, id) { super(menu, 'combobox', content, id); this.role = 'combobox'; this.inputEvent = false; this.variable = menu.pool.lookup(variable); this.register(); } executeAction() { this.variable.setValue(this.input.value, MenuUtil.getActiveElement(this)); } space(event) { super.space(event); MenuUtil.close(this); } focus() { super.focus(); this.input.focus(); } unfocus() { super.unfocus(); this.updateSpan(); } generateHtml() { super.generateHtml(); const html = this.html; html.classList.add(HtmlClasses['MENUCOMBOBOX']); } generateSpan() { this.span = document.createElement('span'); this.span.classList.add(HtmlClasses['MENUINPUTBOX']); this.input = document.createElement('input'); this.input.addEventListener('keydown', this.inputKey.bind(this)); this.input.setAttribute('size', '10em'); this.input.setAttribute('type', 'text'); this.input.setAttribute('tabindex', '-1'); this.span.appendChild(this.input); } inputKey(_event) { this.bubbleKey(); this.inputEvent = true; } keydown(event) { if (this.inputEvent && event.keyCode !== KEY.ESCAPE && event.keyCode !== KEY.RETURN) { this.inputEvent = false; event.stopPropagation(); return; } super.keydown(event); event.stopPropagation(); } updateAria() { } updateSpan() { let initValue; try { initValue = this.variable.getValue(MenuUtil.getActiveElement(this)); } catch (e) { initValue = ''; } this.input.value = initValue; } toJson() { return { type: '' }; } } //# sourceMappingURL=item_combo.js.map