App icon indicating copy to clipboard operation
App copied to clipboard

[$175] Tooltip incorrectly overlaps the fixed filter toolbar

Open melvin-bot[bot] opened this issue 2 weeks ago • 18 comments

Actual behavior

The tooltip renders above the fixed filter toolbar, overlapping it.

Expected behavior

The tooltip should be tucked underneath the fixed filter toolbar.

Video

https://github.com/user-attachments/assets/ab5df86c-e9f9-4cfd-ad1c-f07bd1936488

cc @Expensify/design

Upwork Automation - Do Not Edit
Issue OwnerCurrent Issue Owner: @Gonals

melvin-bot[bot] avatar Nov 15 '26 06:11 melvin-bot[bot]

Proposal

Please re-state the problem that we are trying to solve in this issue.

When scrolling a page with a fixed header and filter toolbar (such as InsightsDashboard or SearchPageWide / SearchPageNarrow in chart or list view), tooltips — specifically ChartTooltip (when a bar/line/pie data point is hovered or touch-pinned while scrolling) and portaled BaseEducationalTooltip / BaseGenericTooltip — render on top of the fixed filter toolbar instead of tucking underneath (or hiding behind) the fixed header/filter toolbar.

What is the root cause of that problem?

There are two complementary causes in the tooltip rendering and positioning pipeline:

  1. Portaled zIndex stacking context & unclamped top boundary in ChartTooltip (src/components/Charts/components/ChartTooltip.tsx & src/components/Charts/components/ChartTooltipPortal/index.tsx):

    • ChartTooltipPortal portals the tooltip directly onto document.body on Web (ReactDOM.createPortal(children, body)) and onto the root <Portal> host on Native (src/components/Charts/components/ChartTooltipPortal/index.native.tsx), applying styles.chartTooltipLayer (zIndex: variables.tooltipZIndex = 10050 in src/styles/index.ts).
    • Meanwhile, the fixed page header (TopBar) and fixed filter toolbar (InsightsPageControls in src/pages/Insights/InsightsDashboard.tsx:359-396, SearchActionsBarWide in src/components/Search/SearchPageHeader/SearchActionsBarWide.tsx:24 with zIndex: 10, and SearchPageNarrow header container with zIndex: 10 / searchTopBarZIndex: 9) live inside the screen subtree at a much lower stacking context.
    • As the user scrolls the ScrollView (InsightsDashboardContent or Search), ChartTooltipAnchor (BoundsObserver on web) updates origin (originY), and tooltipStyle in src/components/Charts/components/ChartTooltip.tsx:161-177 clamps top against const minTop = safeAreaTop; (which is 0 on web/desktop and only the status bar inset on native) and flips the tooltip below the point via PopoverWithMeasuredContentUtils.computeVerticalShift(topAbove - minTop, ...) only when it reaches safeAreaTop, not when it reaches the bottom of the fixed header + filter toolbar. Even worse, when a touch-pinned or hovered chart point scrolls up under the fixed filter toolbar, the portaled tooltip stays visible at zIndex: 10050 right on top of the fixed filter toolbar.
  2. Fixed filter toolbar height is not accounted for in BaseEducationalTooltip (src/components/Tooltip/EducationalTooltip/BaseEducationalTooltip.tsx:85) and scroll dismissal:

    • In BaseEducationalTooltip.tsx:85, availableHeightForTop is calculated as const availableHeightForTop = top - (contentHeaderHeight - offset);, which only subtracts contentHeaderHeight (TopBar height: 72px wide / 64px narrow) and ignores the fixed filter/tab toolbar rendered directly beneath TopBar when !shouldScrollMainHeader.

What changes do you think we should make in order to solve the problem?

