What is the reasoning behind giving focus on hover? #6993
-
Hi! When we hover on for example these menu items here they gain focus. What's the source behind this behavior? Is it in some aria specs? Given how prevalent this pattern is (at least in react-aria) I hoped to find more resources backing it up, but currently this is the only post I've seen referencing it. Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 11 replies
-
This is a problem I'm having at the moment with MenuItems. I understand setting We end up having focus rings on hover. We do want very visible focus rings, but we also have a background colour for hover states, and the focus ring feels like overkill. We want the focus state to have higher visibility because it's harder for KB users to guess where focus will be transported to, whereas pointer device users always know where their pointer is. |
Beta Was this translation helpful? Give feedback.
Sorry for the delay @Joonaspraks, it looks like we missed this issue. I'll do my best to answer the questions here:
You should be able to use the renderProps for
isFocused
andisFocusVisible
, or the data-* attributes in order to determine if you should show the focus ring. We recommend doing this anyways because all the browsers handle:focus
and:focus-visible
differently. See https://react-spectrum.adobe.com/blog/building-a-button-part-3.html#focus-ringsAs for why focus is given on hover, that matches the native behaviour for menus and selects. You can see this by trying the https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/select component. Open it with your mouse, …