Drawer (Scroll to top on Open) #2114
-
If I have a drawer with a lot of scrollable content. If you close the drawer, then re-open, the scroll position remains where it was last. Is there a way to make a drawer "Scroll to the top" when you initially open it? Or have the scroll position reset when you close it?
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
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 dialog.setScrollPosition({ top, left }); Note that you wouldn't be able to call it after A property could also work, but would be less flexible. <sl-dialog reset-scroll-on-close>
...
</sl-dialog> |
Beta Was this translation helpful? Give feedback.
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.
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. usingrequestAnimationFrame()
), ot…