feat(Tooltip): add boundary prop to hide tooltip when it escapes an element#506
Merged
Merged
Conversation
…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.
t3chguy
reviewed
Jun 8, 2026
t3chguy
reviewed
Jun 8, 2026
Comment on lines
+159
to
+160
| // Only pass boundary if set — FloatingUI's Boundary type excludes null | ||
| ...(boundary ? { boundary } : {}), |
Member
There was a problem hiding this comment.
why not use boundary: boundary ?? undefined then?
Contributor
Author
There was a problem hiding this comment.
Fixed both.
Dropped null from the type and simplified the middleware.
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.
Summary
Adds an optional
boundaryprop touseTooltip(and thereforeTooltip) that activates FloatingUI'shidemiddleware withstrategy: "escaped". When the tooltip would overflow the provided boundary, the floating element receives the existinginvisibleclass (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
flipmiddleware so the initial placement is more likely to remain within the same boundary.The prop is fully backward compatible. When
boundaryis 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.tsaddsboundary?: Element | null | Element[]toCommonUseTooltipProps, forwards it to the existingflipmiddleware, and conditionally appendshide({ strategy: "escaped", boundary, padding: 6 })to the middleware list.Tooltip.tsxreadsmiddlewareData?.hide?.escapedand applies the existinginvisibleclass when true. No CSS change is needed.Follow-up
A corresponding Element Web PR will consume this prop on
MLocationBodyto 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-webversion is published.