fix(tooltip): cap the content width at the space Radix measures - #130
Merged
Conversation
TooltipContent set no max-width at all, so every consumer had to cap it themselves or let long content run the tooltip off screen. Studio was doing exactly that at eight call sites behind a token of its own. Give the component the default. The value has to live in the @theme inline block: a plain @theme declares the token on :root, where --radix-tooltip-content-available-width does not exist, so the var() collapses to its 100vw fallback before it ever reaches the tooltip. Inlined, the declaration lands on the content element -- the same element Radix sets the variable on -- and the measurement survives, collision padding included. .tooltip-content is unlayered and so beats a plain utility, which the docs now say, along with the token to retheme. Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
TooltipContentsets nomax-widthat all, so every consumer has to cap it themselves or let long content run the tooltip off screen. Guardian's studio app was doing exactly that at eight call sites behind a token of its own — this pulls the default into the design system so it doesn't have to.Found while reviewing a tooltip sweep in guardian, where the app-level version of this token was silently broken (see below).
The
@theme inlinepart mattersThe value has to live in the
@theme inlineblock. With a plain@theme, Tailwind declares the token on:rootand emitsmax-width: var(--container-tooltip). Avar()inside a custom property is substituted where that property is declared — on:root, where--radix-tooltip-content-available-widthdoesn't exist — so it collapses to the100vwfallback before it ever reaches a tooltip, and the Radix measurement is a bystander.Compiled both ways to confirm:
Inlined, the declaration lands on the content element — the same element Radix sets the variable on — and the measurement survives, collision padding included. Verified in the built
dist/tooltip.module.module.css.module.css.This is the same pattern the component already uses for
@apply origin-(--radix-tooltip-content-transform-origin).Overriding
.tooltip-contentcompiles unlayered, so it beats@layer utilitiesregardless of order — a plainmax-w-*utility won't win, and an override needsmax-w-md!. That's already the convention consumers hit with this component (guardian writestext-xs!on these very tooltips), but it wasn't written down, so the docs now cover both that and the--container-tooltiptoken for a global change.Note for consumers
This is a behavior change: any app relying on unbounded tooltip width now gets a 32rem cap. Guardian is unaffected — it already caps at exactly this value in all eight places, and those come out once this publishes.
Docs updated with a new Width section on the Tooltip page.