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
[selectors] Proposal for a :hover-only pseudo class #7544
Comments
This comment was marked as off-topic.
This comment was marked as off-topic.
I like this idea. If we want to follow the same naming convention as with the media query |
This is very much needed!
Another reason why the |
Hi @devongovett, thanks for the detailed proposal. I agree that the behavior of Mice and fingers are different interfaces and therefore there can be different interpretations about what some states such as hover mean on touch devices. One possible interpretation is that hover should not be possible with touch events as you propose, but I think another worthy of reflection is that hover could be activated while the finger is held down and on the target*. In other words, something could be considered "hovered" when it has what in react-aria you call isPressed state. *note: I know that react-aria's I wouldn't be surprised if you've spent more time on these questions than anyone else, so you probably have good reasons to prefer the behavior you described. If so, I would like to know them :) |
@GermanJablo – I can't answer for Devon, but a couple thoughts I had reading your reply:
|
Yes, my proposal did not consist of that. It could be a new pseudo class.
Well, to quote myself, "Mice and fingers are different interfaces and therefore there can be different interpretations about what some states such as hover mean on touch devices." In this case your interpretation is that the hover indicates that it can be clicked/pressed. But as I said, I think another valid interpretation could be that hover indicates that something can be clicked/pressed OR that it is being pressed/clicked. Personally, if I press a button on my mobile I have an expectation that it will turn a slightly different color while it is being pressed. I consider it to be feedback from the UI to the user that if he releases his finger from that position, an operation will be performed. That said, it's also true that what I'm saying could be achieved with a combination of Again, I don't 100% disagree with your interpretation, I just think there are two valid readings. And in a decision as important as this one, I think they should be considered and discussed. |
@GermanJablo – What you describe sounds like |
Thanks @devongovett for starting this issue. I was thinking and complaining about the same issue recently and have my own write up explaining the problem and possible solutions. Some of it may be a bit repetitive, but I want to share it here so we can discuss some of the details before one us can start a more formal proposal to get this problem solved. ProblemDue to legacy reasons, The specific problem is that on modern touchscreen OSs, hover interactions "stick". I.e, After touching and letting on an element with Further, the existing Adobe has a detailed blog post explaining the problem and how they had to resort to using Javascript to solve it. Desired OutcomeThere are two possible desired outcomes:
ProposalsThere are at least two possible ways to solve this problem: 1. A new
|
Intro
The current
:hover
pseudo class has an issue: due to backward compatibility with older sites, it applies on tap on touch devices. This makes sense as it ensures that older sites not designed for compatibility with touch devices are usable (e.g. hover menus). However, it also leads to sub-optimal experiences in many cases, where the hover state "sticks" on tap. Ideally it wouldn't apply at all on touch devices.The
hover
/any-hover
media queries appear to be a workaround to this. Wrap your:hover
selectors in those, and they won't apply on touch devices. However, this does not work correctly on devices with both pointer and touch support, e.g. modern iPads, Windows laptops with touch screens, etc. The media query doesn't update based on the input device the user is currently using, only based on what devices are available. Therefore, sometimes the hover effect either doesn't apply when it should, or applies when it shouldn't depending on the current input device.Currently, the only way to work around this is to apply classes with JavaScript based on pointer events rather than using
:hover
. I wrote more details and examples in this blog post.Proposal
I would like to propose a new
:hover-only
pseudo class. This would apply only when hovering with a pointer or another device capable of hover, and would not apply when using touch input, stylus input, etc. Updating the existing:hover
pseudo class to have this behavior would be a huge breaking change, so I think a new pseudo class is needed here.While this can be achieved with JavaScript, I think a CSS-only solution would be very nice. Writing the JS from scratch to handle this is quite involved, and likely not as performance optimized as something browsers could implement natively. Due to the complexity, most websites don't implement this, leading to a worse user experience. I think if it were built into the web platform and easier for developers to get right, the UX of hoverable elements across the web could be improved.
The text was updated successfully, but these errors were encountered: