Skip to content

Drawer (Scroll to top on Open) #2114

Discussion options

You must be logged in to vote

This isn't as intuitive as I'd like it to be, and it relies on digging into the shadow root to target the scroll container.

This applies to both dialog and drawer.

 dialog.addEventListener('sl-show', () => {
  requestAnimationFrame(() => {
    dialog.shadowRoot.querySelector('[part~="body"]').scrollTop = 0;
  });
});

Example: https://codepen.io/claviska/pen/oNrbLmg?editors=1000


@lindsaym-fa any thoughts on this? I'm not sure the dialog should automatically reset it's scroll position, as that might not always be desirable.

A method could work, but it's still a bit awkward to use because of timing. You have to call it at least one tick after sl-show (e.g. using requestAnimationFrame()), ot…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@lindsaym-fa
Comment options

Answer selected by EddieLongStockings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
3 participants