Closed Bug 1634153 Opened 3 months ago Closed 3 months ago

focus({preventScroll: true}); does not work on textareas

Categories

(Core :: DOM: Core & HTML, defect, P2)

75 Branch
defect

Tracking

()

RESOLVED FIXED
mozilla77
Tracking Status
firefox77 --- fixed

People

(Reporter: caleb, Assigned: emilio)

References

Details

Attachments

(2 files)

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1 Safari/605.1.15

Steps to reproduce:

Probably just skip to the fiddle here:

https://jsfiddle.net/xya79cqL/

Summary of the repro:

  1. Scroll a textarea out of view
  2. Call el.focus({preventScroll: true}) where el is an HTMLTextareaElement
  3. Page scrolls even though it shouldn't.

Other notes:

  • Nightly is affected
  • It works correctly for <input>
  • I haven't tested any other kinds of elements.
  • Chrome does this correctly.

Actual results:

Page scrolls.

Expected results:

Page should not have scrolled.

Severity: normal → --
Component: Untriaged → DOM: Core & HTML
Product: Firefox → Core

This is because bug 353539 introduced back in the day a way to scroll to the caret of the textarea, but that doesn't restrict the scrolling to the textarea, and also tries to scroll the textarea into view.

Assignee: nobody → emilio
Status: UNCONFIRMED → NEW
Ever confirmed: true
See Also: → 353539

Bug 353539 introduced a ScrollOnFocusEvent to scroll the caret on focus
whenever the form control was focused.

However ScrollOnFocusEvent::Run was forgetting to pass
nsISelectionController::SCROLL_FIRST_ANCESTOR_ONLY, so it was also
scrolling the document, which is pretty unexpected when you use
.focus({ preventScroll: true }) for example.

Use ScrollSelectionIntoView instead, does the right thing and is what
the original bug intended anyhow.

To make clear it happens async.

Depends on D73181

Pushed by ealvarez@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/04108f403e7b
Make textarea focus code not unconditionally scroll. r=masayuki
https://hg.mozilla.org/integration/autoland/rev/86989c06d090
Rename and devirtualize nsITextControlFrame::ScrollSelectionIntoView. r=masayuki
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/23345 for changes under testing/web-platform/tests
Upstream web-platform-tests status checks passed, PR will merge once commit reaches central.
Priority: -- → P2
Status: NEW → RESOLVED
Closed: 3 months ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla77
Upstream PR merged by moz-wptsync-bot
Regressions: 1634456
Regressions: 1644366
You need to log in before you can comment on or make changes to this bug.