Skip to content

fix(SearchBox): keep icon and input on one row at ≤480px#34

Open
JSv4 wants to merge 1 commit into
mainfrom
claude/issue-33-YVFg1
Open

fix(SearchBox): keep icon and input on one row at ≤480px#34
JSv4 wants to merge 1 commit into
mainfrom
claude/issue-33-YVFg1

Conversation

@JSv4

@JSv4 JSv4 commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #33 — on screens ≤ 480px the leading search icon was stranded on its own line above the input (icon / input / button rendering as three stacked rows).

Root cause

The @media (max-width: 480px) rule gave .oc-search-box__input a non-zero flex-basis. With flex-wrap: wrap, an item's hypothetical (flex-basis) size — not its shrunk size — is what the line-collection algorithm uses to decide wrapping. A non-zero basis lets the input's hypothetical size exceed the remaining space next to the icon, so the input wraps onto its own flex line and leaves the flex-shrink: 0 icon alone on the row above.

Note: the specific value reported in #33 (flex: 1 1 100%) was already changed to flex: 1 1 auto in 0.1.20 (the #27 fix, which the reporter hadn't tested — they were on 0.1.19). But auto is still not bulletproof: it relies on the input's intrinsic width fitting beside the icon, so on a sufficiently narrow viewport the icon can still be stranded. That's why this bug has now been filed twice.

Fix

Set the input to flex: 1 1 0 in the ≤480px media query — a zero flex-basis, matching the desktop base rule (flex: 1). The input's hypothetical size is then 0, so it always shares the first row with the icon and grows to fill the remaining space; only the full-width button wraps to a second row. This holds regardless of the input's intrinsic width or the viewport width.

Regression coverage

  • SearchBox.test.tsx (new) — asserts DOM order (icon → input → button) and pins the mobile flex rule: input must be flex: 1 1 0 with min-width: 0 (and explicitly not 100%/auto), button full-width, icon ordered before input. jsdom can't perform flex layout, so the guard is on the CSS-in-JS rule that governs the wrap.
  • MobileLayout story at 320px with a long placeholder — visual regression coverage for the reported scenario.

Verification

  • npm run test — 156 passed (5 new)
  • npm run lint — clean
  • npm run build — success

https://claude.ai/code/session_01VMc2dtCs97wcswd8uwMddo


Generated by Claude Code

The mobile media query gave the input a non-zero flex-basis, letting its
hypothetical size push it onto its own flex line and stranding the leading
search icon on the row above (icon / input / button as three stacked rows).

Use flex: 1 1 0 on the input in the <=480px media query, matching the desktop
base rule, so the input always shares the first row with the icon and grows to
fill the remaining space; only the full-width button wraps to a second row.
This is robust regardless of the input's intrinsic width, unlike the prior
flex: 1 1 auto which could still wrap on sufficiently narrow viewports.

Adds a SearchBox test asserting DOM order and the mobile flex rule, plus a
MobileLayout story at 320px for visual regression coverage.

Fixes #33

const ruleFor = (selector: string) => {
const re = new RegExp(
`${selector.replace(/[.]/g, '\\.')}\\s*\\{([^}]*)\\}`
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.

SearchBox: mobile layout strands the search icon on its own line above the input

3 participants