When Element.focus() is used, the element should be scrolled into view such that the element is in a defined position. Currently dom-focus states:
[...] scroll the element into view with scroll behavior "auto", block flow direction position set to an implementation-defined value, and inline base direction position set to an implementation-defined value.
Added focus/focus-centers-element.html in web-platform-tests/wpt#41029 that essentially checks that Element.focus() behaves similar to Element.scrollIntoView({block: "center", inline: "center"}).
| Test |
Blink |
WebKit |
Gecko |
Gecko (after bug 1842679) |
Element.focus() center in the block direction |
✅ |
✅ |
❌ |
✅ |
Element.focus() center in the inline direction |
✅ |
✅ |
❌ |
✅ |
Element.focus() center in both directions |
✅ |
✅ |
❌ |
✅ |
Since browsers seem to agree that Element.focus() should center the element, it might make sense to specify this instead of leaving this implementation defined. Several web-platform tests assume that Element.focus() will cause an element to end in a certain scroll position (e.g. css/css-scroll-snap/scroll-target-margin-005.html), but AFAIK this is essentially undefined behavior (at least from the specs point of view).
When Element.focus() is used, the element should be scrolled into view such that the element is in a defined position. Currently dom-focus states:
Added
focus/focus-centers-element.htmlin web-platform-tests/wpt#41029 that essentially checks thatElement.focus()behaves similar toElement.scrollIntoView({block: "center", inline: "center"}).Element.focus() center in the block directionElement.focus() center in the inline directionElement.focus() center in both directionsSince browsers seem to agree that
Element.focus()should center the element, it might make sense to specify this instead of leaving this implementation defined. Several web-platform tests assume thatElement.focus()will cause an element to end in a certain scroll position (e.g.css/css-scroll-snap/scroll-target-margin-005.html), but AFAIK this is essentially undefined behavior (at least from the specs point of view).