Depending on whether the desired behavior for the tooltip is to tuck underneath the fixed header/filter toolbar (via stacking context / clipping) or to respect the fixed toolbar boundary when scrolling:

  1. Render ChartTooltip within the scrollable/content stacking context (below the fixed header & filter toolbar) instead of portaling to document.body above zIndex: 10050, or lower its stacking layer relative to the fixed header/filter bar:
    • In src/pages/Insights/InsightsDashboard.tsx (lines 359–401) and src/pages/Search/SearchPageWide.tsx / SearchPageNarrow/index.tsx, the fixed header (TopBar + InsightsPageControls / SearchActionsBarWide) sits above the <View style={styles.flex1}> content area.
    • If the tooltip should visually tuck underneath the fixed filter toolbar as the chart scrolls up:
      • Provide a scoped portal host (e.g. a <PortalHost name="chartTooltip"> / content-level container ref inside the page content <View style={styles.flex1}> below the fixed header/filter toolbar, or keep overflow: 'hidden' on the scroll viewport below the fixed header) rather than portaling to document.body at zIndex: 10050, or ensure the fixed header + filter toolbar container establishes a stacking context above the chart content while the tooltip is portaled into the content layer below the fixed toolbar.
    • Alternatively, if ChartTooltipPortal remains on document.body / root Portal (so it is never clipped horizontally by card bounds), we can track the bottom boundary of the fixed header/toolbar (or dismiss/clip the tooltip on scroll):
      • In src/components/Charts/components/ChartTooltip.tsx, listen to CONST.EVENTS.SCROLLING (emitted by triggerScrollEvent in InsightsDashboard.tsx:232 and SearchPageNarrow/index.tsx:166, and wire useScrollEventEmitter in Search/index.tsx:1586 for chartScrollViewRef) to either dismiss a touch-pinned tooltip on scroll or clamp/hide isTooltipShown when the anchor point (originY + y) scrolls above the fixed header + filter toolbar bottom edge (headerBottomY).
  2. For BaseEducationalTooltip (src/components/Tooltip/EducationalTooltip/BaseEducationalTooltip.tsx):
    • Allow passing an additional top inset / fixed toolbar offset (or measuring the fixed header + filter bar container height) into availableHeightForTop (top - (contentHeaderHeight + fixedToolbarHeight - offset)) so tooltips with shouldHideOnScroll hide as soon as their target moves under the fixed filter toolbar rather than waiting until it reaches TopBar.

What alternative solutions did you explore? (Optional)

  • Raising the fixed filter toolbar's zIndex above variables.tooltipZIndex (10050): Not recommended because Popover (popoverZIndex: 10000) and Modal (modalBaseZIndex: 9999) rely on the global z-index hierarchy in src/styles/variables.ts, so elevating the filter bar above 10050 would cause the filter bar to overlap open modals and popovers. Scoping the tooltip layer beneath the fixed header/filter bar (or clipping/hiding at the toolbar's bottom edge) cleanly preserves modal and popover layering across all platforms.

cocvn157 avatar Nov 15 '26 15:11 cocvn157

@dubielzyk-expensify Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

Triggered auto assignment to Contributor-plus team member for initial proposal review - @rojiphil (External)

Job added to Upwork: https://www.upwork.com/jobs/~022123174109234820079

Not overdue. Waiting for proposals now

dubielzyk-expensify avatar Nov 18 '26 21:11 dubielzyk-expensify

Proposal

What is the root cause of that problem?

In src/pages/Insights/InsightsDashboard.tsx (lines 545–581), the fixed header (TopBar + InsightsPageControls filter toolbar) renders above the scrollable content container (<View style={styles.flex1}>). While the chart cards scroll cleanly underneath the fixed filter toolbar, the chart tooltip (src/components/Charts/components/ChartTooltip.tsx) escapes that clipping boundary for three reasons:

  1. Root-level portaling above the fixed toolbar: ChartTooltipPortal mounts the tooltip on document.body on web (src/components/Charts/components/ChartTooltipPortal/index.tsx) and on the root @gorhom/portal host on native (index.native.tsx), placing it at zIndex: variables.tooltipZIndex above the fixed header.
  2. Fixed viewport positioning on web: styles.chartTooltipLayer spreads tooltipPlatformStyle, which is position: 'fixed' on web (src/styles/utils/generators/TooltipStyleUtils/tooltipPlatformStyles/index.ts). A fixed element ignores ancestor overflow: hidden clipping and always paints in viewport coordinates.
  3. Window-based top clamping: ChartTooltip.tsx (lines 164–174) computes origin in window coordinates and clamps top against minTop = safeAreaTop (0 on web/desktop), unaware of the fixed filter toolbar's bottom edge. As the hovered point approaches the toolbar during scroll, the tooltip remains positioned above the point and paints directly over the Date / Compare / Workspace / Export controls instead of tucking underneath them.

