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

Proposal: elementsFromRect() #1286

Open
justinfagnani opened this issue May 2, 2024 · 1 comment
Open

Proposal: elementsFromRect() #1286

justinfagnani opened this issue May 2, 2024 · 1 comment
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest

Comments

@justinfagnani
Copy link

What problem are you trying to solve?

elementsFromPoint() allows us to utilize the browsers hit-testing get all elements under a specific coordinate. This is great for things like interactive editors that use DOM elements as the editable objects.

But such editors often have other kinds of selection gestures than just a single click that selects at a single coordinate. Often we'll have click-and-drag gestures for selecting all elements under a rectangular window. Some editors will have a lasso tool that lets users draw an irregular selection window. elementsFromPoint() is insufficient for these cases.

What solutions exist today?

There are two rough approaches I know of for finding all elements under a rect:

  1. Call elementsFromPoint() repeatedly in a grid pattern. This uses the native hit-testing mechanism, but it can obviously miss elements that fall between the grid points.

  2. Re-implement hit testing and crawl the entire DOM looking for intersecting elements. This is very difficult and prone to error.

How would you solve it?

Add elementsFromRect() (and possibly elementsFromPath()) that return all elements intersecting the given rect.

Anything else?

No response

@justinfagnani justinfagnani added addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest labels May 2, 2024
@annevk
Copy link
Member

annevk commented May 3, 2024

This should be filed against CSSOM View. Once you file it there could you please link it from here and close this?

(Although I'm not sure we should do this until someone actually defines hit testing.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest
Development

No branches or pull requests

3 participants
@justinfagnani @annevk and others