Replies: 1 comment 3 replies
-
Browsers will scroll the focused input into view automatically. I tested this in Chrome, Firefox, and Safari: https://codepen.io/claviska/pen/RwOZzNr?editors=1010 You shouldn't have to do anything with scrolling unless you want to reset the scroll position to zero after closing a dialog.
|
Beta Was this translation helpful? Give feedback.
-
So I have an <sl-dialog> that has sufficient data in it that it scrolls. The first field (an <sl-input>) in the dialog has the "autofocus" attribute set, so it receives the initial focus when the dialog opens. However, since the dialog is re-used, if it had previously been scrolled so the initial field is no longer visible, when I re-open the dialog, the autofocused field is not scrolled into view. Am I right in thinking that I need to handle the sl-initial-focus event for the dialog, and focus the initial field and then scroll it into view using Element:scrollIntoView()? Shoelace is really good about managing scrolling into view at other times, like when I tab through the fields in the dialog. It feels like the rule should be "when a field is focused, it scrolls into view automatically" which would apply equally to autofocusing when the dialog is first opened. Is this a feature request, or am I missing something?
Beta Was this translation helpful? Give feedback.
All reactions