What changes do you think we should make in order to solve the problem?

Scope the chart tooltip portal inside the scrollable dashboard viewport below the fixed filter toolbar so the tooltip tucks cleanly underneath the toolbar on both web and native without clipping against individual chart cards:

  1. Add an optional ChartTooltipPortalContext (host ref on web, named @gorhom/portal PortalHost on native):
    • Provide a scoped host inside the content container <View style={[styles.flex1, styles.overflowHidden]}> in src/pages/Insights/InsightsDashboard.tsx (below {!shouldScrollMainHeader && header}), so its top edge aligns exactly with the bottom edge of the fixed filter toolbar.
    • Keep the existing root document.body / root <Portal> behavior as the default fallback whenever no scoped host is provided, so charts outside InsightsDashboard are unaffected.
  2. Switch scoped tooltips to host-relative position: 'absolute' coordinates:
    • Web: In ChartTooltipPortal/index.tsx, portal into the scoped host DOM node when present, and use position: 'absolute' instead of position: 'fixed' so the host's overflow: hidden naturally clips the tooltip as it slides underneath the fixed filter toolbar. In ChartTooltipAnchor/index.tsx, subtract the host element's getBoundingClientRect() (x, y) from the anchor bounds so origin is relative to the scoped host (mirroring how ChartTooltipAnchor/index.native.tsx already computes x - hostX, y - hostY against hostOriginRef).
    • Native: Render a named <PortalHost> inside <View style={[styles.flex1, styles.overflowHidden]}> and pass hostName to <Portal> in ChartTooltipPortal/index.native.tsx; ChartTooltipAnchor/index.native.tsx already measures relative to the portal host via hostOriginRef.
  3. Allow the tooltip to slide naturally underneath the top edge when scoped:
    • In ChartTooltip.tsx (tooltipStyle), when rendered inside a scoped clipping host, position vertically relative to the host without forcing Math.max(minTop, ...) or flipping away from the top edge before the anchor scrolls behind the toolbar — so the tooltip tucks smoothly underneath the fixed filter toolbar exactly like the chart card itself, while keeping horizontal clamping within the viewport.
    • Ensure pointerEvents does not intercept clicks on the fixed filter toolbar above the clipping boundary.

What alternative solutions did you explore? (Optional)

  • Raising the filter toolbar zIndex above variables.tooltipZIndex (10050): Rejected because global Modal (9999) and Popover (10000) layers sit below 10050, so raising the toolbar above 10050 would cause it to overlap modals and dropdown popovers.
  • Dismissing the tooltip immediately on any scroll event: Rejected because the expected behavior is for the tooltip to remain visible and tuck smoothly underneath the fixed filter toolbar as the chart scrolls, rather than abruptly disappearing on minor scroll adjustments.

danlopes18-ctrl avatar Nov 21 '26 23:11 danlopes18-ctrl

Not overdue. @rojiphil do we need more proposals here?

dubielzyk-expensify avatar Nov 23 '26 00:11 dubielzyk-expensify

@danlopes18-ctrl Your fix is in the right direction i.e portal the chart tooltip into the content area under the fixed header, with overflow: hidden and host-relative position: absolute, so it clips under the toolbar. Keep the body or root portal as the fallback for charts that are not under a fixed toolbar. Do not raise the toolbar zIndex, and do not dismiss the tooltip on scroll.

Can you please share a test branch with this implementation so that I can conclude the review?

rojiphil avatar Nov 23 '26 03:11 rojiphil

