Skip to content

Commit 13cbecc

Browse files
authored
Add the :has-interest pseudo class (#1144)
* Add :has-interest pseudo class * Tweak * Final * Wish I knew why these won't display properly
1 parent 0d989b4 commit 13cbecc

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

site/src/pages/components/interest-invokers.explainer.mdx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ There is another category of devices which also falls into the "Other" category:
106106
When the HID is a mouse, where hover/de-hover is the method for showing and losing interest, delays are important for a number of reasons:
107107

108108
1. Simply hovering an element should not be enough to show interest in that element, since the user might just be moving the mouse from one place to another on the screen. It would be highly distracting to the user if such a move caused many popovers to show up. For this reason, showing interest needs to be done by hovering an element **for a period of time**.
109-
110109
2. For a similar reason, losing interest cannot be provided by *just* de-hovering the element. For example, in the common case of a link that has a hovercard, it is very common for the hovercard to be separated from the element by some padding space. And it is also common for the user to want to move their mouse *from* the link *to* the hovercard, e.g. to select and copy some text. However, since there's a gap between the elements, moving the mouse across that gap constitutes a de-hover of both the element and its target. For this reason, losing interest needs to be done by de-hovering the element (and its target) **for a period of time**.
111110

112111
Both of these time periods need to be CSS-configurable, because different use cases can require different delays. For example, a responsive gaming site might want very short delays, including potentially zero-delay. On the other hand, information-rich sites such as Wikipedia might want longer delays to ensure their content is easily accessible to all. To achieve this, two properties, `interest-target-show-delay` and `interest-target-hide-delay`, will control the corresponding delays. Because, as described above, both of these delays are fairly critical to proper operation of the interest mechanism, both properties will default to a non-zero value, 0.5 seconds. A shorthand `interest-target-delay` property will control both.
@@ -123,6 +122,30 @@ The same is not true for `interesttarget`. When the target is a popover, the onl
123122

124123
See https://github.com/openui/open-ui/issues/1064#issuecomment-2581511411 (particularly [this comment](https://github.com/openui/open-ui/issues/1064#issuecomment-2581511411)) for more discussion of this section.
125124

125+
## The `:has-interest` Pseudo Class
126+
127+
It is handy to be able to select elements that both a) have the `interesttarget` attribute, and b) are *currently* being shown interest. The `:has-interest` pseudo class matches elements in exactly this state. Two common use cases arise:
128+
129+
1. Styling the trigger element to indicate that it's showing interest:
130+
131+
```
132+
:has-interest {
133+
background-color: lightgreen;
134+
border: 2px solid green;
135+
}
136+
```
137+
138+
2. "Speeding up" the `interest-target-show-delay` when another element already has interest. This is a common request: for example, the first popover hovercard takes ~1 second to show up. But then if you quickly hover another element that also triggers a hovercard, that one shows up much more quickly:
139+
140+
```
141+
[interesttarget] {
142+
interest-target-delay: 1s;
143+
}
144+
container:has(:has-interest) [interesttarget] {
145+
interest-target-show-delay: 0s;
146+
}
147+
```
148+
126149
## Implementation Details
127150

128151
In the style of `commandfor`, we propose to add a global attribute called `interesttarget`, which can be used on `<button>`, `<a>`, and `<area>` elements:

0 commit comments

Comments
 (0)