Bug 238093 - preventScroll does not work with dynamically created elements
Summary: preventScroll does not work with dynamically created elements
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: Forms (show other bugs)
Version: Safari 15
Hardware: Mac (Intel) macOS 11
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-03-18 13:46 PDT by Elliot Nahman
Modified: 2024-05-03 05:13 PDT (History)
7 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Elliot Nahman 2022-03-18 13:46:22 PDT
Safari 15 appears to have implemented the preventScroll option for Element.focus(). See the resolved webkit bug: https://bugs.webkit.org/show_bug.cgi?id=178583. 

While this feature works fine for elements already existing in the DOM, it does not work for dynamically added elements. 

Please see: https://codepen.io/nonmetalhail/pen/KKZzagd
Comment 1 Simon Fraser (smfr) 2022-03-18 13:52:27 PDT
Thanks for the report. I can reproduce.
Comment 2 Radar WebKit Bug Importer 2022-03-18 13:52:39 PDT
<rdar://problem/90502768>
Comment 3 Simon Fraser (smfr) 2022-03-18 14:12:36 PDT
In the bad case we're scrolling via FrameSelection::updateAppearanceAfterLayoutOrStyleChange().
Comment 4 Simon Fraser (smfr) 2022-03-18 14:17:42 PDT
Layout calls FrameSelection::setNeedsSelectionUpdate() which resets m_selectionRevealMode to SelectionRevealMode::Reveal here:

    if (innerTextSizeChanged && frame().selection().isFocusedAndActive() && document().focusedElement() == &inputElement()) {
        // The caps lock indicator was hidden or shown. If it is now visible then it may be occluding
        // the current selection (say, the caret was after the last character in the text field).
        // Schedule an update and reveal of the current selection.
        frame().selection().setNeedsSelectionUpdate(FrameSelection::RevealSelectionAfterUpdate::Forced);
    }

This is trying to ensure that text within the input is scrolled into view, but has the side effect of also triggering page scrolling.