From 8a07a83def7f6d1d5c5621a74b4b2393ca912d8d Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Mon, 15 Jul 2024 15:40:38 +0100 Subject: [PATCH 1/2] toggle style order --- src/textual/widgets/_toggle_button.py | 5 ++++- .../snapshot_apps/toggle_style_order.py | 19 +++++++++++++++++++ tests/snapshot_tests/test_snapshots.py | 5 +++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 tests/snapshot_tests/snapshot_apps/toggle_style_order.py diff --git a/src/textual/widgets/_toggle_button.py b/src/textual/widgets/_toggle_button.py index b649081fd7..dca89cdbd0 100644 --- a/src/textual/widgets/_toggle_button.py +++ b/src/textual/widgets/_toggle_button.py @@ -169,6 +169,7 @@ def _make_label(self, label: TextType) -> Text: label = label.split()[0] except IndexError: pass + return label @property @@ -216,7 +217,9 @@ def render(self) -> RenderResult: """ button = self._button label = self._label.copy() - label.stylize(self.get_component_rich_style("toggle--label", partial=True)) + label.stylize_before( + self.get_component_rich_style("toggle--label", partial=True) + ) spacer = " " if label else "" return Text.assemble( *( diff --git a/tests/snapshot_tests/snapshot_apps/toggle_style_order.py b/tests/snapshot_tests/snapshot_apps/toggle_style_order.py new file mode 100644 index 0000000000..a92e41a421 --- /dev/null +++ b/tests/snapshot_tests/snapshot_apps/toggle_style_order.py @@ -0,0 +1,19 @@ +from textual.app import App +from textual.widgets import Checkbox, Label + + +class CheckboxApp(App): + CSS = """ + Checkbox > .toggle--label, Label { + color: white; + text-opacity: 50%; + } + """ + + def compose(self): + yield Checkbox("[red bold]This is just[/] some text.") + yield Label("[red bold]This is just[/] some text.") + + +if __name__ == "__main__": + CheckboxApp().run() diff --git a/tests/snapshot_tests/test_snapshots.py b/tests/snapshot_tests/test_snapshots.py index 5cc5bf4d5a..f158e7d9bd 100644 --- a/tests/snapshot_tests/test_snapshots.py +++ b/tests/snapshot_tests/test_snapshots.py @@ -1328,3 +1328,8 @@ async def run_before(pilot: Pilot) -> None: assert snap_compare( SNAPSHOT_APPS_DIR / "programmatic_disable_button.py", run_before=run_before ) + + +def test_toggle_style_order(snap_compare): + """Regression test for https://github.com/Textualize/textual/issues/3421""" + assert snap_compare(SNAPSHOT_APPS_DIR / "toggle_style_order.py") From 54a023cc0f506aa29be1a7c8db7566ae504d0e00 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Mon, 15 Jul 2024 15:57:28 +0100 Subject: [PATCH 2/2] snapshot --- .../__snapshots__/test_snapshots.ambr | 164 ++++++++++++++++++ 1 file changed, 164 insertions(+) diff --git a/tests/snapshot_tests/__snapshots__/test_snapshots.ambr b/tests/snapshot_tests/__snapshots__/test_snapshots.ambr index dba02e40e7..9737670c56 100644 --- a/tests/snapshot_tests/__snapshots__/test_snapshots.ambr +++ b/tests/snapshot_tests/__snapshots__/test_snapshots.ambr @@ -47899,6 +47899,170 @@ ''' # --- +# name: test_toggle_style_order + ''' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + CheckboxApp + + + + + + + + + + ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ + XThis is just some text. + ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ + This is just some text. + + + + + + + + + + + + + + + + + + + + + + + + + ''' +# --- # name: test_tooltips_in_compound_widgets '''