This commit is contained in:
iulia bejan 2020-11-24 12:19:13 +01:00
Родитель 8ad2afc84c 5201d5792d
Коммит 3f59add398
2 изменённых файлов: 12 добавлений и 12 удалений

Просмотреть файл

@ -88,9 +88,9 @@ class TextExpander {
this.combobox.navigate(1)
}
deactivate(cursor: number): boolean {
deactivate(cursor: number) {
const menu = this.menu
if (!menu || !this.combobox) return false
if (!menu || !this.combobox) return
this.menu = null
menu.removeEventListener('combobox-commit', this.oncommit)
@ -102,7 +102,6 @@ class TextExpander {
menu.remove()
this.lookBackIndex = cursor
return true
}
onDismiss() {
@ -209,11 +208,13 @@ class TextExpander {
}
onKeydown(event: KeyboardEvent) {
if (event.key === 'Escape') {
if (this.deactivate(this.input.selectionEnd || this.lookBackIndex)) {
event.stopImmediatePropagation()
event.preventDefault()
if (event.key === 'Escape' && (this.menu || this.combobox)) {
const cancelled = this.expander.dispatchEvent(new CustomEvent('text-expander-dismiss', {cancelable: true}))
if (cancelled) {
return
}
event.stopImmediatePropagation()
event.preventDefault()
}
}
}

Просмотреть файл

@ -51,8 +51,7 @@ describe('text-expander element', function() {
it('Escape triggers text-expander-dismiss', async function() {
const expander = document.querySelector('text-expander')
const input = expander.querySelector('textarea')
const menu = document.createElement('ul');
const menu = document.createElement('ul')
menu.appendChild(document.createElement('li'))
expander.addEventListener('text-expander-change', event => {
@ -61,13 +60,13 @@ describe('text-expander element', function() {
})
input.focus()
// This is dependent on the implementation detail or text-expander-element
// and it needs to wait for all the Promises there to fullfil
// This is dependent on the implementation detail of text-expander-element
// and it needs to await for all the Promises there to fullfil
await await await triggerInput(input, ':')
const resultDismiss = once(expander, 'text-expander-dismiss')
input.dispatchEvent(new KeyboardEvent('keydown', {key: 'Escape'}))
const eventDismiss= await resultDismiss
const eventDismiss = await resultDismiss
assert.equal(eventDismiss.type, 'text-expander-dismiss')
})
})