Skip to content

fix: let overlays handle presses and Tab on tooltip anchors - #303

Merged
starc007 merged 2 commits into
starc007:mainfrom
l4u532:fix/tooltip-dismiss-layer
Nov 30, 2026
Merged

starc007 merged 2 commits into
starc007:mainfrom
l4u532:fix/tooltip-dismiss-layer

Conversation

@l4u532

@l4u532 l4u532 commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

tl;dr

Reproduction

Open Options, hover Add until its tooltip shows, then click Add.

import { useState } from "react";
import {
  DropdownMenu,
  DropdownMenuContent,
  DropdownMenuItem,
  DropdownMenuTrigger,
} from "@/components/motion/dropdown-menu";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/motion/tooltip";

export function TooltipDismissRepro() {
  const [count, setCount] = useState(0);

  return (
    <div style={{ display: "flex", alignItems: "center", gap: 32 }}>
      <DropdownMenu>
        <DropdownMenuTrigger>
          <button type="button">Options</button>
        </DropdownMenuTrigger>
        <DropdownMenuContent>
          <DropdownMenuItem>Rename</DropdownMenuItem>
        </DropdownMenuContent>
      </DropdownMenu>
      <Tooltip>
        <TooltipTrigger onClick={() => setCount((count) => count + 1)}>
          Add
        </TooltipTrigger>
        <TooltipContent>Add one</TooltipContent>
      </Tooltip>
      <output>Count: {count}</output>
    </div>
  );
}

For the consuming case, replace Dropdown Menu with TableMenu. Pass ariaLabel="Options", trigger="Options", and one Rename item.

The touch reproduction uses a staged setup because touch has no hover. Tapping Add to show the tooltip would close an open menu. Open the menu, then mount the Tooltip with defaultOpen on a short timer. Wait for its bubble to appear, then tap Add.

Browser verification

Captured on 2026-11-29. Playwright read the menu state and count in Chrome. Safari on an iPhone 17 Pro simulator exposed the menu item and count in its accessibility tree.

First press with the tooltip visible Before #292 (40e138ae) Upstream (c0944430) Proposed fix
Dropdown Menu Closes, count 1 Stays open, count 1 Closes, count 1
Table Menu Closes, count 1 Stays open, count 1 Closes, count 0

Chrome mouse, Chrome touch emulation and iPhone Safari touch gave the same menu and count results. On upstream, the first press hides the tooltip and the second closes the menu.

Chrome mouse. The fixed table menu closes with the count at zero.

Chrome mouse comparison

iPhone Safari touch. The closing tap leaves the count at zero. The next tap dismisses the tooltip and adds one.

iPhone Safari touch comparison

Before #292. Both menus closed. Table Menu already let the first press through.

Chrome and Safari before #292

Chrome chart and keyboard. A press on a Treemap tile left the dropdown open on upstream. With the patch, it closes. Tab from Close panel in Center Morph Modal moved focus out of the document on upstream. With the patch, it returns to Save inside the modal.

Chrome chart press and modal Tab comparison

Cause and scope

Tooltip now passes the bubble as the shared useDismiss hook's optional layerRef. Other overlays use that element for outside presses and focus traps. The ref matches the hook's existing DOM boundary API. The tooltip still checks both the anchor and bubble for its own dismissal.

Since #292, useDismiss returns early for a press in a layer opened above the current overlay. Tooltip had registered both the bubble and anchor in its layer. Even before #292, inOtherLayer used that boundary when deciding whether to consume the click.

The tooltip's capture listener must leave anchor presses to the trigger. That gives the trigger's pointerdown handler time to record that the tooltip was open. Using the bubble for both boundaries made the second tap reopen the tooltip in Chrome touch emulation.

The same boundary applies to chart tooltips whose anchor is the whole plot. It also keeps focus traps from treating a focused tooltip trigger as part of a newer layer.

Chrome and iPhone Safari confirmed that pressing the portaled bubble still keeps its containing popover open, as intended by #292. Ordinary two-tap tooltip toggling passed in both. At 375 px with reduced motion, Chrome showed the tooltip on Tab to Add and dismissed it on Escape. Desktop Safari mouse, keyboard and reduced motion remain unverified.

The Tooltip code applies cleanly alongside #299, which covers inert anchors. Both PRs edit Tooltip's accessibility paragraph and the registry dates, so the second to merge needs a small rebase.

Test plan

  1. In Dropdown Menu, press Add with its tooltip visible. The first press closes the menu and increments the count.
  2. In Table Menu, repeat. The first press closes the menu with the count at zero. A second press increments it.
  3. Inside MorphPopoverContent, wrap a button in a Tooltip. Open the popover, tap that button to show its tooltip, then tap the bubble. The popover stays open.
  4. Render the Dropdown Menu from the reproduction beside TreemapPreview. Open the menu, hover a tile until its tooltip shows, then click the tile. The menu closes.
  5. Render a Center Morph Modal whose content has one Save button. Tab from Save to the close button. With its tooltip visible, press Tab again. Focus returns to Save.
  6. Run bun run check and bun test. Both passed with 196 registry components and 239 accessibility tests.

@l4u532

l4u532 commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

Updated in 8ee87fda.

  • lib/layers.ts. The contains doc is back to one sentence, like the other Layer fields. The reason Tooltip passes only its bubble stays beside the useDismiss call in tooltip.tsx.
  • About copy. Tooltip's accessibility paragraph now says that Tab and Shift Tab keep cycling inside a dialog while the trigger's tooltip shows.
  • Description.

There is no runtime change. bun run check (196 registry components) and bun test (239 tests) pass.

@l4u532
l4u532 force-pushed the fix/tooltip-dismiss-layer branch from 8ee87fd to eb6c723 Compare November 30, 2026 09:04
@starc007
starc007 merged commit ad6d11c into starc007:main Nov 30, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants