Skip to content

[preview card] Integrate inline positioning - #2074

Merged
atomiks merged 9 commits into
mui:masterfrom
atomiks:feat/preview-card-tooltip-inline
May 7, 2026
Merged

atomiks merged 9 commits into
mui:masterfrom
atomiks:feat/preview-card-tooltip-inline

Conversation

@atomiks

@atomiks atomiks commented Jun 6, 2025 •

Copy link
Copy Markdown
Contributor

Closes #2064

Previously it would choose the whole bounding client rect rather than choosing an individual client rect. align="start" sort of alleviates this problem but you can't use center positioning or other sides.

https://deploy-preview-2074--base-ui.netlify.app/experiments/inline-positioning

Screen.Recording.2025-06-06.at.4.21.44.pm.mov

@atomiks atomiks added type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature. component: preview card Changes related to the preview card component. labels Jun 6, 2025
@pkg-pr-new

pkg-pr-new Bot commented Jun 6, 2025 •

Copy link
Copy Markdown
  • base-ui-tanstack-start

  • vite-css-base-ui-example

    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/react@2074
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@2074
    

commit: 7882002

@mui-bot

This comment was marked as outdated.

@atomiks
atomiks force-pushed the feat/preview-card-tooltip-inline branch from f6338d2 to 1158c4c Compare June 6, 2025 06:31
@netlify

This comment was marked as outdated.

@atomiks
atomiks force-pushed the feat/preview-card-tooltip-inline branch 2 times, most recently from 1f4d6cc to cde5577 Compare June 6, 2025 06:37
@mui mui deleted a comment from netlify Bot Jun 6, 2025
@mui mui deleted a comment from netlify Bot Jun 6, 2025
@atomiks
atomiks force-pushed the feat/preview-card-tooltip-inline branch from cde5577 to 04fe93c Compare June 6, 2025 06:41
@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Sep 3, 2025
@oleksandr-danylchenko

oleksandr-danylchenko commented Dec 16, 2025 •

Copy link
Copy Markdown

Hello 👋🏻
Do I understand correctly that the Popover and the Tooltip components will need to go through a similar treatment for positioning with inline FloatingUI middleware?

Currently, we are experiencing a similar issue with the Popover over multiline text:
a popover is rendered in the middle above multi-line textual content

@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Dec 22, 2025
@mui-bot

mui-bot commented Dec 22, 2025 •

Copy link
Copy Markdown

Bundle size report

