Skip to content

Commit

Permalink
Respect min/max height for flex column containers
Browse files Browse the repository at this point in the history
Fix #2374.
  • Loading branch information
liZe committed Feb 8, 2025
1 parent 965b3b4 commit 98add20
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
64 changes: 64 additions & 0 deletions tests/layout/test_flex.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,32 @@ def test_flex_direction_row():
assert div_1.position_x < div_2.position_x < div_3.position_x


@assert_no_logs
def test_flex_direction_row_max_width():
page, = render_pages('''
<article style="display: flex; max-width: 100px">
<div></div>
</article>
''')
html, = page.children
body, = html.children
article, = body.children
assert article.width == 100


@assert_no_logs
def test_flex_direction_row_min_height():
page, = render_pages('''
<article style="display: flex; min-height: 100px">
<div></div>
</article>
''')
html, = page.children
body, = html.children
article, = body.children
assert article.height == 100


@assert_no_logs
def test_flex_direction_row_rtl():
page, = render_pages('''
Expand Down Expand Up @@ -135,6 +161,44 @@ def test_flex_direction_column():
assert div_1.position_y < div_2.position_y < div_3.position_y


@assert_no_logs
def test_flex_direction_column_min_width():
page, = render_pages('''
<article style="display: flex; flex-direction: column; min-height: 100px">
<div></div>
</article>
''')
html, = page.children
body, = html.children
article, = body.children
assert article.height == 100


@assert_no_logs
def test_flex_direction_column_max_height():
page, = render_pages('''
<article style="display: flex; flex-flow: column wrap; max-height: 100px">
<div style="height: 40px">A</div>
<div style="height: 40px">B</div>
<div style="height: 40px">C</div>
</article>
''')
html, = page.children
body, = html.children
article, = body.children
assert article.height == 100
div1, div2, div3 = article.children
assert div1.height == 40
assert div1.position_x == 0
assert div1.position_y == 0
assert div2.height == 40
assert div2.position_x == 0
assert div2.position_y == 40
assert div3.height == 40
assert div3.position_x == div1.width
assert div3.position_y == 0


@assert_no_logs
def test_flex_direction_column_rtl():
page, = render_pages('''
Expand Down
3 changes: 2 additions & 1 deletion weasyprint/layout/flex.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from ..formatting_structure import boxes
from . import percent
from .absolute import AbsolutePlaceholder, absolute_layout
from .preferred import max_content_width, min_content_width
from .preferred import max_content_width, min_content_width, min_max
from .table import find_in_flow_baseline


Expand Down Expand Up @@ -311,6 +311,7 @@ def flex_layout(context, box, bottom_space, skip_stack, containing_block,
children = children[:index + 1]
break
box.height += child_height
box.height = max(box.min_height, min(box.height, box.max_height))

# 9.3.5 If the flex container is single-line, collect all the flex items
# into a single flex line.
Expand Down

0 comments on commit 98add20

Please sign in to comment.