You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Should widgets scroll to highlighted item when resized? #5580
I've been hesitant to create an issue for this, but should widgets automatically scroll to the highlighted item after being resized? Or is this something that is expected to be handled by the developer?
The below example with an OptionList hopefully demonstrates what I mean. Obviously resizing the terminal could also cause the highlighted item to go out of view.
fromtextual.appimportApp, ComposeResultfromtextual.containersimportHorizontalfromtextual.widgetsimportFooter, OptionList, PlaceholderclassExampleApp(App):
BINDINGS= [
("t", "toggle_panel", "Toggle Panel"),
]
CSS=""" Placeholder { width: 2fr; display: none; } .show-panel { Placeholder { display: block; } } """defcompose(self) ->ComposeResult:
withHorizontal():
yieldOptionList(
*[
f"This is option {i} which is long and might wrap when the widget is resized"foriinrange(100)
]
)
yieldPlaceholder()
yieldFooter()
defon_mount(self) ->None:
options=self.query_one(OptionList)
options.highlighted=50defaction_toggle_panel(self) ->None:
self.toggle_class("show-panel")
if__name__=="__main__":
app=ExampleApp()
app.run()
It probably should... I can't think of any reason why not scrolling would be more desirable. Should be a simple fix. Calling scroll_to_highlight on the resize event.
I could see reasons why I wouldn't want this. If I've got the highlighted item scrolled out of view, it might suggest I'm reading other items in the list. What is highlighted doesn't always correspond to where my attention currently is. If I resize in this case, I definitely would want to try and keep my current reading position in the list (in other words: don't scroll).
Activity
github-actions commentedon Feb 25, 2025
We found the following entries in the FAQ which you may find helpful:
Feel free to close this issue if you found an answer in the FAQ. Otherwise, please give us a little time to review.
This is an automated reply, generated by FAQtory
willmcgugan commentedon Feb 26, 2025
It probably should... I can't think of any reason why not scrolling would be more desirable. Should be a simple fix. Calling
scroll_to_highlighton the resize event.darrenburns commentedon Mar 3, 2025
I could see reasons why I wouldn't want this. If I've got the highlighted item scrolled out of view, it might suggest I'm reading other items in the list. What is highlighted doesn't always correspond to where my attention currently is. If I resize in this case, I definitely would want to try and keep my current reading position in the list (in other words: don't scroll).
TomJGooding commentedon Mar 3, 2025
@darrenburns Fair point. I'm usually navigating with the keyboard, so hadn't considered if you'd scrolled away from the highlight using the mouse.
github-actions commentedon May 31, 2026
I hope I solved your issue!
Consider sponsoring my work to continue to maintain and develop Textual.