Skip to content

feat(Tooltip): add boundary prop to hide tooltip when it escapes an element#506

Merged
t3chguy merged 2 commits into
element-hq:mainfrom
Tamajit-005:feat/tooltip-boundary
Jun 9, 2026
Merged

feat(Tooltip): add boundary prop to hide tooltip when it escapes an element#506
t3chguy merged 2 commits into
element-hq:mainfrom
Tamajit-005:feat/tooltip-boundary

Conversation

@Tamajit-005

@Tamajit-005 Tamajit-005 commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds an optional boundary prop to useTooltip (and therefore Tooltip) that activates FloatingUI's hide middleware with strategy: "escaped". When the tooltip would overflow the provided boundary, the floating element receives the existing invisible class (clip-path: inset(50%) + pointer-events: none), allowing it to remain in the accessibility tree while being visually hidden.

The boundary is also forwarded to the flip middleware so the initial placement is more likely to remain within the same boundary.

The prop is fully backward compatible. When boundary is omitted, tooltip behavior remains unchanged.

Motivation

Element Web's "Expand map" tooltip on location messages can overlap the message composer at the bottom of the timeline. Constraining the tooltip to the message panel boundary allows it to hide cleanly when it would escape that area, without requiring consumers to implement their own FloatingUI middleware configuration.

Implementation

useTooltip.ts adds boundary?: Element | null | Element[] to CommonUseTooltipProps, forwards it to the existing flip middleware, and conditionally appends hide({ strategy: "escaped", boundary, padding: 6 }) to the middleware list. Tooltip.tsx reads middlewareData?.hide?.escaped and applies the existing invisible class when true. No CSS change is needed.

Follow-up

A corresponding Element Web PR will consume this prop on MLocationBody to keep the "Expand map" tooltip from overlapping the message composer. That PR will land in element-hq/element-web once this change is merged and a new @vector-im/compound-web version is published.

…lement

Adds an optional 'boundary' prop to useTooltip/Tooltip that activates
FloatingUI's 'hide' middleware with strategy='escaped'. When the tooltip
would overflow the boundary, it gets the 'invisible' class (clip-path:
inset(50%)) so it remains in the DOM for screen readers but is visually
hidden. The boundary is also passed to the 'flip' middleware so the
initial placement is more likely to stay inside it.

This lets consumers like Element Web keep the 'Expand map' tooltip on
location messages from overlapping the message composer at the bottom
of the timeline.
@Tamajit-005 Tamajit-005 requested a review from a team as a code owner June 6, 2026 18:49
@Tamajit-005 Tamajit-005 requested review from Half-Shot and t3chguy and removed request for a team June 6, 2026 18:49
Comment thread src/components/Tooltip/useTooltip.ts
Comment thread src/components/Tooltip/useTooltip.ts Outdated
Comment on lines +159 to +160
// Only pass boundary if set — FloatingUI's Boundary type excludes null
...(boundary ? { boundary } : {}),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why not use boundary: boundary ?? undefined then?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed both.
Dropped null from the type and simplified the middleware.

@t3chguy t3chguy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks sane to me, thanks

@t3chguy t3chguy merged commit 6d691ae into element-hq:main Jun 9, 2026
4 of 5 checks 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