diff --git a/CHANGELOG.md b/CHANGELOG.md index 44d72a52b..fb0a39404 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Fixed visual glitches and crash when changing `DataTable.header_height` https://github.com/Textualize/textual/pull/6128 - Fixed TextArea.placeholder not handling multi-lines https://github.com/Textualize/textual/pull/6138 - Fixed issue with RichLog when App.theme is set early https://github.com/Textualize/textual/pull/6141 +- Fixed children of collapsible not being focusable after collapsible is expanded https://github.com/Textualize/textual/pull/6143 ## [6.1.0] - 2025-08-01 diff --git a/src/textual/css/_style_properties.py b/src/textual/css/_style_properties.py index edc591966..2b3ebfe77 100644 --- a/src/textual/css/_style_properties.py +++ b/src/textual/css/_style_properties.py @@ -841,6 +841,12 @@ class StringEnumProperty(Generic[EnumType]): children=self._refresh_children, parent=self._refresh_parent, ) + + if self._display: + node = obj.node + if node is not None and node.parent: + node._nodes.updated() + else: if value not in self._valid_values: raise StyleValueError( diff --git a/tests/snapshot_tests/__snapshots__/test_snapshots/test_collapsible_focus_children.svg b/tests/snapshot_tests/__snapshots__/test_snapshots/test_collapsible_focus_children.svg new file mode 100644 index 000000000..dc36c01d2 --- /dev/null +++ b/tests/snapshot_tests/__snapshots__/test_snapshots/test_collapsible_focus_children.svg @@ -0,0 +1,154 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + CollapseApp + + + + + + + + + + ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ +▼ Collapsible + +▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ + Hello  +▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/snapshot_tests/test_snapshots.py b/tests/snapshot_tests/test_snapshots.py index 034dfd799..ea8a7434f 100644 --- a/tests/snapshot_tests/test_snapshots.py +++ b/tests/snapshot_tests/test_snapshots.py @@ -4675,3 +4675,18 @@ def test_rich_log_early_write(snap_compare) -> None: log_widget.write("Hello, World!") assert snap_compare(TestApp()) + + +def test_collapsible_focus_children(snap_compare) -> None: + """Regression test for https://github.com/Textualize/textual/issues/6140 + + You should see an expanded collapsible containing a button. The button should be focused. + + """ + + class CollapseApp(App): + def compose(self) -> ComposeResult: + with Collapsible(title="Collapsible", collapsed=False): + yield Button("Hello") + + assert snap_compare(CollapseApp(), press=["enter", "enter", "tab"])