diff --git a/src/textual/widgets/_data_table.py b/src/textual/widgets/_data_table.py index 32fab94cef..c6c31be50d 100644 --- a/src/textual/widgets/_data_table.py +++ b/src/textual/widgets/_data_table.py @@ -330,6 +330,9 @@ class DataTable(ScrollView, Generic[CellType], can_focus=True): ) """The coordinate of the `DataTable` that is being hovered.""" + def watch_cell_padding(self) -> None: + self._clear_caches() + class CellHighlighted(Message): """Posted when the cursor moves to highlight a new cell. @@ -1052,6 +1055,9 @@ def watch_fixed_columns(self) -> None: def watch_zebra_stripes(self) -> None: self._clear_caches() + def watch_cell_padding(self) -> None: + self._clear_caches() + def watch_hover_coordinate(self, old: Coordinate, value: Coordinate) -> None: self.refresh_coordinate(old) self.refresh_coordinate(value) diff --git a/tests/snapshot_tests/__snapshots__/test_snapshots.ambr b/tests/snapshot_tests/__snapshots__/test_snapshots.ambr index ac7d6c80d6..496d5a5319 100644 --- a/tests/snapshot_tests/__snapshots__/test_snapshots.ambr +++ b/tests/snapshot_tests/__snapshots__/test_snapshots.ambr @@ -14159,6 +14159,164 @@ ''' # --- +# name: test_datatable_change_cell_padding + ''' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + TableApp + + + + + + + + + + + one  two  three + valuevalueval   + +  one    two    three  +  value  value  val    + +   one      two      three   +   value    value    val     + +    one        two        three    +    value      value      val      + +           one                      two                      three           +           value                    value                    val             + + + + + + + + + + + + + + ''' +# --- # name: test_datatable_column_cursor_render ''' diff --git a/tests/snapshot_tests/snapshot_apps/data_table_cell_padding.py b/tests/snapshot_tests/snapshot_apps/data_table_cell_padding.py index ec1d8a6991..df7283abb3 100644 --- a/tests/snapshot_tests/snapshot_apps/data_table_cell_padding.py +++ b/tests/snapshot_tests/snapshot_apps/data_table_cell_padding.py @@ -16,6 +16,12 @@ def compose(self) -> ComposeResult: dt.add_row("value", "value", "val") yield dt + def key_a(self): + self.query(DataTable).last().cell_padding = 20 + + def key_b(self): + self.query(DataTable).last().cell_padding = 10 + app = TableApp() if __name__ == "__main__": diff --git a/tests/snapshot_tests/test_snapshots.py b/tests/snapshot_tests/test_snapshots.py index 4e5f8d53df..7797a8c2bd 100644 --- a/tests/snapshot_tests/test_snapshots.py +++ b/tests/snapshot_tests/test_snapshots.py @@ -172,6 +172,13 @@ def test_datatable_cell_padding(snap_compare): assert snap_compare(SNAPSHOT_APPS_DIR / "data_table_cell_padding.py") +def test_datatable_change_cell_padding(snap_compare): + # Check that horizontal cell padding is respected. + assert snap_compare( + SNAPSHOT_APPS_DIR / "data_table_cell_padding.py", press=["a", "b"] + ) + + def test_footer_render(snap_compare): assert snap_compare(WIDGET_EXAMPLES_DIR / "footer.py")