Scroll the mobile bottom bar when its entries overflow

JA
4h ago
+175-31

Part of #6022

Fork pre-flight: jaysbeekay/sure#1046 (same branch, same commit)

Problem

On a phone, and in the installed PWA, the bottom bar is the only navigation. It is a fixed flex justify-around row, so every entry is squeezed into the screen width. To make room, Portfolio was marked desktop_only and left off the bar, so a preview user on a phone has no way to open /portfolio. Entries that do fit are narrow: at 390 px, Home, Bills and Plan are 32 px wide.

Behaviour

  • Each bottom-bar entry keeps a minimum width of min-w-18 (4.5rem) and does not shrink.
  • The entries sit in an inner row, flex justify-around min-w-full w-max. When they fit, the row is the bar's width and spreads them out as before.
  • When they don't fit, the row grows to their width and the bar scrolls sideways (overflow-x-auto). The row is never narrower than its entries, so justify-around never meets negative free space. Some engines center that case, which would push Home off the left edge where scrolling can't reach it.
  • With the new layout, the first entry starts at the left edge, the last is reachable by scrolling, and the entry cut off at the right edge shows there is more.
  • Portfolio is in the bottom bar for preview users. desktop_only comes off portfolio_nav_item. No entry used the flag after that, so the flag, its layout filter and the _nav_item partial's desktop_only local are removed.
  • The desktop sidebar renders the same _nav_item partial, so the new item classes use the max-lg: prefix. At 1440 px every sidebar entry has the same position and size as before (84x57).
  • Tailwind utilities only. No CSS added to sure-design-system.css or application.css.

Not in this PR: the edge fade from the issue. A static mask-r-* would also fade the last entry when everything fits, and the first entry once the bar is scrolled to the end. Showing it only while there is more to scroll needs scroll-state queries or JavaScript. Letting users choose the bar's entries is PR 2, stacked on this one.

Validation

  • test/system/mobile_bottom_nav_scroll_test.rb (new, 390x844):
    • Seven entries (preview, assistant on): scrollWidth > clientWidth, every entry is at least 72 px wide, the first entry is not off-screen, the row is at least as wide as its entries, the last is fully visible after scrollIntoView, and the order is Home through Assistant. Before the change it failed on the bar does not overflow ... Expected 390 to be > 390.
    • Four entries (no preview, assistant off): no overflow, and the space before the first entry matches the space after the last (still justify-around). It passes before and after the change.
  • test/controllers/portfolios_controller_test.rb: the two tests that asserted Portfolio was absent from nav[data-viewport-target=bottomNav] now assert it is present for a preview user. It is still absent without preview. Before the change: Expected exactly 1 element matching "nav[data-viewport-target=bottomNav] a[href=\"/portfolio\"]", found 0.
  • Mutations, each run on a copy and each turning a test red:
    • Upstream's old bar markup: "the entries overflow their row".
    • Inner row without w-max, and a scrolling justify-around nav with no inner row: "the entries overflow their row". Chrome start-aligns this case, so the row-width check, not the Home position, is what catches it.
    • Item min width dropped: "the bar does not overflow".
  • Full bin/rails test: 19547 runs, 0 failures. The 8 errors are ReleaseNotesWorkflowTest, from the local test environment, and are unrelated to this change.
  • System tests: mobile_bottom_nav_scroll, mobile_bottom_nav_clearance, sidebar_narrow, sidebar_widths, sidebar_animation_rows, portfolios, bills_mobile, release_highlights. 55 runs, 0 failures.
  • rubocop, erb_lint and Brakeman are clean. No JS changed.

Screenshots

Preview user with the assistant enabled, on the dashboard.

BeforeAfter
390 px, startbefore 390 startafter 390 start
390 px, scrolled to the endbefore 390 end (no scrolling)after 390 end
375 pxbefore 375after 375
390 px, first entry keyboard-focusedbefore 390 focus (ring clipped at the top and left)after 390 focus
Desktop 1440 pxbefore 1440after 1440

Summary by cubic

Fixes the mobile bottom bar squeezing every navigation entry into the screen width, which kept Portfolio off the bar entirely. Each entry now keeps a 4.5rem minimum tap width, and the bar scrolls sideways when the entries overflow; with few entries it still spreads them across the width as before.

  • Portfolio now shows in the bottom bar for preview users, so /portfolio is reachable on a phone; the now-unused desktop_only flag is removed.
  • The entries row has 2px of padding on every side, so a focused entry's focus ring stays inside the bar's scroll clip.
  • The desktop sidebar renders the same partial and its layout is unchanged.
  • Part of #6022.

Summary by CodeRabbit

  • New Features

    • The mobile navigation now includes Portfolio when preview access is enabled and displays all desktop navigation links, except Assistant.
    • When navigation entries exceed the available width, the bottom bar scrolls horizontally so every entry remains reachable.
  • Bug Fixes

    • Navigation entries retain a usable minimum width, with adequate spacing for focus indicators. When all entries fit, they remain evenly spaced in the bar.