9
9
10
10
from textual import _widget_navigation
11
11
from textual .binding import Binding , BindingType
12
- from textual .containers import Container
12
+ from textual .containers import VerticalScroll
13
13
from textual .events import Click , Mount
14
14
from textual .message import Message
15
15
from textual .reactive import var
16
16
from textual .widgets ._radio_button import RadioButton
17
17
18
18
19
- class RadioSet (Container , can_focus = True , can_focus_children = False ):
19
+ class RadioSet (VerticalScroll , can_focus = True , can_focus_children = False ):
20
20
"""Widget for grouping a collection of radio buttons into a set.
21
21
22
22
When a collection of [`RadioButton`][textual.widgets.RadioButton]s are
@@ -42,7 +42,7 @@ class RadioSet(Container, can_focus=True, can_focus_children=False):
42
42
* ToggleButton. If those styles ever get updated, these should be too.
43
43
*/
44
44
45
- RadioSet > * {
45
+ RadioSet > RadioButton {
46
46
background: transparent;
47
47
border: none;
48
48
padding: 0 1;
@@ -188,6 +188,7 @@ def watch__selected(self) -> None:
188
188
self .query (RadioButton ).remove_class ("-selected" )
189
189
if self ._selected is not None :
190
190
self ._nodes [self ._selected ].add_class ("-selected" )
191
+ self ._scroll_to_selected ()
191
192
192
193
def _on_radio_button_changed (self , event : RadioButton .Changed ) -> None :
193
194
"""Respond to the value of a button in the set being changed.
@@ -276,3 +277,9 @@ def action_toggle_button(self) -> None:
276
277
button = self ._nodes [self ._selected ]
277
278
assert isinstance (button , RadioButton )
278
279
button .toggle ()
280
+
281
+ def _scroll_to_selected (self ) -> None :
282
+ """Ensure that the selected button is in view."""
283
+ if self ._selected is not None :
284
+ button = self ._nodes [self ._selected ]
285
+ self .call_after_refresh (self .scroll_to_widget , button , animate = False )
0 commit comments