[v2.0-rc] Calling scrollIntoView() does not work on Polaris web components

Calling .scrollIntoView() directly on Polaris web component elements has no effect. This was tested with <s-section>, <s-stack>, and <s-box>.

Example

<s-page>
  <s-button onClick={() => { document.getElementById('test')?.scrollIntoView() }}>
    Scroll to element
  </s-button>
  <s-box background="strong" blockSize="100%" />
  <s-section id="test">
    Test
  </s-section>  
</s-page>

Expected Behavior

Calling scrollIntoView() on the Polaris element scrolls the page to bring it into view.

Actual Behavior

Nothing happens. The scroll position does not change.

Workaround

Wrapping the component in a standard <div> and calling scrollIntoView() on that div works as expected:

<s-page>
  <s-button onClick={() => { document.getElementById('test')?.scrollIntoView() }}>
    Scroll to element
  </s-button>
  <div id="test">
    <s-section>
      Test
    </s-section>  
  </div>
</s-page>

Hi @TobiasDalhof I reproduced this in a small test in Chrome with both the current stable and 2.0 RC builds.

These components use display: contents on their outer element, so it doesn’t have its own layout box. scrollIntoView() stops when its target has no box. That explains why the <div> wrapper you found works: it gives the browser a box to scroll to.