Re: [csswg-drafts] [selectors] :focus-visible matches on initial programmatic focus (#5885)

> ... I think the Firefox behavior is the right one, because otherwise you don't show outlines for random focus moves that the user has no way of knowing about.

There's not much practical difference between

```js
newFocusTarget.focus();
```

and 

```
document.activeElement.blur();
newFocusTarget.focus();
```

Why should they result in different behaviour?

> > Under what circumstances do authors programmatically move focus?
> 
> I expect the current spec language is pretty useful to do stuff like: Click a button, open a menu, move the focus to that menu, or stuff like that.

Agreed, that is what the current spec covers - those are cases where a user interaction has caused focus to move, so we cue off the user interaction.

It's exceptionally hard to think of a case other than immediately after page load when an author would move focus not in response to a user interaction.

Given that Firefox and Safari have internally inconsistent (but consistent with the operating system) behaviour for focus on click on macOS (focus is set when clicking a focusable `<div>`, but not when clicking a `<button>`, for example), it might be worth adding some language to capture the case where a user has interacted with an element which does not receive focus on click in some cases, and that interaction caused focus to move.

> > Why would someone not currently or likely to immediately start using the keyboard want to know what the currently focused element is?
> 
> I don't know how this question is particularly relevant to this issue, but I agree that elements that accept keyboard input should always trigger focus-visible.

It's relevant to this earlier question:

> How is the user supposed to know what's focused otherwise?

My answer is that if the user is not about to use the keyboard, they don't need to know, and the remainder of the rules (including my proposed language from https://github.com/w3c/csswg-drafts/issues/5885#issuecomment-765008329) ensure that in the majority of cases where they would be likely to be interested in what element is focused, the focus is shown.




-- 
GitHub Notification of comment by alice
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/5885#issuecomment-767174862 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Monday, 25 January 2021 23:18:04 UTC