Closed Bug 1739154 Opened 4 years ago Closed 4 years ago

delegatesFocus changes focused inner element when host is focused

Categories

(Core :: DOM: UI Events & Focus Handling, defect)

Firefox 94
defect

Tracking

()

RESOLVED FIXED
99 Branch
Tracking Status
firefox99 --- fixed

People

(Reporter: nlawson, Assigned: sefeng211)

References

(Blocks 1 open bug)

Details

Attachments

(2 files)

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

Steps to reproduce:

  1. Go to this URL: https://bl.ocks.org/nolanlawson/ef0cebcb48a5cf958d176056486642cd

Actual results:

It says "focused: first" and the first input is focused.

Expected results:

It should say "focused: second" and the second input should be focused.

As shown in the attached screenshot, Chrome 95 and Safari 15.1 have the correct behavior.

It also seems to depend on whether the focusable elements are inside an iframe. Here is a demo without an iframe – all three browsers correctly say "focused: second" in this case: https://bl.ocks.org/nolanlawson/ef0cebcb48a5cf958d176056486642cd

The key part of the code is this:

div.shadowRoot.querySelector('.second').focus()
div.focus()

Because div is a shadow host with delegatesFocus set to true, focusing it should not change the focus from the second input to the first input.

The Bugbug bot thinks this bug should belong to the 'Core::DOM: UI Events & Focus Handling' component, and is moving the bug to that component. Please revert this change in case you think the bot is wrong.

Component: Untriaged → DOM: UI Events & Focus Handling
Product: Firefox → Core

Sorry, I made a typo with the URLs I provided.

On my machine (MacOS Big Sur 11.6), I get the following results:

Firefox Nightly 96.0a1 Firefox 94.0
Iframe first (incorrect) first (incorrect)
No iframe second (correct) second (correct)

I.e., both versions behave the same (incorrectly) in the version with the iframe. Both are also correct for the version without the iframe.

Severity: -- → S2
Blocks: shadowdom
Flags: needinfo?(sefeng)

When the document is an embedded iframe, this check fails because the browsing context isn't a top level browsing context, and this makes the behaviour different.

Looks like I probably incorrectly interpreted the spec. I am making a patch to fix that.

Flags: needinfo?(sefeng)

According to the spec, focus delegate step should be run unless
the focus target is a shadow-including-ancestor of the current focus.
Our code didn't do this correctly.

Assignee: nobody → sefeng
Pushed by sefeng@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/ce9573bfe078 Fix a bug where focus delegate step may be run when it shouldn't be r=emilio
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/32740 for changes under testing/web-platform/tests
Regressions: 1754138
Status: UNCONFIRMED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → 99 Branch
Upstream PR merged by moz-wptsync-bot
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: