Skip to content

fix: keep the active pill in a narrow or large-font header - #248

Merged
therealsama merged 1 commit into
mainfrom
fix/header-active-pill-narrow-fit
Sep 5, 2026
Merged

therealsama merged 1 commit into
mainfrom
fix/header-active-pill-narrow-fit

Conversation

@therealsama

@therealsama therealsama commented Sep 5, 2026 •

Copy link
Copy Markdown
Collaborator

The comments pill vanished from the header on a 320px phone, and at raised font settings the row painted over the logo instead of overflowing into the menu.

What was wrong

  • Hidden by phantom width. At 320px the nav is 200px and the trigger reserved 105px (a 21px separator slot plus an 84px labelled pill), so comments at an estimated 96px lost the row by a single pixel. The real elements need 188.2px — it fit all along, with 11.8px to spare.
  • Estimates never scaled. PILL_WIDTH_NO_ICON is px measured at a 16px root, but pills are sized in rem. At 412px and 150% the packer read the four tabs as 230px against a 232px nav, called it a fit and rendered no trigger; the truth was 310px, and justify-end spilled the excess 78px leftward across the logo. The same px-versus-rem defect feat: sharpen touch feel across the mobile swipe feed #227 fixed for --header-height.
  • Text can grow on its own. Android's text scaling, in Chrome and Firefox alike, inflates glyphs while leaving every rem length — and the root font size — where it was, so reading the root sees nothing at all. On a comment view at 320px the row escaped the nav from 1.2× on, by 27px at 1.5×, and being right-aligned the edge it clipped was the active pill.
  • Nothing clipped the nav. Below ~200px the labelled trigger — 75.7px in a 44px nav — sat 32px over the logo.

Changes

  • A phone pays for neither the separator nor the trigger's label: chevron only, with aria-label keeping the accessible name. That frees 63px — 46px of label, and 17px of separator net of the one gap the row still needs — so 320px now shows comments and best.
  • usePackedNav scales an estimate in two halves, because a reader can enlarge one without the other: boxes (padding, icons, gaps) by the root font size, glyphs by a hidden probe carrying the pills' own typography. One probe covers every mechanism — a browser font setting, an OS text size, a minimum font size, a substituted font — and reads them as they actually render: at a real 24px default it measures 102.7px where the arithmetic says 107.25, font metrics not being linear. CI is the unplanned proof — its Linux stack renders comments at 67.7px against this machine's 71.5px, so the packer there spends 5% less on every label than the table asks for, which is exactly right for a narrower font.
  • min-h-7 on the chevron trigger, which lost its line box along with its label.
  • One estimate is deliberately loose and now says so: the icon budget is spent when md: draws an icon but decided by a hook asking 767px in px where md: asks 48rem, so a reader off a 16px root gets a band where they disagree. Measured both halves — above a 16px root the icon is reserved and hidden, which only over-reserves; below, it renders unreserved, and the band's tightest row still had ~200px spare against the ~66px it wanted.
  • The nav is overflow-clip as a backstop, with a 12px clip margin so the active pill's 0 2px 8px glow survives it.
shape before after
320px, default font no pill at all comments + best + chevron
412px, 150% font 4 pills, no trigger, row 78px over the logo 1 pill + trigger, contained
164px, default font trigger 32px over the logo chevron fits the 44px nav
320px, 1.5× text scaling row 27px over, active pill clipped comments kept, 39px to spare
chevron trigger 34×22px 34×28px, level with the pills

One unrelated file

e2e/touch-feel.spec.ts gains a wait, not an assertion. The overscroll guard added with the touch work polls for a class the profile route drops as it mounts; on a loaded runner it spent that whole budget waiting for a render it could not see, and it failed an intermediate CI run here at 10.4s against 2.4s locally. It now waits for the profile's own heading before polling. Included because it fails this branch's CI, not because it belongs to this change.