Bundle Parsed size Gzip size
@base-ui/react 🔺+2.33KB(+0.50%) 🔺+863B(+0.57%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

@netlify

netlify Bot commented Dec 22, 2025 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 7882002
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/69fc6d933c720e0008bb5d24
😎 Deploy Preview https://deploy-preview-2074--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@atomiks
atomiks force-pushed the feat/preview-card-tooltip-inline branch from f159eea to 5c35ad5 Compare December 22, 2025 03:37

@oleksandr-danylchenko oleksandr-danylchenko left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! The extracted getInlineRectHoverCoords and createInlineMiddleware look pretty good! I like how nicely they fit into an existing infrastructure. I believe that the next step will be adding the inline condition prop for the *Positioner components. Ideally, the consumers may be able to control which clientRect will be picked. Either only the first one, or the hovered one.

@atomiks

atomiks commented Dec 31, 2025

Copy link
Copy Markdown
Contributor Author

@oleksandr-danylchenko what's a reason to not choose the hovered one?

@atomiks
atomiks marked this pull request as ready for review December 31, 2025 05:47
@atomiks atomiks changed the title [preview card] Integrate inline positioning [preview card][tooltip][popover] Integrate inline positioning Dec 31, 2025
@atomiks atomiks added component: tooltip Changes related to the tooltip component. component: popover Changes related to the popover component. labels Dec 31, 2025
@oleksandr-danylchenko

Copy link
Copy Markdown

@oleksandr-danylchenko what's a reason to not choose the hovered one?

I'd say "design preference". Consumers might wanna show the popover in a "static" place, over the 1st client rectangle. That would correspond to the inline middleware behavior in Floating UI. It might make the migration from Floating easier for the existing components.

@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jan 9, 2026
@michaldudak
michaldudak requested a review from Copilot January 22, 2026 14:20
@atomiks atomiks removed the component: popover Changes related to the popover component. label Mar 11, 2026
@atomiks
atomiks force-pushed the feat/preview-card-tooltip-inline branch from 8ea5633 to 9fb87ea Compare March 11, 2026 07:29
@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Apr 1, 2026
@atomiks atomiks changed the title [preview card][tooltip] Integrate inline positioning [preview card] Integrate inline positioning Apr 9, 2026
@atomiks
atomiks force-pushed the feat/preview-card-tooltip-inline branch from 20b00d4 to 3c317c4 Compare April 9, 2026 06:04
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Apr 9, 2026
@code-infra-dashboard

code-infra-dashboard Bot commented Apr 9, 2026 •

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+2.97KB(+0.64%) 🔺+995B(+0.67%)

Details of bundle changes

Performance

Total duration: 1,128.67 ms 🔺+39.55 ms(+3.6%) | Renders: 50 (+0) | Paint: 1,722.98 ms 🔺+51.83 ms(+3.1%)

Test Duration Renders
Select mount (200 instances) 135.95 ms 🔺+18.66 ms(+15.9%) 3 (+0)
Menu mount (300 instances) 131.93 ms 🔺+15.31 ms(+13.1%) 2 (+0)
Tabs mount (200 instances) 213.36 ms 🔺+12.25 ms(+6.1%) 4 (+0)
Mixed surface mount (app-like density) 70.25 ms 🔺+7.50 ms(+12.0%) 5 (+0)
Select open (500 options) 55.11 ms 🔺+6.13 ms(+12.5%) 14 (+0)

…and 7 more — details


Check out the code infra dashboard for more information about this PR.

@oleksandr-danylchenko

Copy link
Copy Markdown

Hey, @atomiks 👋🏻
Was the Tooltip inline rendering stripped out, too? Are there still plans to implement it as a part of a separate PR?

@atomiks

atomiks commented Apr 9, 2026

Copy link
Copy Markdown
Contributor Author

I'm just trying to keep it scoped to preview card for now, as it's the most commonly affected component where this inline positioning is needed as the cost of this is not free

@atomiks
atomiks force-pushed the feat/preview-card-tooltip-inline branch from 5bfe9bb to aa5d637 Compare May 4, 2026 05:39
@michaldudak

Copy link
Copy Markdown
Member

Review summary

Aggregated findings from a multi-agent review (code, tests, error handling, comments) plus one external finding. Recurring concerns cluster around how lineIndex / coords are captured and reused.

Critical

  • Stale hovered-line coords leak across close/reopen of the same trigger. inlineRectCoordsRef is not cleared when the card closes. Hover line 2 → close → reopen the same trigger via controlled open / triggerId (no new hover or focus event) → the trigger-identity check at inlineRect.ts:240-247 accepts the old coords and the popup anchors to the previously hovered line instead of the side-aligned fallback expected for non-hover opens. The existing tests cover stale coords from a different element, not stale coords from the same element across lifecycles. Fix: invalidate inlineRectCoordsRef.current on close (carefully, to avoid exit-position jumps) and add a regression: hover wrapped trigger line 2 → close → controlled-open the same triggerId → assert side-aligned rect.

  • Stale lineIndex is trusted across re-layouts within a single open lifecycle — inlineRect.ts:143-145. The middleware indexes lines[coords.lineIndex] without verifying the captured (x, y) still lies inside that line. If the trigger reflows after capture (font load, container resize, content insertion above), the popup silently anchors to the wrong line. Re-validate the captured coord against the candidate rect before reusing lineIndex, falling back to the x/y re-find.

    These two are related (both stem from coords persisting too long) but neither fix subsumes the other: clear-on-close handles the cross-lifecycle case, re-validate-on-use handles the mid-session re-layout case. Both are needed.

  • Untested middleware safeguards — three branches that protect against runaway behavior have no direct test:

    • The early-return when computed rects equal state.rects.reference (inlineRect.ts:264-270) — guards against Floating UI infinite reset loops.
    • The fast-path when reference.getClientRects is missing (inlineRect.ts:233-237) — needed for custom virtual anchors.
    • The single-line short-circuit (inlineRect.ts:135-137) — every non-wrapping trigger goes through this.

Important

  • Asymmetric coord refresh while open — inlineRect.ts:208-222. onMouseMove early-returns when isOpen, but onMouseEnter always overwrites coords. With safePolygon, users routinely re-enter the trigger from the popup, which would reposition it mid-open. Either gate onMouseEnter on !isOpen for symmetry, or add a comment + test asserting the intended re-anchor.

  • Inverted-comparison branch needs explanation or removal — inlineRect.ts:155-157. The condition lines[0].left > lines[1].right reads like a likely typo (after a top-sort, this is "first line starts right of where second line ends" — unusual geometry). It silently returns the union bounding box, masking stale coords. Add a comment naming the geometry it detects, add a test (multi-column / disjoint two-rect fallback), or delete it.

  • Combined error condition hides integration bugs — inlineRect.ts:249-251. if (!rect || typeof state.platform.getElementRects !== 'function') collapses an expected fall-through (!rect) with a configuration bug (missing platform method). Split them and dev-warn on the second.

  • Synthetic (0, 0) mouse events overwrite valid coords — inlineRect.ts:200-223. Programmatic MouseEvents (tests, accessibility tools) often have clientX/Y === 0. getInlineRectCoords treats these as real coordinates and writes lineIndex: -1 into the ref, replacing earlier valid data. Reject when the coord falls outside the trigger's bounding rect.

  • Left-side placement untested — symmetric to the covered right-side branch (inlineRect.ts:167-189). A copy-paste error (swapped </> or ±Infinity) wouldn't be caught. Mirror the existing right-placement test.

  • Focus-clears-coords integration test doesn't exercise the regression — PreviewCardPositioner.test.tsx:680. The test tabs in from a clean state, so coordsRef is already undefined whether or not onFocus clears it. To assert the actual behavior, hover line 2 first, then blur, then keyboard-open.

Suggestions

  • File header comment overclaims — inlineRect.ts:5-7. "Improved left/right edge grouping" isn't substantiated. Either point at the concrete scenario or drop the claim. The actually non-obvious WHY (why a local copy exists rather than wrapping @floating-ui/react-dom's inline()) is missing.
  • Magic constants lack WHY comments — getLineRects half-height threshold (inlineRect.ts:76) and the ±2px slop in findLineIndex (inlineRect.ts:99-102) are exactly the heuristics future maintainers will second-guess.
  • Floating-point equality in edge grouping — inlineRect.ts:184. nextEdge === edge will miss subpixel-different rects on justified text. Matches Floating UI's own behavior, but Math.abs(nextEdge - edge) < 0.5 would be more robust.
  • findLineIndex returns the first match — inlineRect.ts:96-104. With merged lines containing mixed font sizes (e.g. an <a> containing a <sup>), two lines can both contain the point. Prefer the line whose center is closest to y.
  • Redundant comments in test file — PreviewCardPositioner.test.tsx:120-129. Three comments restate what the assertions already say. The single intent comment at line 102 is enough.
  • Loose X-tolerance windows — integration assertions use ~20px-wide acceptance windows for X-coords; combined with small popup widths, off-by-one-rect regressions could slip through.
  • Trigger-switch test name is misleading — PreviewCardPositioner.test.tsx:467. The test actually asserts "stale coords for the previous trigger don't bleed over." Rename or comment so a future contributor doesn't read it as a no-op.

