Closed Bug 1738777 Opened 4 years ago Closed 4 years ago

Tabbing order is incorrect when crossing a shadow root and manually calling focus

Categories

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

Firefox 93
defect

Tracking

()

VERIFIED FIXED
100 Branch
Tracking Status
firefox100 --- verified
firefox101 --- verified

People

(Reporter: elliot.nahman, Assigned: sefeng211)

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.54 Safari/537.36

Steps to reproduce:

In a layout using web components with Shadow DOM, one can tab to different items each living in their own shadow tree. However, manually calling focus on one item then resets the tabbing order to the start of the parent DOM tree instead of continuing on to the next tabbable item in the DOM.

See CodePen for example: https://codepen.io/nonmetalhail/pen/OJjjzej

In my CodePen example, there is a web component comprised of a button in a shadow root. When there are several on a page, you can hit Tab to go to the first button. Hitting Tab again takes you to a DIV with a tabindex and that DIV calls focus on the next web component button. Hitting Tab from the second button takes you back to the first button instead of the third button which is the next item in the DOM.

In the attached image, you see that FF appears to be calculating the correct overall tabbing order, 22 -> 23 ->24, but manually calling focus on the button resets it, causing it to go from 22 -> 23 -> (manual focus call) -> 22.

Chrome and Safari both move focus onto the next item in the DOM rather than reseting to the start.

Actual results:

After manually calling focus on something inside its own shadow tree, hitting Tab brings focus to the first item in the parent DOM tree.

In the example: 22 -> 23 -> (manual focus call) -> 22

Expected results:

After manually calling focus on something inside its own shadow tree, hitting Tab should brings focus to the next tabbable item in the parent DOM tree.

22 -> 23 -> (manual focus call) -> 24

Component: Untriaged → DOM: Core & HTML
Product: Firefox → Core
Component: DOM: Core & HTML → DOM: UI Events & Focus Handling
Severity: -- → S2

Hi Sean, I wonder if you have ideas of where our code may do something wrong. And would be interested in knowing if you have a different view on the severity. Thanks!

Flags: needinfo?(sefeng)

I think this happens when we couldn't find a focusable element in the shadow dom, we update the tabIndex and to continue the search from the top level shadow host. In this case, the tabIndex becomes -1, however I think we should start to ignore tabIndex to do further searches when it becomes -1, but we don't.

I'll make a patch to demonstrate the idea.

Assignee: nobody → sefeng
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true

Clearing my NI since I have the patch up.

Flags: needinfo?(sefeng)
Attachment #9266593 - Attachment description: Bug 1738777 - Check whether we need to ignore tabindex again when searching back from Shadow DOM to light DOM r=smaug → Bug 1738777 - Check whether we need to ignore tabindex again when doing sequential navigation r=smaug
Pushed by sefeng@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/ca57cb620eb3 Check whether we need to ignore tabindex again when doing sequential navigation r=edgar
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/33470 for changes under testing/web-platform/tests
Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → 100 Branch
Upstream PR merged by moz-wptsync-bot

Reproduced the issue on Firefox 95.0a1 (2021-06-10) under macOS 11.6.5 by using the STR from Comment 0.

The third item is now selected by tabbing on Firefox 100.0 and 101.0a1. Tests were performed on macOS 11.6.5, Ubuntu 20.04 and Windows 11.

Status: RESOLVED → VERIFIED
Flags: qe-verify+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: