Skip to content

Commit

Permalink
[Fix #10] target vs currentTarget (#12)
Browse files Browse the repository at this point in the history
Co-authored-by: Jeremy Walton <[email protected]>
  • Loading branch information
OutlawAndy and Jeremy-Walton authored Sep 27, 2023
1 parent 53501ed commit 66dc7e9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@rolemodel/turbo-confirm",
"type": "module",
"version": "1.1.0",
"version": "1.1.1",
"description": "Drop-in upgrade for Rails' data-turbo-confirm feature to support custom HTML dialogs.",
"main": "src/index.js",
"directories": {
Expand Down
14 changes: 6 additions & 8 deletions src/lib/ConfirmationController.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,12 @@ export default class ConfirmationController {
}, this.#config.animationDuration)
}

#clickTarget({currentTarget}) {
// Turbo listens for link clicks on the document.
if (currentTarget === document) {
// in this case, activeElement is the link that was clicked
return currentTarget.activeElement.closest(`[data-turbo-confirm]`)
} else {
return currentTarget.closest(`[data-turbo-confirm]`)
}
#clickTarget({target}) {
// in the case of a turbo link intercept, the target is the document.
// Form submissions still have the original submitter as the target.
const element = target.activeElement ?? target

return element.closest('[data-turbo-confirm]')
}

#setupListeners() {
Expand Down

0 comments on commit 66dc7e9

Please sign in to comment.