Strengths

  • Solid coverage of the happy-path scenarios: hovered-line positioning, side-aligned fallback, virtual-reference contextElement, scroll handling, and the keepMounted + custom anchor + collision-boundary regression net.
  • Trigger-identity check correctly handles the multi-trigger Preview Card model (within a single lifecycle).
  • Project-conventions clean: no setTimeout/rAF/document/window global access, owner-doc-aware where it matters, browser-only tests gated with describe.skipIf(isJSDOM), no Chai/Sinon leakage, no flushMicrotasks after await render.
  • Public-API discipline: inline is internal-only on useAnchorPositioning, types exported via the popups barrel, store integration matches the closeDelayRef pattern.
  • Bundle-cost commit shows deliberate care about size impact when reimplementing Floating UI's middleware locally.
  • InlineRectCoords JSDoc is genuinely useful — lineIndex documentation explains a non-obvious capture detail.

Recommended action

  1. Address both stale-coords paths: clear inlineRectCoordsRef on close (cross-lifecycle) and re-validate lineIndex against captured (x, y) at middleware time (mid-session re-layout). Add a regression test for each.
  2. Add tests for the three untested middleware safeguards.
  3. Resolve the onMouseEnter / onMouseMove asymmetry one way or the other and clarify or delete the inverted-comparison branch.
  4. Split the combined !rect || !getElementRects early-out and reject (0, 0) synthetic coords.
  5. Add the missing left-side placement test and rework the focus-coords-clearing integration test so it actually proves what it claims.
  6. Comment / suggestion cleanups can be folded in at the same time.

@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label May 6, 2026
@atomiks
atomiks force-pushed the feat/preview-card-tooltip-inline branch from dca68c1 to a9d8440 Compare May 7, 2026 01:37
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label May 7, 2026
@atomiks
atomiks merged commit eacfe8a into mui:master May 7, 2026
6 checks passed
@atomiks
atomiks deleted the feat/preview-card-tooltip-inline branch May 7, 2026 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: preview card Changes related to the preview card component. component: tooltip Changes related to the tooltip component. type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[preview card][tooltip] Support inline positioning

5 participants