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

Add support for pseudo class :has #1

Open
wants to merge 1 commit into
base: pseudo-class-is
Choose a base branch
from

Conversation

tornqvist
Copy link
Owner

@tornqvist tornqvist commented Feb 7, 2022

A naive implementation of the :has (aka. parent) selector. It only supports selecting children but not any of the more complex and interesting uses of the selector. It does however avoid crashing on unrecognized new syntax, see leeoniya#55 (comment).

div:has(span) { … } /* will match <div><span></span><div> */
span:has(+ span) { … } /* will not match <div><span></span><span></span><div> */

I also noticed that pseudo class selectors don't support multiple selectors, e.g. :not(span, div) but that is a different matter.

@tornqvist tornqvist changed the title Add support for pseudo class has Add support for pseudo class :has Feb 7, 2022
@leeoniya
Copy link

leeoniya commented Feb 7, 2022

@tornqvist did you mean to open this against the main repo?

It only supports selecting children

any barriers to just doing this recursively?

@tornqvist
Copy link
Owner Author

tornqvist commented Feb 7, 2022

This change is very similar to leeoniya#59 so I opened it here to avoid merge conflicts. If both are accepted I could merge this before you accept the other one but if you prefer, I could open a PR against the main repo.

any barriers to just doing this recursively?

My specific use case is for selecting an element preceding a specific sibling, e.g. .foo:has(+ .bar), and this doesn't support that. I can't see how that could be achieved with recursive :has(…):has(…). Or maybe that's not what you meant? But this does fix the crash, which is enough for me for the time being.

@tornqvist
Copy link
Owner Author

I take it you're not opposed to this fix, @leeoniya? Should I go ahead and merge it into the :is branch and we can then merge that into the main repo, given that you're okay with these two changes?

@leeoniya
Copy link

sorry, i will take a closer look at both of your PRs over the weekend. been a bit busy past week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants