Skip to content

Commit

Permalink
Polyfill SVGElement.contains()
Browse files Browse the repository at this point in the history
  • Loading branch information
javan committed Sep 17, 2019
1 parent 9267d8b commit aa76e25
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/@stimulus/core/src/tests/cases/action_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ export default class ActionTests extends LogControllerTestCase {
<div id="multiple" data-action="click->c#log click->c#log2 mousedown->c#log"></div>
</div>
<div id="outside"></div>
<svg id="svgRoot" data-controller="c" data-action="click->c#log">
<circle id="svgChild" data-action="mousedown->c#log" cx="5" cy="5" r="5">
</svg>
`

async "test default event"() {
Expand Down Expand Up @@ -51,4 +54,13 @@ export default class ActionTests extends LogControllerTestCase {
{ name: "log2", eventType: "click" }
)
}

async "test actions on svg elements"() {
await this.triggerEvent("#svgRoot", "click")
await this.triggerEvent("#svgChild", "mousedown")
this.assertActions(
{ name: "log", eventType: "click" },
{ name: "log", eventType: "mousedown" }
)
}
}
6 changes: 6 additions & 0 deletions packages/@stimulus/polyfills/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ import "core-js/fn/set"
import "element-closest"
import "mutation-observer-inner-html-shim"
import "eventlistener-polyfill"

if (typeof SVGElement.prototype.contains != "function") {
SVGElement.prototype.contains = function(node) {
return this === node || this.compareDocumentPosition(node) & Node.DOCUMENT_POSITION_CONTAINED_BY
}
}

0 comments on commit aa76e25

Please # to comment.