fix: fix event propagation for click delegates (#1317)

fixes #1316
This commit is contained in:
Nolan Lawson 2019-07-07 17:32:50 -07:00 committed by GitHub
parent 114aaf0c13
commit 7fd6cdc22c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 43 additions and 39 deletions

View file

@ -146,10 +146,13 @@
type: ({ media }) => media.type type: ({ media }) => media.type
}, },
methods: { methods: {
async onClick () { onClick () {
let { mediaAttachments, index } = this.get() (async () => {
let showMediaDialog = await importShowMediaDialog() let { mediaAttachments, index } = this.get()
showMediaDialog(mediaAttachments, index) let showMediaDialog = await importShowMediaDialog()
showMediaDialog(mediaAttachments, index)
})()
return true
} }
}, },
data: () => ({ data: () => ({

View file

@ -197,21 +197,20 @@
let isClick = type === 'click' let isClick = type === 'click'
let isEnter = type === 'keydown' && keyCode === 13 let isEnter = type === 'keydown' && keyCode === 13
if (!isClick && !isEnter) { if (!isClick && !isEnter) {
return return false
} }
if (checkDomAncestors(target, isUserInputElement, isStatusArticle)) { if (checkDomAncestors(target, isUserInputElement, isStatusArticle)) {
// this element or any ancestors up to the status-article element is // this element or any ancestors up to the status-article element is
// a user input element // a user input element
return return false
} }
if (checkDomAncestors(target, isToolbar, isStatusArticle)) { if (checkDomAncestors(target, isToolbar, isStatusArticle)) {
// this element or any of its ancestors is the toolbar // this element or any of its ancestors is the toolbar
return return false
} }
e.preventDefault()
e.stopPropagation()
this.open() this.open()
return true
}, },
open () { open () {
let { originalStatusId } = this.get() let { originalStatusId } = this.get()

View file

@ -190,6 +190,7 @@
sensitivesShown[uuid] = !sensitivesShown[uuid] sensitivesShown[uuid] = !sensitivesShown[uuid]
this.store.set({ sensitivesShown }) this.store.set({ sensitivesShown })
this.fire('recalculateHeight') this.fire('recalculateHeight')
return true
} }
} }
} }

View file

@ -287,21 +287,22 @@
) )
}, },
methods: { methods: {
async onRefreshClick (e) { onRefreshClick () {
e.preventDefault() (async () => {
e.stopPropagation() let { pollId } = this.get()
let { pollId } = this.get() this.set({ loading: true })
this.set({ loading: true }) try {
try { let poll = await doAsyncActionWithDelay(() => getPoll(pollId))
let poll = await doAsyncActionWithDelay(() => getPoll(pollId)) if (poll) {
if (poll) { let { polls } = this.store.get()
let { polls } = this.store.get() polls[pollId] = poll
polls[pollId] = poll this.store.set({ polls })
this.store.set({ polls }) }
} finally {
this.set({ loading: false })
} }
} finally { })()
this.set({ loading: false }) return true
}
}, },
async onSubmit (e) { async onSubmit (e) {
e.preventDefault() e.preventDefault()

View file

@ -81,6 +81,7 @@
this.fire('recalculateHeight') this.fire('recalculateHeight')
stop('clickSpoilerButton') stop('clickSpoilerButton')
}) })
return true
} }
} }
} }

View file

@ -77,22 +77,22 @@
optionsKey optionsKey
} = this.get() } = this.get()
registerClickDelegates(this, { registerClickDelegates(this, {
[favoriteKey]: (e) => { [favoriteKey]: () => {
e.preventDefault()
e.stopPropagation()
this.toggleFavorite() this.toggleFavorite()
return true
}, },
[reblogKey]: (e) => { [reblogKey]: () => {
e.preventDefault()
e.stopPropagation()
this.reblog() this.reblog()
return true
}, },
[replyKey]: (e) => { [replyKey]: () => {
e.preventDefault()
e.stopPropagation()
this.reply() this.reply()
return true
}, },
[optionsKey]: (e) => this.onOptionsClick(e) [optionsKey]: () => {
this.onOptionsClick()
return true
}
}) })
on('postedStatus', this, this.onPostedStatus) on('postedStatus', this, this.onPostedStatus)
}, },
@ -127,9 +127,7 @@
this.fire('recalculateHeight') this.fire('recalculateHeight')
}) })
}, },
async onOptionsClick (e) { async onOptionsClick () {
e.preventDefault()
e.stopPropagation()
let { originalStatus, originalAccountId } = this.get() let { originalStatus, originalAccountId } = this.get()
let updateRelationshipPromise = updateProfileAndRelationship(originalAccountId) let updateRelationshipPromise = updateProfileAndRelationship(originalAccountId)
let showStatusOptionsDialog = await importShowStatusOptionsDialog() let showStatusOptionsDialog = await importShowStatusOptionsDialog()

View file

@ -28,9 +28,10 @@ function onEvent (e) {
return // ignore if the user is selecting text inside the clickable area return // ignore if the user is selecting text inside the clickable area
} }
} }
e.preventDefault() if (callbacks[key](e)) { // callback returns true to indicate it has handled the action
e.stopPropagation() e.preventDefault()
callbacks[key](e) e.stopPropagation()
}
} }
} }