Can't programatically focus a contenteditable label element
Categories
(Core :: DOM: UI Events & Focus Handling, defect, P3)
Tracking
()
People
(Reporter: emilio, Unassigned)
Details
data:text/html,<label contenteditable style="display: block; user-select: text">Foo</label><button onclick='document.querySelector("label").focus()'>Focus label</button>
Click and tab navigation do focus the element, so this is pretty weird behavior IMO.
Reporter | ||
Comment 1•5 years ago
|
||
WDYT Masayuki? I think we should allow to programatically focus the element, but wanted to double-check with you.
Comment 2•5 years ago
|
||
I think that <label>
element should do nothing about focus handling if it's editable. For example, even if it's an element in contenteditable="true"
, clicking it should be treated as moving caret to the clicked position.
Updated•5 years ago
|
Comment 3•5 years ago
|
||
This is not any element, but labels specifically. If I replace label
with div
or span
, then the test works as expected.
HTMLLabelElement::focus
has been overridden, to delegate the focus to the labeled element as identified by the for
attribute, but when the for
attribute is not set, nothing happens.
I suppose that there should be a fallback to focusing the label
element if it is either a contentEditable host or has a tabIndex, after:
https://searchfox.org/mozilla-central/rev/5a10be606f2d76ef22f1f44565749490de991d35/dom/html/HTMLLabelElement.cpp#60-64
Updated•5 years ago
|
Updated•5 years ago
|
Description
•