@rojiphil I took a different route to the same result, and I've shared a test branch and before/after videos below. Your constraints are all met: the toolbar's zIndex stays as it is, the tooltip isn't dismissed on scroll, and charts that aren't under a fixed toolbar keep the root portal. Updated: it now also covers the Spend search chart view, wide and narrow, as you asked in your later review.

How this differs from the dashboard portal proposal: that proposal moves the tooltip into a portal host inside the content area and converts ChartTooltipAnchor on web to host-relative position: absolute coordinates. This one leaves the tooltip on document.body, in the window coordinates it already uses, and clips it at the toolbar's measured bottom edge with clip-path. Positioning code stays as it is, nothing changes coordinate systems, and the change is smaller (about 90 lines).

Proposal

Please re-state the problem that we are trying to solve in this issue.

On Insights, when you scroll with a chart tooltip showing, the tooltip covers the fixed filter toolbar (Date / Compare / Group currency / Export). It should slide underneath the toolbar like the chart does.

What is the root cause of that problem?

The toolbar is rendered above the dashboard's scrolling content in InsightsDashboard. On web, ChartTooltipPortal mounts the tooltip on document.body with position: fixed and zIndex: variables.tooltipZIndex, so nothing in the content area clips it. ChartTooltip only keeps the tooltip inside the window's safe area (minTop = safeAreaTop, 0 on web). It doesn't know where the toolbar ends, so it paints over the toolbar until the tooltip reaches the top of the window.

What changes do you think we should make in order to solve the problem?

  1. Add a ChartTooltipClipBoundary around the Insights content area, below the fixed top bar and filter controls. On web it uses BoundsObserver to measure the top edge of the content area and passes that edge (clipTop) down through a small ChartTooltipClipTopContext. The value comes from layout, so it updates when the filter row wraps. On native it is a plain View.
  2. In ChartTooltipPortal (web), keep mounting on document.body. When clipTop is set, wrap the tooltip in a fixed full-window layer with clip-path: inset(<clipTop>px 0 0) and pointer-events: none. Whatever is above the edge is hidden and can't be clicked, so toolbar clicks still reach the toolbar, and a pressable tooltip keeps its own pointerEvents: 'auto'.
  3. Spend search charts (wide and narrow): wrap the chart scroll view in Search with the same boundary.
    • Wide: the filter bar sits above the scroll view, so the clip edge is the scroll view's top.
    • Narrow: the filter header floats over the chart's top padding and slides away as you scroll (topBarOffset in SearchPageNarrow). The boundary takes a topInset (the existing getSearchNarrowHeaderHeight(hasFilterBars)) plus the header's current shift, which SearchPageNarrow passes down as headerOffset. So the clip edge is always the header's current bottom: 228px with the header showing and 64px once it has slid away, where a fixed edge would hide tooltips in the space the header left. Only the boundary and its tooltips re-render as the header slides, not the Search page.
  4. In ChartTooltip, while clipTop is set, don't flip or clamp the tooltip at the top of the window. Flipping there would pull it back out from behind the toolbar. It just follows its point and slides under the toolbar.

Charts without a fixed toolbar get no clipTop and keep today's behavior exactly.

What alternative solutions did you explore? (Optional)

  • Portal inside the content area with overflow: hidden (the other proposal). This clips the top correctly too, but it converts the web anchor to host-relative coordinates and puts the tooltip under a clipping ancestor. That ancestor clips the tooltip's left and right sides as well, for example a tooltip on the first or last point near the edge of a narrow Spend chart, which is the reason the tooltip was moved to document.body in the first place. clip-path only cuts the top edge.
  • Raising the toolbar's zIndex or dismissing the tooltip on scroll. Rejected, for the reasons in your review.

One trade-off for design: if you hover a point sitting just under the toolbar without scrolling, part of its tooltip starts out under the toolbar. I tried flipping it below the point in that case, but then the tooltip jumps below its point while you scroll instead of tucking under, so I kept the tuck-under behavior the issue asks for. It's a one-line change if design prefers the flip.

Test branch

