Repository navigation
fix(layout): honor align-items for bare text mixed with img in flex - #456
Open
tannevaled wants to merge 1 commit into
Open
tannevaled wants to merge 1 commit into
tannevaled wants to merge 1 commit into
Conversation
A display:flex row holding an <img> followed by literal bare text (no wrapping element) ignored align-items entirely: the text always sat flush with the image's synthesized baseline (its own bottom edge), regardless of flex-start/center/flex-end/stretch. flex()'s hasDirectText fallback (triggered whenever a flex container has any direct text-node child, e.g. "<img>some text") bypasses flexRow's cross-axis handling completely and lays the content out as plain CSS 2.1 inline content, which never reads align-items. The element-only case (text wrapped in e.g. <strong>) was already correct, since flexItems only collects element children. Add alignInlineFlexItems to reposition each inline item within its line per align-items after the inline fallback runs, keeping InlineItem.NestedBox in sync via the existing translateBox helper. As a side effect this also removes a phantom gap: the line height used to include baseline descent room no item occupied. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.
Summary
Fixes a confirmed HEAD defect (pinned at v0.17.0, reported by a go-slides
session): a
display:flexrow container holding an<img>followed byliteral bare text (no wrapping element) ignored
align-itemsentirely. Thetext was always positioned per default CSS 2.1 inline baseline alignment — an
image's synthesized baseline is its own bottom edge — regardless of the
declared
align-itemsvalue (flex-start/center/flex-end/stretch).The adjacent, textually similar shape where the text is wrapped in an element
(e.g.
<strong>text</strong>next to the<img>) was already correct atHEAD:
flexItemsonly ever collects element children, so that case reachesflexRow's own cross-axis handling (crossOffset), which already honorsalign-itemscorrectly.Root cause
flex()'s fallback branch inlayout/flex.gotriggers onhasDirectText,true whenever the flex container has any direct text-node child. That
branch bypasses
flexRow/flexColumncompletely and lays the container outas a plain CSS 2.1 inline formatting context via
layoutInline, which neverreads
align-items.Fix
Added
alignInlineFlexItemsinlayout/flex.go, called right after theinline-fallback layout runs, to reposition each inline item within its line
according to
align-items(flex-start/stretch→ cross-start flush,center→ centered,flex-end→ cross-end flush), keepingInlineItem.NestedBoxin sync via the existingtranslateBoxhelper. Thisalso removes a phantom gap in the single-line case: the line height used to
include baseline-descent room that no item actually occupied.
Scope: only the single-line case gets the line-height correction, to avoid
risking new gaps in the already-approximate multi-line mixed-fallback path.
The separate
hasBlockBreak/placeInlineSegmentspath (a promotedblock-level child mixed with bare text) is untouched — out of scope for this
fix.
Testing
Added
layout/flex_mixedtext_align_test.go:TestFlexMixedTextAndImageHonorsAlignItems: matrix overflex-start/center/flex-end/stretch for the bare-text+img shape.
TestFlexMixedTextAndImageDefaultAlignItems: noalign-itemsdeclared(the real-world theme rule), confirming the initial
stretchvalue nolonger glues text to the image's bottom edge.
TestFlexElementWrappedTextAndImageAlignItems: regression guard for thealready-correct element-wrapped-text shape, unaffected by this change.
Full gate green:
gotest ./...,gotest ./layout/... -race,gofmt -l .(clean for the touched files),
go vet ./...,govulncheck ./....🤖 Generated with Claude Code