Skip to content

Pseudo classes for the interesttarget API #12154

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

Open
mfreed7 opened this issue May 2, 2025 · 5 comments
Open

Pseudo classes for the interesttarget API #12154

mfreed7 opened this issue May 2, 2025 · 5 comments

Comments

@mfreed7
Copy link
Contributor

mfreed7 commented May 2, 2025

The explainer for interesttarget proposes four new pseudo classes:

  • :has-interest - matches on the invoker when the user is currently showing interest in that invoker.
  • :has-partial-interest - matches on the invoker when the user is currently showing partial interest in that invoker. (They have merely focused the invoker, but haven't fully-activated it via the hot-key.)
  • :target-of-interest - matches on the target of the invoker when the user is showing interest in the invoker for this target.
  • :target-of-partial-interest - matches on the target of the invoker when the user is showing partial interest in the invoker for this target.

To hopefully help with the terminology:

<button interesttarget=foo>The *invoker*</button>
<div popover id=foo>The *target* of the invoker</div>

A few notes:

  • It felt slightly easier to understand if :has-interest means "has any kind of interest" (including partial), and :has-partial-interest means "specifically only has partial interest". But suggestions appreciated.
  • @dbaron pointed out that these names are kind of ambiguous, and also that there is actually a third permutation (match on the invoker but describe the target) but I’m not sure there are use cases for that third set, so I'm not proposing it at this point.
  • As always, the names need bikeshedding. E.g. :has-interest or just :interest? And target-of-interest is somewhat descriptive but still leaves something to be desired. Maybe it’s ok.

Thoughts?

@tabatkins
Copy link
Member

Yeah, these naming patterns aren't quite consistent with what we use elsewhere.

What about:

  • :interest-invoker (matching any interest) and :interest-invoker(partial | total)? (total keyword just a guess)
  • :interest-target and :interest-target(partial | total), same meanings

Do we want to expose a state keyword for things that are potentially interest invokers/targets, but that are currently without any interest? Or is that ambiguous when interest isn't being shown?

@mfreed7
Copy link
Contributor Author

mfreed7 commented May 2, 2025

Yeah, these naming patterns aren't quite consistent with what we use elsewhere.

That doesn't surprise me! Thanks for the help with suggestions.

  • :interest-invoker (matching any interest) and :interest-invoker(partial | total)? (total keyword just a guess)

I like both. I assume the second suggestion was :interest-invoker-partial ? If so, I think that works.

  • :interest-target and :interest-target(partial | total), same meanings

Those were my initial stabs at names too, but the confusing thing is that the attribute is called interesttarget. So it might be confusing to have :interest-target match not on the element with interesttarget, but instead on the target of that element. Having said that, I'm also ok with this naming. Because I really don't like :interest-target-target.

Do we want to expose a state keyword for things that are potentially interest invokers/targets, but that are currently without any interest? Or is that ambiguous when interest isn't being shown?

Hmm. I think that can be handled with [interesttarget]:not(:interest-invoker), no? Perhaps you just mean it might be convenient to have a shorthand for that?

@tabatkins
Copy link
Member

I assume the second suggestion was :interest-invoker-partial ?

No, it was a functional pseudoclass that took a few keywords letting you indicate exactly what variety of interest you wanted to match on (while the non-functional one defaulted to some form of interest that we think is likely the most useful). So :interest-invoker(partial).

So it might be confusing to have :interest-target match not on the element with interesttarget, but instead on the target of that element.

I think that's fine - the interesttarget attribute indicates which element is the interest target. It doesn't indicate that the element with the attribute is the interest target.

Hmm. I think that can be handled with [interesttarget]:not(:interest-invoker), no? Perhaps you just mean it might be convenient to have a shorthand for that?

I wasn't sure there was a way to express that; not all negative selectors actually can be written explicitly in a simple manner. I think a shorthand is convenient, yes, since you're likely writing your actual-interest selectors as just :interest-invoker, and having to add the [interesttarget] (to avoid :not(:interest-invoker) over-matching on the rest of the page) isn't super obvious.

@mfreed7
Copy link
Contributor Author

mfreed7 commented May 5, 2025

No, it was a functional pseudoclass that took a few keywords letting you indicate exactly what variety of interest you wanted to match on (while the non-functional one defaulted to some form of interest that we think is likely the most useful). So :interest-invoker(partial).

Oh! Duh, reading it again, I can see this clearly. I like this idea! Are there other functional pseudo classes that also work without the ()? Either way I like the idea, and my vote would be for :interest-invoker (without ()) to be sugar for :interest-invoker(total) - that's usually the most useful selector, since it's a superset of :interest-invoker(partial).

I think that's fine - the interesttarget attribute indicates which element is the interest target. It doesn't indicate that the element with the attribute is the interest target.

Fair enough.

Do we want to expose a state keyword for things that are potentially interest invokers/targets, but that are currently without any interest? Or is that ambiguous when interest isn't being shown?

Hmm. I think that can be handled with [interesttarget]:not(:interest-invoker), no? Perhaps you just mean it might be convenient to have a shorthand for that?

I wasn't sure there was a way to express that; not all negative selectors actually can be written explicitly in a simple manner. I think a shorthand is convenient, yes, since you're likely writing your actual-interest selectors as just :interest-invoker, and having to add the [interesttarget] (to avoid :not(:interest-invoker) over-matching on the rest of the page) isn't super obvious.

Ok - I guess maybe the shorthand would be :interest-invoker(none) or something?

@tabatkins
Copy link
Member

Are there other functional pseudo classes that also work without the ()?

Yes, :host and :host(), for example. We've used it in a few other designs that ended up being dropped, too.

I guess maybe the shorthand would be :interest-invoker(none) or something?

Something like that. possible, maybe.

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

2 participants