Skip to content

feat(widget): degrade to a compact card in a slot too small for the interface #161

Closed

Description

@Ardnived

Summary

Make the widget degrade gracefully when a host gives it a slot too small for the full interface:
render a compact card with a button that opens the whole thing in a viewport-covering
overlay
.

Two reasons this is next rather than later.

compact already exists as a documented parameter and nothing reads it. #149 added it to the
loader's config surface and docs/embedding.md describes its three values to hosts. A parameter we
document and then ignore is worse than one we never shipped — a host who sets compact=always
today gets silence.

The case is live, not hypothetical. sahajayoga.nl embeds the atlas at a hard-coded 400×600
and sahajayoga.at at 100%×600. Today the widget's only two answers are "fill your box" and "take
the whole viewport", so a 400×600 slot gets an interface that does not fit in it.

Stage E3 of the programme (.claude/reports/whitelabel-seo-program.md §7). E1/E2 — the iframe
document and its postMessage protocol — are deliberately not here
: they are the larger half, and
both their candidate clients are unverified (#152).

Proposed changes

The predicate

embedForm(metrics) beside mapSlotWarning in src/lib/embed-slot.ts, whose docblock already
argues the map-mode requirement.

⚠ They must use different thresholds, and the docblock has to say why. mapSlotWarning asks
"did somebody clearly intend a box here?" — a relative question, thresholds deliberately slack
because a false positive costs one line in a stranger's console. embedForm asks "does the
interface fit?"
— an absolute question, and a false positive now changes what renders.
Start at COMPACT_MAX_WIDTH_PX = 360 / COMPACT_MAX_HEIGHT_PX = 420, tuned in Ladle against
400×600 as the reference.

This also resolves what the slot warning was apologising for. A narrow map-mode slot currently
warns and then paints over the page anyway; it can now render compact instead. Keep the console
warning only where auto-detect was overridden off (compact=never plus a slot that does not fit) —
the host has said "don't", so a sentence is all that is left.

Who owns the decision

AppShell, and it matters that it is above MapProvider: in compact state the map must not
render at all, and mapbox-gl is the single largest second-hop cost in the app. Only AppShell sits
above it.

⚠ That saving is invisible to pnpm size by design — it budgets the eager graph and mapbox-gl
is a dynamic import. Say so in the PR rather than claiming a bundle win the gate cannot show.

DrawerStack keeps its own useIsWide(container) untouched: wide-vs-narrow and compact-vs-full are
different questions. Note src/config/responsive.test.ts's closed list of viewport callers is
unaffected, because this is a container reading — deliberate, not luck.

The overlay

Not the Modal atom. That is max-w-md with a title/description/× header; the expanded widget
wants the whole viewport with no chrome, and it contains vaul drawers, which are themselves Radix
Dialogs. A new surface on @radix-ui/react-dialog directly: fixed inset-0, no chrome, portaled to
overlayContainer() (never document.body — that is outside the style scope).

The docblock's first line should be the insight: expansion is not a new layout, it is map mode's
layout made explicit and reversible.
A fixed; inset: 0 layer is exactly what map mode already
paints, which is why vaul's window-height arithmetic becomes correct rather than broken — the
widget genuinely does span the window. Nothing new has to be taught to vaul, and "not in the box"
stops being an accident and becomes a state with an entry and an exit.

Radix supplies the focus trap, focus restore to the Open button, Esc, aria-modal, and the host
<body> scroll lock that docs/embedding.md already documents as an honest exception. It needs an
sr-only Dialog.Title and aria-describedby={undefined}, the same dance ModalContent already
does.

The seam

One hook, src/hooks/use-expansion.tsx, with providers — the same shape as MapController, which
.claude/rules/components.md already blesses, so no component branches on whether expansion is
possible:

  • LocalExpansionProvider — renders the Radix overlay in-page.
  • NoExpansionProvider — standalone; canExpand: false.

A third, framed provider lands with E1/E2. Designing for it now is what keeps that from being a
rewrite.

What the card shows

Reuse the wholesale feed — getGeojson is already fetched once and cached (WHOLESALE_GC_TIME), so
no new fetcher. Two or three rows through EventListItem, which is the repo's one React.memo
precisely because it takes what it needs as props rather than subscribing to the URL. The primary
button's label must be task-named, not product-named ("Find a class near you"), which serves the
de-branding work as well as the accessible name.

⚠ Entering compact mode logs a console warning naming the measured size and the threshold
(#149's diagnostic contract). A host who wanted the full interface needs to know they got the small
one and what to change.

⚠ AppShell is inside Suspense on clientQuery, so a 300px slot shows a full-height
LoadingFallback before the compact card. Minor, but it should be handled or noted.

Acceptance criteria

  • compact=always / never / auto all do what docs/embedding.md says, and an unrecognised value still resolves to auto.
  • A slot below the threshold renders the compact card; the map subtree does not mount and mapbox-gl is not fetched.
  • The Open button expands to a viewport-covering overlay; Esc, focus trap and focus restore all work; the host page's scroll is locked while open and restored on close.
  • vaul drawers inside the overlay compute their travel correctly — the reason the overlay is fixed; inset: 0 rather than contained.
  • compact=never in a slot that does not fit logs a console warning with the measured size and the threshold; auto entering compact logs one too.
  • The card's Open button has a task-named accessible label, and no brand string (the feat(ui): de-brand the widget and keep host CSS out of it #158 ratchet still passes).
  • Reduced motion: the expand/collapse transition is framer-motion so MotionConfig covers it — not CSS, which would need a fourth seam.
  • docs/embedding.md's sizing section documents the behaviour; CHANGELOG.md records it.
  • pnpm lint && pnpm typecheck && pnpm test:run && pnpm build && pnpm size && pnpm ladle:build pass.
  • Write an implementation report to .claude/reports/<issue-number>-<short-slug>.md.

Test strategy

Node lane: embedForm table-driven, mirroring mapSlotWarning's existing "stays quiet"
structure; the compact card's markup via renderToStaticMarkup (landmark name, button accessible
name, no brand string).

Ladle: the card at 400×600, which is the live reference case, plus the threshold boundaries.

Browser (Playwright MCP) — the two things no lane can answer, and the first is the biggest
unknown in this ticket:

  • vaul nested inside a Radix Dialog. Both are @radix-ui/react-dialog; nesting is supported in principle and the dismissible-layer and pointer-events interplay needs a real browser. ⚠ Memory records that Floating-UI popovers get pointer-locked out inside a modal vaul drawer — the same family of problem, so check the Dropdown atom inside the overlay too.
  • Expansion over an ancestor with transform / contain: layout, which defeat position: fixed (the measured table in .claude/rules/components.md).

Files affected

  • src/lib/embed-slot.ts — embedForm + its thresholds
  • src/components/organisms/CompactCard/ (new, + stories)
  • src/components/atoms/ExpandedSurface/ (new, + stories)
  • src/hooks/use-expansion.tsx (new)
  • src/App.tsx — AppShell picks the form, above MapProvider
  • src/Widget.tsx, src/main.tsx — provider wiring
  • docs/embedding.md, CHANGELOG.md

References

Activity

  1. added 15 commits that reference this issue on Aug 19, 2026
    8fc7150
    782e3c2
    7a314c2
    313b714
    5379999
    cfca7e5
    dd9243e
    9a24827
    3c57f89
    72c655b
    84a46d9
    3449beb
    38a7683
    072b604
    bd5a7ac
  2. 32 remaining items

  3. added 11 commits that reference this issue on Aug 20, 2026
    a8c71e2
    1f21d51
    db993c0
    8b55a19
    78b495c
    370aa83
    859bb41
    135c3af
    4446a92
    458d7e2
    0b5ac87
  4. added 2 commits that reference this issue on Aug 24, 2026
    7ef11b2
    a867929
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Hold Until

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions