Grid: exclude items with auto block-axis margins from baseline alignment - #1125
Merged
Conversation
Per css-align-3 §9.5, a box with an auto margin in the relevant axis does not participate in baseline alignment. Matches the flexbox implementation's participates_in_baseline_alignment check.
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Objective
Per css-align-3 §9.5, a box with an
automargin in the relevant axis does not participate in baseline alignment. The grid algorithm didn't check for this: the container's first-baseline selection preferred any first-row item withalign-self: baseline(even with an auto block-axis margin), and such items were also baseline-shimmed during track sizing.This is observable in WPT css/css-grid/alignment/grid-baseline-001.html sub-case "We don't participate in baseline alignment if there's an auto margin": an inline-grid with children
<div>baseline</div>and<div style="align-self: baseline; margin-top: auto">below</div>should generate its baseline from the first item, but taffy picked the auto-margin item.Context
The fix mirrors the existing flexbox implementation (
FlexItem::participates_in_baseline_alignment, which checks that neither cross-axis margin is auto):GridItem::participates_in_baseline_alignment():compute/grid/mod.rs) now picks the first first-row item that participates in baseline alignment, falling back to the row's first item in grid orderhas_baseline_aligned_itemandresolve_item_baselines(track_sizing.rs) use the same predicate: only participating items are counted, have their baselines resolved, and receive abaseline_shim. Non-participating items (including auto-margin items) are no longer shimmed, so an auto-margin item is bottom-aligned by its auto margin insteadTests: two new generated-test fixtures mirroring the WPT sub-case (
grid_baseline_child_auto_margin_container_baseline,grid_align_items_baseline_child_auto_margin); all 8 generated permutations fail onmainand pass with this fix. Full test suite regenerated withjust gentest;cargo test --workspace,cargo fmtandcargo clippyare clean.Link to Devin session: https://dioxus.staging.devinenterprise.com/sessions/9ea93cbb618a491a9f4240b8a4780893
Requested by: @nicoburns