Skip to content

Commit 0b27ffc

Browse files
committed
changelog
1 parent 3db737b commit 0b27ffc

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1212
- Fixed `TextArea` cursor display on wrapped lines https://github.com/Textualize/textual/pull/6196
1313
- Fixed `remove_children` not refreshing layout https://github.com/Textualize/textual/pull/6206
1414

15+
### Added
16+
17+
- Added `grid_size` property to `GridLayout` https://github.com/Textualize/textual/pull/6210
18+
1519
## [6.5.0] - 2025-10-31
1620

1721
### Added

src/textual/layouts/grid.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ def arrange(
7272

7373
table_size_rows = styles.grid_size_rows
7474

75-
self._grid_size = (table_size_columns, table_size_rows)
76-
7775
viewport = parent.app.viewport_size
7876
keyline_style, _keyline_color = styles.keyline
7977
offset = (0, 0)
@@ -171,9 +169,9 @@ def repeat_scalars(scalars: Iterable[Scalar], count: int) -> list[Scalar]:
171169
cell_coord = next_coord()
172170

173171
column_scalars = repeat_scalars(column_scalars, table_size_columns)
174-
row_scalars = repeat_scalars(
175-
row_scalars, table_size_rows if table_size_rows else row + 1
176-
)
172+
table_size_rows = table_size_rows if table_size_rows else row + 1
173+
row_scalars = repeat_scalars(row_scalars, table_size_rows)
174+
self._grid_size = (table_size_columns, table_size_rows)
177175

178176
def apply_width_limits(widget: Widget, width: int) -> int:
179177
"""Apply min and max widths to dimension.

tests/layouts/test_grid.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from textual import containers, widgets
2+
from textual.app import App, ComposeResult
3+
from textual.layouts.grid import GridLayout
4+
5+
6+
async def test_grid_size():
7+
"""Test the `grid_size` property on GridLayout."""
8+
9+
class GridApp(App):
10+
CSS = """
11+
Grid {
12+
grid-size: 3;
13+
grid-columns: auto;
14+
height: auto;
15+
Label {
16+
padding: 2 4;
17+
border: blue;
18+
}
19+
}
20+
"""
21+
22+
def compose(self) -> ComposeResult:
23+
with containers.VerticalScroll():
24+
with containers.Grid():
25+
for _ in range(7):
26+
yield widgets.Label("Hello, World!")
27+
28+
app = GridApp()
29+
async with app.run_test() as pilot:
30+
await pilot.pause()
31+
await app.wait_for_refresh()
32+
grid_layout = app.query_one(containers.Grid).layout
33+
assert isinstance(grid_layout, GridLayout)
34+
assert grid_layout.grid_size == (3, 3)

0 commit comments

Comments
 (0)