Skip to content

fix: keep wrapping item labels in line with their fields (#2048) - #2072

Open
clinnygee wants to merge 1 commit into
mainfrom
issue/2048
Open

fix: keep wrapping item labels in line with their fields (#2048)#2072
clinnygee wants to merge 1 commit into
mainfrom
issue/2048

Conversation

@clinnygee

Copy link
Copy Markdown
Collaborator

Fixes #2048.

Problem

In the "Absolute cardiovascular disease risk calculation" section of the Aboriginal and Torres Strait Islander Health Check, the question "Do you have access to the Aus CVD Risk-i application from your clinical system?" rendered well below its Yes/No radios rather than beside them.

This was not specific to that question — any item label long enough to wrap onto a second line was affected, for plain text, rendering-xhtml and rendering-markdown alike.

Causes

Two independent issues, both in ItemLabel:

  1. Inline-flex baseline. The label text sits in a display: inline-flex box. An inline-flex box takes its baseline from its first flex item — here the usually-empty prefix span. Once the text wrapped, that baseline sat ~15px below the surrounding line box's baseline, pushing the whole label down. The box now aligns to the top of its line box.

  2. XHTML paragraph margins. Labels supplied as rendering-xhtml are wrapped in a <p>, whose margin-block-start added a further 14px. Question labels now trim their outer paragraph margins. Display items keep theirs, since they are standalone blocks of prose rather than a single run of label text.

Group headings were never affected — their Typography is already a flex container, which blockifies the inner box and removes it from the line box entirely. Grid groups are also unaffected, since their table cells centre vertically; GridRow/GridTable are left alone.

Result

Measured from the top of the row to the first line of label text:

Label Before After
Plain text 25px 10px
rendering-xhtml 25px 10px
String item 25px 10px

10px is the offset a single-line label already had (ItemLabel's 4px nudge plus the line's half-leading), so wrapping labels now sit exactly where non-wrapping ones do.

Verified by rendering the real assembled 715 questionnaire's CVD section: the question now lines up with its radios, matching the plain-text question directly above it.

Testing

  • New WrappingItemLabels story under SDC/9.1.1 Rendering > Text Appearance, covering plain, xhtml and string wrapping labels. Its play function asserts the first line of label text starts at the top of its row; it passes with the fix and fails (25px > 12px threshold) without it.
  • Renderer build (tsc) and root npm run lint pass with no errors.
  • Renderer Jest suite: 92/92 suites, 2190 tests pass.
  • Storybook test-runner passes for the affected suite.

🤖 Generated with Claude Code

A question label that wrapped onto multiple lines was rendered below its
field instead of beside it. Two separate causes:

1. The label text sits in a `display: inline-flex` box, which takes its
   baseline from its first flex item - usually the empty prefix span.
   Once the text wrapped, that baseline sat ~15px below the surrounding
   line box's baseline, pushing the whole label down. The box now aligns
   to the top of its line box instead.

2. Labels supplied as rendering-xhtml are wrapped in a `<p>`, whose
   block margins added a further offset. Question labels now trim the
   outer paragraph margins; display items keep theirs, since they are
   standalone blocks of prose rather than a single run of text.

Measured from the top of the row, plain, xhtml and string labels all go
from 25px to 10px - the same offset a single-line label already had.

Adds a WrappingItemLabels story whose play function asserts the first
line of label text starts at the top of its row.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Question answer alignment issue

1 participant