Skip to content

Commit

Permalink
Fix nested global action binding
Browse files Browse the repository at this point in the history
  • Loading branch information
javan committed Oct 9, 2020
1 parent d489ce3 commit 2b6facc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/@stimulus/core/src/binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class Binding {
} else if (eventTarget instanceof Element && this.element.contains(eventTarget)) {
return this.scope.containsElement(eventTarget)
} else {
return true
return this.scope.containsElement(this.action.element)
}
}

Expand Down
8 changes: 7 additions & 1 deletion packages/@stimulus/core/src/tests/cases/action_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default class ActionTests extends LogControllerTestCase {
<div data-controller="c" data-action="keydown@window->c#log">
<button data-action="c#log"><span>Log</span></button>
<div id="outer" data-action="click->c#log">
<div id="inner" data-controller="c" data-action="click->c#log"></div>
<div id="inner" data-controller="c" data-action="click->c#log keyup@window->c#log"></div>
</div>
<div id="multiple" data-action="click->c#log click->c#log2 mousedown->c#log"></div>
</div>
Expand Down Expand Up @@ -45,6 +45,12 @@ export default class ActionTests extends LogControllerTestCase {
this.assertActions({ name: "log", eventType: "keydown" })
}

async "test nested global actions"() {
const innerController = this.controllers[1]
await this.triggerEvent("#outside", "keyup")
this.assertActions({ controller: innerController, eventType: "keyup" })
}

async "test multiple actions"() {
await this.triggerEvent("#multiple", "mousedown")
await this.triggerEvent("#multiple", "click")
Expand Down

0 comments on commit 2b6facc

Please # to comment.