hasKeyboardModality: suppress hadKeyboardEvent changes while typing. #260
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is submitted as a proposed improvement in behavior, and since it might be at variance with existing browser implementations of :focus-visible, it's reasonable to reject it. But I think it's worth discussing whether the minor improvement is desirable, and at least to put this PR in the repo history for anyone who feels .focus-visible should work this way.
In summary, this proposal improves the behavior when using Enter to submit a form causes the focus to shift to another element on the page.
The goal is to match user expectations in a common scenario for Single Page Apps and generally dynamic webpages. Say you have a search field that, when submitted, fetches data via XHR and displays it on the page, calling focus() on the first search result.
With the existing behavior, clicking into the field, typing the query, then hitting Enter will cause that first result to be focus-visible — due to the Enter keydown. That's unexpected for people who mostly use a pointer.
With this change, it's not the Enter keydown that determines focus-visible, it's the method by which you focused the field. If you used Tab to focus the field, the first result will be focus-visible. If you used a pointer to focus the field, it will not.
More details in the commit messages.