Closed Bug 1842679 Opened 2 years ago Closed 2 years ago

Element.focus() should scrollIntoView with block/inline set to "center" when a scroll is needed

Categories

(Core :: Layout: Scrolling and Overflow, task, P3)

task

Tracking

()

RESOLVED FIXED
117 Branch
Tracking Status
firefox117 --- fixed

People

(Reporter: dlrobertson, Assigned: dlrobertson)

References

(Regressed 1 open bug)

Details

Attachments

(3 files)

Attached file element-focus.html

Summary

When Element.focus() is used, the element should be scrolled into view such that the element is centered when the scroll completes

Steps to reproduce

  1. Navigate to the attached test case
  2. Click the "Focus" button
  3. Observe the position of the red element

Expected results

The red element should be in the center of the viewport

Actual results

The red element is at the very bottom of the viewport

Discussion

This is technically allowed by the spec, as dom-focus states:

... block flow direction position set to an implementation-defined value, and inline base direction position set to an implementation-defined value.

However, both chrome and safari both use block: "center" and inline: "center". This might make it worthwhile to update to the same behavior as chrome and safari. In particular Element.focus() is used in some web-platform-tests. It may be that we fail or pass for invalid reasons due to our behavior here.

This will some impacts where documents depend on our current behavior.

Severity: -- → S3
Priority: -- → P3
See Also: → 1843227
Duplicate of this bug: 1843251

I think we should do this in this release cycle, wdyt? It'd be bad shipping inconsistent behavior between keyboard and regular .focus(), in particular because script focus is commonly used by pages to implement custom keyboard / mouse behavior.

Flags: needinfo?(drobertson)

(In reply to Emilio Cobos Álvarez (:emilio) from comment #3)

I think we should do this in this release cycle, wdyt?

Yeah, I can try to get this done. There were quite a few tests that expect the current behavior of Element.focus(), but that makes this a reasonable background task to work on. If I don't make it to the top of the try highscores chart, I'll be disappointed :p

It'd be bad shipping inconsistent behavior between keyboard and regular .focus(), in particular because script focus is commonly used by pages to implement custom keyboard / mouse behavior.

Is this severe enough to warrant feature gating or backing out the current fix for keyboard scrolls?

Flags: needinfo?(drobertson) → needinfo?(emilio)

(In reply to Dan Robertson (:dlrobertson) from comment #4)

Is this severe enough to warrant feature gating or backing out the current fix for keyboard scrolls?

I think we should avoid shipping the inconsistent behavior yes.

Flags: needinfo?(emilio)

At a glance try doesn't seem that unhappy:

I can take this I guess, if you're busy with other stuff.

Assignee: nobody → emilio
See Also: → 1818126

(In reply to Emilio Cobos Álvarez (:emilio) from comment #6)

I can take this I guess, if you're busy with other stuff.

I have time to work on it and I have an old revision that also changed the behavior of Element.focus() and fixed some of the tests... Most of them were reasonably easy fixes.

Ah, alright then! Feel free to steal :)

Assignee: emilio → drobertson

Element.focus() now centers an element in the block and inline
directions when the element should be scrolled into view. Update tests
to account for this.

Pushed by drobertson@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/f02a0e3200b0 Consistently scroll to center for focus. r=dlrobertson https://hg.mozilla.org/integration/autoland/rev/7ffbd7298f7b Update test expectations for Element.focus change. r=emilio,credential-management-reviewers,devtools-reviewers,sgalich,ochameau
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/41059 for changes under testing/web-platform/tests
Status: NEW → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 117 Branch
Upstream PR merged by moz-wptsync-bot
Regressions: 1844326
Regressions: 1858984
Regressions: 1857482
Regressions: 1874867
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: