diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/elements/Element.js | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/elements/Element.js b/src/elements/Element.js index f39f777..2aaeab5 100644 --- a/src/elements/Element.js +++ b/src/elements/Element.js @@ -87,7 +87,10 @@ export default class Element extends Dom { // return array of all ancestors of given type up to the root svg parents (until = this.root()) { - until = makeInstance(until) + const isSelector = typeof until === 'string' + if (!isSelector) { + until = makeInstance(until) + } const parents = new List() let parent = this @@ -98,9 +101,16 @@ export default class Element extends Dom { parents.push(parent) - if (parent.node === until.node) { + if (!isSelector && (parent.node === until.node)) { + break + } + if (isSelector && parent.matches(until)) { break } + if (parent.node === this.root().node) { + // We worked our way to the root and didn't match `until` + return null + } } return parents |