diff --git a/ui-v2/app/components/phrase-editor.js b/ui-v2/app/components/phrase-editor.js index e280b571c1e9..4eb7bce817fc 100644 --- a/ui-v2/app/components/phrase-editor.js +++ b/ui-v2/app/components/phrase-editor.js @@ -1,44 +1,67 @@ import Component from '@ember/component'; import { get, set } from '@ember/object'; +import { inject as service } from '@ember/service'; export default Component.extend({ + dom: service('dom'), classNames: ['phrase-editor'], item: '', - remove: function(index, e) { - this.items.removeAt(index, 1); - this.onchange(e); + didInsertElement: function() { + this._super(...arguments); + // TODO: use {{ref}} + this.input = get(this, 'dom').element('input', this.element); }, - add: function(e) { - const value = get(this, 'item').trim(); - if (value !== '') { - set(this, 'item', ''); - const currentItems = get(this, 'items') || []; - const items = new Set(currentItems).add(value); - if (items.size > currentItems.length) { - set(this, 'items', [...items]); - this.onchange(e); + onchange: function(e) {}, + search: function(e) { + // TODO: Temporarily continue supporting `searchable` + let searchable = get(this, 'searchable'); + if (searchable) { + if (!Array.isArray(searchable)) { + searchable = [searchable]; } + searchable.forEach(item => { + item.search(get(this, 'value')); + }); } + this.onchange(e); }, - onkeydown: function(e) { - switch (e.keyCode) { - case 8: - if (e.target.value == '' && this.items.length > 0) { - this.remove(this.items.length - 1); + oninput: function(e) {}, + onkeydown: function(e) {}, + actions: { + keydown: function(e) { + switch (e.keyCode) { + case 8: // backspace + if (e.target.value == '' && get(this, 'value').length > 0) { + this.actions.remove.bind(this)(get(this, 'value').length - 1); + } + break; + case 27: // escape + set(this, 'value', []); + this.search({ target: this }); + break; + } + this.onkeydown({ target: this }); + }, + input: function(e) { + set(this, 'item', e.target.value); + this.oninput({ target: this }); + }, + remove: function(index, e) { + get(this, 'value').removeAt(index, 1); + this.search({ target: this }); + this.input.focus(); + }, + add: function(e) { + const item = get(this, 'item').trim(); + if (item !== '') { + set(this, 'item', ''); + const currentItems = get(this, 'value') || []; + const items = new Set(currentItems).add(item); + if (items.size > currentItems.length) { + set(this, 'value', [...items]); + this.search({ target: this }); } - break; - } - }, - oninput: function(e) { - set(this, 'item', e.target.value); - }, - onchange: function(e) { - let searchable = get(this, 'searchable'); - if (!Array.isArray(searchable)) { - searchable = [searchable]; - } - searchable.forEach(item => { - item.search(get(this, 'items')); - }); + } + }, }, }); diff --git a/ui-v2/app/styles/base/components/pill/layout.scss b/ui-v2/app/styles/base/components/pill/layout.scss index 6b4b05f39b12..95b1e132ea81 100644 --- a/ui-v2/app/styles/base/components/pill/layout.scss +++ b/ui-v2/app/styles/base/components/pill/layout.scss @@ -8,4 +8,5 @@ padding: 0; height: 10px; margin-right: 3px; + font-size: 0; } diff --git a/ui-v2/app/templates/components/phrase-editor.hbs b/ui-v2/app/templates/components/phrase-editor.hbs index 480849c5f979..d0e8d5e74ed1 100644 --- a/ui-v2/app/templates/components/phrase-editor.hbs +++ b/ui-v2/app/templates/components/phrase-editor.hbs @@ -1,11 +1,11 @@ -