https://github.com/MannA-001/App/tree/test/106940-tooltip-toolbar (rebuilt on the latest main, now including the Spend chart view)

Checks on the branch: typecheck passes, lint adds no new errors, every changed component compiles with the React Compiler (Search/index.tsx already fails on main with the same 9 findings, unchanged), the 8 new tests pass, and the 93 existing chart, Search and Insights tests still pass.

Insights (desktop web 1440×900, local fixture with a signed-in workspace and simulated chart data):

  • The tooltip slides under the toolbar and comes back out when you scroll back up.
  • While it overlaps the toolbar, clicks on the toolbar controls still reach them (hit-tested on Export).
  • When the window narrows and the filter row wraps, the cutoff moves with it (from 132px to 168px).

Before (main: the tooltip covers Compare / Group currency)

https://github.com/user-attachments/assets/77c55f7e-676e-4fdc-9c39-4f9893b6e9f6

After (test branch: the tooltip tucks under the toolbar)

https://github.com/user-attachments/assets/029a6f99-aaf9-41bd-8bb5-d2522765871f

Spend, wide (local fixture with 12 months of expenses in a bar chart: hover November, then scroll the chart up)

Before (main): the tooltip paints over Filters / Display

https://github.com/user-attachments/assets/7cde38b8-6926-430f-b243-9717656b35fd

After: the tooltip slides under the filter bar (clip edge 134px)

https://github.com/user-attachments/assets/923ce2aa-403f-458c-abf8-836641f0d852

Spend, narrow (390×520 touch: scroll down so the header slides away, scroll up a little so it slides back over the chart, then tap November)

Before (main): the tooltip paints over the tabs and search field

https://github.com/user-attachments/assets/a6d9fe5c-5b7a-4eb8-af13-d0be8e3c3ae7

After: the tooltip stays under the header (clip edge 228px). With the header slid away, the edge moves to 64px and the tooltip shows in full.

https://github.com/user-attachments/assets/69c687af-2d1d-4116-b2de-87ea4b37db95

What specific scenarios should we cover in automated tests?

These are written on the test branch (tests/unit/ChartTooltipClipTest.tsx, tests/ui/ChartTooltipClipPlacementTest.tsx). The placement test fails on main (the tooltip is pushed back to 0 instead of staying at -20 under the toolbar).

  • With a fixed toolbar, the web portal wraps the tooltip in a layer clipped at the measured clipTop. With no boundary, it renders straight into document.body as it does today.
  • With clipTop set, ChartTooltip doesn't flip or clamp at the top of the window. Without it, placement matches today's.
  • ChartTooltipClipBoundary provides the area's top edge, adds topInset for a floating header, moves the edge with the header's shift once it has slid away, and provides nothing when disabled.

MannA-001 avatar Nov 23 '26 08:11 MannA-001

@rojiphil Thank you for the review! Here is the test branch rebased on latest main (29381d5c):

  • Test branch: https://github.com/danlopes18-ctrl/App/tree/test/106940-insights-tooltip-portal
  • Commit: https://github.com/danlopes18-ctrl/App/commit/a2286900

