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

[cssom] getClientRects / getBoundingClientRect for pseudo elements #6689

Open
WilcoFiers opened this issue Sep 27, 2021 · 4 comments
Open

[cssom] getClientRects / getBoundingClientRect for pseudo elements #6689

WilcoFiers opened this issue Sep 27, 2021 · 4 comments
Labels
Agenda+ Later Lower-priority items that are flagged for CSSWG discussion css-pseudo-4 Current Work

Comments

@WilcoFiers
Copy link

One of the big challenges in automated accessibility testing is to test for color contrast. And one of the biggest challenges in testing for color contrast is to figure out what is going on with pseudo elements on the page. It would be very helpful if, similar to window.getComputedStyle the Element.getClientRects and Element.getBoundingClientRect methods could accept an argument which tells the browser to return rect(s) of the pseudo element instead. This could look something like:

const pseudoRects = elm.getClientRects(':after');

This would help tools like axe-core, and other accessibility tools, which currently just sort of have to guess what's going on with the pseudo elements based on computed styles.

@tabatkins
Copy link
Member

There's a few other operations that would probably make sense for pseudo-elements as well. We had an older proposal for a PseudoElement object that you could retrieve with code like elm.pseudo("::before"), which would just expose a few methods like scrollTo() and getBoundingClientRect().

@tabatkins tabatkins added the css-pseudo-4 Current Work label Sep 27, 2021
@fantasai fantasai added the Agenda+ Later Lower-priority items that are flagged for CSSWG discussion label Dec 29, 2022
@harellevy
Copy link

looks like promising stuff. any workarounds instead of appending the same styles as pseudo to a temporary div element, calculating and removing it?

@paulirish
Copy link
Member

a PseudoElement object that you could retrieve with code like elm.pseudo("::before")

👀 Looks like this is in the current editor's draft: https://drafts.csswg.org/css-pseudo-4/#window-interface Def excited for that!

@josepharhar
Copy link
Contributor

This would also be helpful for customizable select's ::picker(select) pseudo-element, or any other part-like pseudo-element

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Agenda+ Later Lower-priority items that are flagged for CSSWG discussion css-pseudo-4 Current Work
6 participants