w3c / uievents

UI Events
https://w3c.github.io/uievents/
Other
147 stars 51 forks source link

Explain that mousedown focuses form controls #81

Open cvrebert opened 8 years ago

cvrebert commented 8 years ago

Refs https://html.spec.whatwg.org/#activation:dom-click-2

Click-focusing behaviour (e.g. the focusing of a text field when user clicks in one) typically happens before the click, when the mouse button is first depressed, and is therefore not discussed here.

Nor is it discussed anywhere else in HTML. UI Events doesn't currently seem to cover this either, but I think it would be the logical place for it.

ConradIrwin commented 7 years ago

I think it also focuses things with tabindex, and presumably any other "focusable areas?" https://www.w3.org/TR/html51/editing.html#focusable

I ran into this because I was trying to find reference to this behaviour:

<div tabindex="-1" onfocus="console.log('div focus')">
  <span onclick="document.querySelector('input').focus()">click me</span>
  <input onfocus="console.log('input focus')">
</div>

Clicking on the span generates:

div focus
input focus
clshortfuse commented 1 year ago

Related Chrome bug: mousedown from buttons 4 and 5 cause focus and blur

It's not exactly the same because it causes a blur event (not the same as focusing a form element).

Firefox and Safari do not perform this behavior. But Chrome has it as the default action for the mousedown event which allows devs to call preventDefault on it.