Implementation summary

  1. Scoped clipping host (ChartTooltipPortalHost + ChartTooltipPortalContext):
    • Wraps the scrollable content container directly below {!shouldScrollMainHeader && header} in src/pages/Insights/InsightsDashboard.tsx (enabled={!shouldScrollMainHeader}), applying styles.overflowHidden and styles.pRelative only when enabled.
    • Web: portals into the host DOM node via ReactDOM.createPortal (callback ref, avoiding setState in effects) and switches ChartTooltip's layer to styles.pAbsolute while ChartTooltipAnchor/index.tsx subtracts hostElement.getBoundingClientRect() (x, y) so coordinates stay host-relative and automatically track toolbar height changes / filter wrapping via flexbox.
    • Native: renders a named @gorhom/portal <PortalHost name={hostName} /> inside the clipping container and passes hostName to <Portal> in ChartTooltipPortal/index.native.tsx; ChartTooltipAnchor/index.native.tsx already mounts hostOriginRef inside ChartTooltipPortal, so native coordinates align to the scoped host out of the box.
  2. Prevents side clipping & preserves smooth tuck-under:
    • ChartTooltipPortalHost measures hostWidth / hostHeight via onLayout and passes them through ChartTooltipPortalContext.
    • When scoped, ChartTooltip.tsx clamps left strictly against hostWidth ([0, portalWidth - width]) so tooltips near the left/right edges of the dashboard content pane are never clipped horizontally, and allows top to slide smoothly negative under the fixed filter toolbar without clamping to safeAreaTop or flipping below the point.
    • Toolbar zIndex is untouched, tooltips are not dismissed on scroll, and pointer events on the clipped region above the host boundary never intercept toolbar clicks.
  3. Unchanged fallback:
    • When enabled={false} (shouldScrollMainHeader on narrow layouts) or outside InsightsDashboard, ChartTooltipPortalContext is null and ChartTooltipPortal, ChartTooltipAnchor, and ChartTooltip keep the existing document.body / root <Portal> behavior unchanged.

Automated tests planned for the PR

  • Unit tests verifying ChartTooltipPortal mounts into the scoped host when ChartTooltipPortalHost is enabled and falls back to document.body / root <Portal> when disabled or absent.
  • Unit tests verifying ChartTooltipAnchor reports host-relative coordinates inside a scoped host and window coordinates otherwise.
  • Unit tests verifying ChartTooltip uses styles.pAbsolute, clamps horizontally to hostWidth, and allows vertical tuck-under without top clamping when scoped.

Let me know if you'd like any adjustments on the test branch!

danlopes18-ctrl avatar Nov 23 '26 09:11 danlopes18-ctrl

Any updates here @rojiphil ?

dubielzyk-expensify avatar Nov 25 '26 23:11 dubielzyk-expensify

@danlopes18-ctrl Thanks for the test branch. The Insights host is the right approach.

In addition, please note that search chart view still needs the same host. Wide and narrow Spend both render ChartTooltip under a fixed filter bar, so that tooltip still paints over the toolbar. Wrap those content views in ChartTooltipPortalHost the same way as Insights.

rojiphil avatar Nov 26 '26 02:11 rojiphil

@danlopes18-ctrl proposal LGTM along with the additional comment at https://github.com/Expensify/App/issues/106940#issuecomment-7180973033 🎀👀🎀 C+ reviewed

rojiphil avatar Nov 26 '26 02:11 rojiphil

Triggered auto assignment to @Gonals, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

Thank you @rojiphil! Sounds good — I will also wrap the wide and narrow Spend search chart content views in ChartTooltipPortalHost the same way as Insights, and will open the PR as soon as I'm assigned.

danlopes18-ctrl avatar Nov 26 '26 02:11 danlopes18-ctrl

Hi @Gonals — gentle ping on this one since it's marked \Overdue. Happy to open the PR right away as soon as it's assigned whenever you have a moment!

danlopes18-ctrl avatar Nov 30 '26 18:11 danlopes18-ctrl

@rojiphil @Gonals small process thing here. this issue never got the Help Wanted label, only External, so it never showed up in the Help Wanted list and most contributors never saw it. per the contributing guidelines the flow is Help Wanted first, then proposals get reviewed and one is picked. could we add Help Wanted and give it a normal proposal window before assigning anyone?

David-2002065 avatar Nov 30 '26 18:11 David-2002065

small process thing here. This issue never got the Help Wanted label, only External, so it never showed up in the Help Wanted list and most contributors never saw it. per the contributing guidelines the flow is Help Wanted first, then proposals get reviewed and one is picked.

Sorry for the confusion here. You are right about the process as the Help Wanted label should have been applied. As Melvin's proposal was missing, I also missed checking the label before reviewing the proposals. I will be careful next time about this.

@mallenexpensify I think it will help if the automation takes care of applying the Help Wanted label on issues like this where external label is applied and Melvin is not going to post a proposal. What do you think?

rojiphil avatar Dec 01 '26 02:12 rojiphil