Skip to content

Commit

Permalink
fix(radioset): make radio set scrollable
Browse files Browse the repository at this point in the history
  • Loading branch information
TomJGooding committed Oct 11, 2024
1 parent 4d4fb73 commit 3c7d217
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/textual/widgets/_radio_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

from textual import _widget_navigation
from textual.binding import Binding, BindingType
from textual.containers import Container
from textual.containers import VerticalScroll
from textual.events import Click, Mount
from textual.message import Message
from textual.reactive import var
from textual.widgets._radio_button import RadioButton


class RadioSet(Container, can_focus=True, can_focus_children=False):
class RadioSet(VerticalScroll, can_focus=True, can_focus_children=False):
"""Widget for grouping a collection of radio buttons into a set.
When a collection of [`RadioButton`][textual.widgets.RadioButton]s are
Expand All @@ -42,7 +42,7 @@ class RadioSet(Container, can_focus=True, can_focus_children=False):
* ToggleButton. If those styles ever get updated, these should be too.
*/
RadioSet > * {
RadioSet > RadioButton {
background: transparent;
border: none;
padding: 0 1;
Expand Down Expand Up @@ -188,6 +188,7 @@ def watch__selected(self) -> None:
self.query(RadioButton).remove_class("-selected")
if self._selected is not None:
self._nodes[self._selected].add_class("-selected")
self._scroll_to_selected()

def _on_radio_button_changed(self, event: RadioButton.Changed) -> None:
"""Respond to the value of a button in the set being changed.
Expand Down Expand Up @@ -276,3 +277,9 @@ def action_toggle_button(self) -> None:
button = self._nodes[self._selected]
assert isinstance(button, RadioButton)
button.toggle()

def _scroll_to_selected(self) -> None:
"""Ensure that the selected button is in view."""
if self._selected is not None:
button = self._nodes[self._selected]
self.call_after_refresh(self.scroll_to_widget, button, animate=False)

0 comments on commit 3c7d217

Please sign in to comment.