Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parents(selector) does not find ancestors by selector #1235

Closed
gormster opened this issue Nov 23, 2021 · 0 comments
Closed

parents(selector) does not find ancestors by selector #1235

gormster opened this issue Nov 23, 2021 · 0 comments

Comments

@gormster
Copy link
Contributor

Bug report

parents(selector) does not behave as expected. It does not always terminate at the closest matching ancestor; instead, this behaviour only occurs if the first element matching the selector in the document is a direct ancestor of the calling element.

Fiddle

https://jsfiddle.net/gormster/2xw7sape/

Explanation

Expected behaviour

parents(selector) should return the ancestors of the current element up until an element that matches selector, as documented. In the supplied fiddle, both circles should turn green.

Actual behaviour

The returned list of elements only terminates if the first element in the document that matches selector is a direct ancestor of the calling element. In other words, if element.root().findOne(selector) is in element.parents(), then element.parents(selector) works (almost) as expected. However:

  • If there are multiple elements in the parent chain that match the selector, parents(selector) matches the furthest element, not the closest one (https://jsfiddle.net/gormster/erhwjv1c/)
  • If there are multiple elements in the document that match the selector, and the first such element is not in the parent chain, parents(selector) returns all parents including the elements in the containing HTML document (https://jsfiddle.net/gormster/2xw7sape/)
  • If there are no elements in the document that match the selector, parents(selector) throws a TypeError (https://jsfiddle.net/gormster/c7k23vt0/)
gormster added a commit to gormster/svg.js that referenced this issue Nov 23, 2021
This is literally all you have to do to break this function... just have
one single other group in your document.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant