prevent blur event in menus, fix #353

This commit is contained in:
Philipp Kühn 2019-06-11 07:15:36 +02:00
parent 134c4c0132
commit 2189151903
2 changed files with 22 additions and 0 deletions

View File

@ -14,6 +14,9 @@ class Menu {
this.isActive = false this.isActive = false
this.top = 0 this.top = 0
// the mousedown event is fired before blur so we can prevent it
this.options.element.addEventListener('mousedown', this.handleClick)
this.options.editor.on('focus', ({ view }) => { this.options.editor.on('focus', ({ view }) => {
this.update(view) this.update(view)
}) })
@ -22,6 +25,10 @@ class Menu {
}) })
} }
handleClick(event) {
event.preventDefault()
}
update(view, lastState) { update(view, lastState) {
const { state } = view const { state } = view
@ -72,6 +79,10 @@ class Menu {
this.sendUpdate() this.sendUpdate()
} }
destroy() {
this.options.element.removeEventListener('mousedown', this.handleClick)
}
} }
export default function (options) { export default function (options) {

View File

@ -67,6 +67,9 @@ class Menu {
this.left = 0 this.left = 0
this.bottom = 0 this.bottom = 0
// the mousedown event is fired before blur so we can prevent it
this.options.element.addEventListener('mousedown', this.handleClick)
this.options.editor.on('focus', ({ view }) => { this.options.editor.on('focus', ({ view }) => {
this.update(view) this.update(view)
}) })
@ -75,6 +78,10 @@ class Menu {
}) })
} }
handleClick(event) {
event.preventDefault()
}
update(view, lastState) { update(view, lastState) {
const { state } = view const { state } = view
@ -132,6 +139,10 @@ class Menu {
this.sendUpdate() this.sendUpdate()
} }
destroy() {
this.options.element.removeEventListener('mousedown', this.handleClick)
}
} }
export default function (options) { export default function (options) {