w3c / csswg-drafts

CSS Working Group Editor Drafts
https://drafts.csswg.org/
Other
4.44k stars 656 forks source link

:contains() #8164

Open oleedd opened 1 year ago

oleedd commented 1 year ago

What is with the :contains() selector? Why isn't it added? Can't find any info.

Loirooriol commented 1 year ago

If you want to propose a new selector, at least explain what elements it would match?

oleedd commented 1 year ago

It is not new. From your site: image https://learn.microsoft.com/en-us/previous-versions/troubleshoot/winautomation/process-development-tips/web-automation/how-to-use-the-contains-css-selector

Loirooriol commented 1 year ago

Well, current work is Selectors Level 4, which only mentions :contains() as an extension of JSONSelect. But OK, it was in the Nov 2001 CR of Level 3: https://www.w3.org/TR/2001/CR-css3-selectors-20011113/#content-selectors

The :contains("foo") pseudo-class notation represents an element whose textual contents contain the given substring. The argument of this pseudo-class can be a string (surrounded by double quotes) or a keyword.

oleedd commented 1 year ago

And what is with it? Browsers don't support it.

Loirooriol commented 1 year ago

This thread is relevant: https://lists.w3.org/Archives/Public/www-style/2012Apr/0377.html

In particular, https://lists.w3.org/Archives/Public/www-style/2012Apr/0380.html

It seems to be quite difficult to implement efficiently in the face of dynamic updates.

That's from 2012, things may have changed.

oleedd commented 1 year ago

What about Chrome?

This is perfectly appropriate for use in a static query, like for querySelector()

It is what I need. And the same with :on-screen().

I think we should add this back to Selectors, but create a "dynamic" and "static" profile

Has it started? It is a very good idea. Because layout selectors can be in the "static" profile.

Loirooriol commented 1 year ago

Profiles were already added in 483a3b693d7f60e504cff129b168e7667692defd. But later they were removed: ac45936684fe89c2658283c5aa0e3c401f66f207

oleedd commented 1 year ago

Why removed?

Loirooriol commented 1 year ago

Because the snapshot profile was only used by :has(), and from https://github.com/w3c/csswg-drafts/issues/3925#issuecomment-492724267

It was pointed out nobody impl :has not even in query selection. Spec should align with reality and not say you can use it.

oleedd commented 1 year ago

From that conversation:

Some features make this much harder, like contains() and especially the subject selector. It might be possible to do dynamic matching quickly, but it's a non-trivial task.

I suggest to ask the Chromium and Mozilla developers how it is for now.