Tradeoffs

  • Mobile loses the word "more" and the hairline separator. Both are chrome the chevron and the pill styling already carry.
  • The chevron-only trigger is a smaller target than the 75.7px pill it replaces, though min-h-7 keeps it above the 24×24 WCAG 2.5.8 minimum and level with its neighbours.
  • At 320px with a 150% font the pill (132.7px) and the trigger (111.2px) cannot share a 140px nav, so the trigger wins and no pill shows. Fixing that needs the contextual pill to fall back to its icon; left out deliberately.
  • The probe is a hidden element in the nav whose width is read on every re-measure. Its word lives in content, so it adds nothing to the DOM's text or the accessibility tree.

Test plan

  • usePackedNav: the same 300px row seats four tabs at a 16px root and one at 24px; a 1.3× probe drops a pill the root font alone would have kept; a probe that has not laid out leaves the root font in charge.
  • Header: mobile reserves little enough for the widest pill at 320px, spends more where there is room, renders a bare chevron with no separator beside it, and gives the probe the same typography as the pills it stands in for.
  • e2e: the comments pill is in the bar at 320px; the row stays inside the nav at 412px/150%, at 164px, and at 1.3× and 1.5× text-only scaling; the probe measures exactly the active pill's label, and its own word rather than the 44px nav around it; the trigger is as tall as the pills; and the root font size stays the reader's to set.
  • 991 unit and 788 e2e (Chromium, Firefox, Mobile Chrome, Mobile Safari) passing, plus typecheck and lint. Every new guard was mutation-tested against its own fix, which is how the 22px trigger was caught, along with two claims of mine that the code did not support and a whitespace-pre that turned out to defend nothing.

@therealsama
therealsama force-pushed the fix/header-active-pill-narrow-fit branch 7 times, most recently from abd016c to 2ae1718 Compare September 5, 2026 16:14
The nav packs pills from a table of estimated widths. Three ways that table
was wrong, each of which put the pill for the page you are on in the menu or
over the logo.

The trigger reserved 105px of a 200px nav at 320px, so `comments` at an
estimated 96px lost the row by one pixel — though the real elements needed
188.2px and had 11.8px to spare. Mobile now drops the decorative separator and
the `more` label, keeping the chevron and its accessible name, which frees
63px: enough for the widest pill and a feed tab beside it.

The estimates were read as px while the pills are sized in `rem` and their
labels in neither. A reader at 150% rendered four tabs 310px wide where the
packer read 230px against a 232px nav, so it drew no trigger at all and
`justify-end` spilled 78px of row leftward across the logo. The packer now
scales boxes by the root font size and glyphs by a hidden probe measured in
the nav — Android inflates text without moving a single `rem`, so the two are
not the same reading. A substituted font lands in that same reading: CI's
Linux stack renders the widest label 5% narrower than the table claims, and
the row is packed 5% cheaper accordingly. `overflow-clip` on the nav contains
whatever an estimate still gets wrong, with room for the active pill's glow.

The chevron-only trigger lost its line box along with its label, leaving the
14px icon to set a 22px height — under the 24px WCAG 2.5.8 asks of a target.
`min-h-7` puts it back level with the pills.

One estimate stays deliberately loose. The icon budget is spent when `md:`
draws an icon, but decided by a hook asking for 767px in px where `md:` asks
48rem, so a reader off a 16px root gets a band where the two disagree. Both
halves of it measured safe, and the constant now says so rather than leaving
the next reader to find out.

Guards: the widest pill at 320px, the row inside the nav at 412px/150% and at
164px, the active pill surviving 1.3× and 1.5× text-only scaling, the trigger
as tall as its neighbours, the probe measuring a label rather than the box
around it, and — the premise under all of it — a root font size the reader
still controls.

Adjacent, and in this branch because it fails this branch's CI: the overscroll
guard added with the touch work polls for a class the profile route drops as
it mounts, and on a loaded runner it spent that budget waiting for a render it
could not see. It now waits for the profile's own heading first.
@therealsama
therealsama merged commit 9aaac2b into main Sep 5, 2026
4 checks passed
@therealsama
therealsama deleted the fix/header-active-pill-narrow-fit branch September 5, 2026 18:35
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.

2 participants