UNPKG

@ebay/ebayui-core

Version:

Collection of core eBay components; considered to be the building blocks for all composite structures, pages & apps.

50 lines (49 loc) 1.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const event_utils_1 = require("../../common/event-utils"); class Combobox { onCreate(input) { var _a; this.state = { selected: (_a = input.selected) !== null && _a !== void 0 ? _a : [], }; } onInput(input) { if (input.selected === null) { this.state.selected = []; } else if (input.selected) { this.state.selected = input.selected; } } handleKeydown(e) { (0, event_utils_1.handleEnterKeydown)(e, () => { const value = e.target.value; e.preventDefault(); if (value) { this.selectChip(value); } }); } selectChip(text) { if (!this.state.selected.includes(text)) { this.state.selected = [...this.state.selected, text]; this.emit("change", { selected: this.state.selected, }); } } handleDelete(index) { this.state.selected = [ ...this.state.selected.slice(0, index), ...this.state.selected.slice(index + 1), ]; this.emit("change", { selected: this.state.selected, }); } getDropdownEl() { return () => this.getEl("root"); } } module.exports = Combobox;