Closed Bug 1538299 Opened 6 years ago Closed 6 years ago

currently there is no way to focus a label element from within a script

Categories

(Core :: DOM: Core & HTML, defect, P3)

66 Branch
defect

Tracking

()

RESOLVED DUPLICATE of bug 1240285

People

(Reporter: wpirino1, Unassigned)

Details

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.75 Safari/537.36

Steps to reproduce:

  1. I created a page with just a single label element that looks like: <label tabindex="0">Test</label>
  2. I ran document.querySelector('label').focus()
  3. I then checked the value of document.activeElement

Actual results:

document.activeElement was set to the body element

Expected results:

document.activeElement should have been set to the label element

Works as expected in chrome/safari. Also works as expected if you replace the label with a span or div.

Summary: focus method has unexpected effect when called on a label element with tabindex → currently there is no way to focus a label element from within a script
Component: Untriaged → DOM: Core & HTML
Product: Firefox → Core
Has STR: --- → yes

As comment 1 said, span or div can be focussed by using focus() but label cannot.

If we associate a <label> with an <input> element, and try to focus it.
The input element can be focussed.

Priority: -- → P3
Status: UNCONFIRMED → RESOLVED
Closed: 6 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.