Skip to content

Commit f7626e1

Browse files
authored
fix(radioset): make radio set scrollable (#5109)
* fix(radioset): make radio set scrollable * add snapshot test * update changelog
1 parent afc310a commit f7626e1

File tree

4 files changed

+203
-13
lines changed

4 files changed

+203
-13
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
## Unreleased
9+
10+
### Fixed
11+
12+
- Fixed `RadioSet` not being scrollable https://github.com/Textualize/textual/issues/5100
13+
814
## [0.83.0] - 2024-10-10
915

1016
### Added

src/textual/widgets/_radio_set.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99

1010
from textual import _widget_navigation
1111
from textual.binding import Binding, BindingType
12-
from textual.containers import Container
12+
from textual.containers import VerticalScroll
1313
from textual.events import Click, Mount
1414
from textual.message import Message
1515
from textual.reactive import var
1616
from textual.widgets._radio_button import RadioButton
1717

1818

19-
class RadioSet(Container, can_focus=True, can_focus_children=False):
19+
class RadioSet(VerticalScroll, can_focus=True, can_focus_children=False):
2020
"""Widget for grouping a collection of radio buttons into a set.
2121
2222
When a collection of [`RadioButton`][textual.widgets.RadioButton]s are
@@ -42,7 +42,7 @@ class RadioSet(Container, can_focus=True, can_focus_children=False):
4242
* ToggleButton. If those styles ever get updated, these should be too.
4343
*/
4444
45-
RadioSet > * {
45+
RadioSet > RadioButton {
4646
background: transparent;
4747
border: none;
4848
padding: 0 1;
@@ -188,6 +188,7 @@ def watch__selected(self) -> None:
188188
self.query(RadioButton).remove_class("-selected")
189189
if self._selected is not None:
190190
self._nodes[self._selected].add_class("-selected")
191+
self._scroll_to_selected()
191192

192193
def _on_radio_button_changed(self, event: RadioButton.Changed) -> None:
193194
"""Respond to the value of a button in the set being changed.
@@ -276,3 +277,9 @@ def action_toggle_button(self) -> None:
276277
button = self._nodes[self._selected]
277278
assert isinstance(button, RadioButton)
278279
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)
Loading

0 commit comments

Comments
 (0)