Closed Bug 2037337 Opened 8 days ago Closed 7 days ago

Focus lost from slotted element on slot wrapper reorder in shadow DOM

Categories

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

Firefox 148
defect

Tracking

()

RESOLVED FIXED
152 Branch
Tracking Status
firefox-esr115 --- unaffected
firefox-esr140 --- unaffected
firefox150 --- wontfix
firefox151 --- wontfix
firefox152 --- fixed

People

(Reporter: serguey.kulikov, Assigned: emilio)

References

(Regression)

Details

(Keywords: nightly-community, regression)

Attachments

(2 files)

Steps to reproduce:

Reproduction: https://codepen.io/web-padawan/pen/dPOYdJa or see .html attached

Problem: when a slotted element is focused, reordering its slot wrapper in shadow DOM causes document.activeElement to be moved to <body> without a blur event.

Possibly related to https://bugzilla.mozilla.org/show_bug.cgi?id=2037008

Actual results:

Focus silently moves to <body> without firing blur / focusout events.

Expected results:

Focus should remain on the slotted element and document.activeElement should not change to <body>.

Status: UNCONFIRMED → NEW
Component: Untriaged → DOM: UI Events & Focus Handling
Ever confirmed: true
Product: Firefox → Core
Regressed by: 1996182

:emilio, since you are the author of the regressor, bug 1996182, could you take a look? Also, could you set the severity field?

For more information, please visit BugBot documentation.

Flags: needinfo?(emilio)

So this changed behavior but I think the new behavior is more consistent with other DOM moves isn't it?

You're reordering the <slot> by moving them around, the fact that that didn't blur seems like a bug? You're removing the thing you're slotting into.

The behavior change is because I tweaked this line to use the flat tree.

I'm curious about the use case for this (isn't moveBefore() a better API for what you want to do anyways?).

The spec is woefully undefined here... I guess you could argue that the <input> is still in the dom and in this case it happens to still be in the flattened tree before the focus fixup runs...

Flags: needinfo?(emilio) → needinfo?(serguey.kulikov)
See Also: → 2037008
Duplicate of this bug: 2037008

Thank you for taking a look. For the record, the original issue manifested in our web component that re-assigns slot attribute on child elements when re-rendering. IMO if the element that has focus remains in the DOM, the fact that it's losing focus is somewhat unexpected, but I agree it's an edge case. If this is considered wontfix, we'd have to stick to a workaround to re-focus it.

Flags: needinfo?(serguey.kulikov)
Assignee: nobody → emilio
Attachment #9583654 - Attachment description: WIP: Bug 2037337 - Restore focus removal behavior. → Bug 2037337 - Restore focus behavior when removing a slot but not the focused node. r=smaug
Status: NEW → ASSIGNED

Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/59708 for changes under testing/web-platform/tests

Status: ASSIGNED → RESOLVED
Closed: 7 days ago
Resolution: --- → FIXED
Target Milestone: --- → 152 Branch

Upstream PR merged by moz-wptsync-bot

The patch landed in nightly and beta is affected.
:emilio, is this bug important enough to require an uplift?

For more information, please visit BugBot documentation.

Flags: needinfo?(emilio)

Relatively late in the beta cycle for something regressed in 146, IMHO.

Flags: needinfo?(emilio)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: