- 
                Notifications
    You must be signed in to change notification settings 
- Fork 97
          feat(modals, tooltips): adds fallbackPlacements support to Tooltip and TooltipModal
          #2020
        
          New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| </TooltipDialog> | ||
| <Grid> | ||
| <Grid.Row style={{ height: 'calc(100vh - 80px)' }}> | ||
| <Grid.Row style={{ height: 'calc(100vh - 200px)' }}> | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Offset story content to allow for overlay flip.
| }); | ||
|  | ||
| const [floatingPlacement] = getFloatingPlacements( | ||
| const [floatingPlacement, fallbackPlacements] = getFloatingPlacements( | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if props.fallbackPlacements is undefined, getFloatingPlacements will generate opposite fallbackPlacements.
react-components/packages/theming/src/utils/getFloatingPlacements.ts
Lines 57 to 77 in 0101f3c
| const toFallbackPlacements = ( | |
| primaryPlacement: FloatingPlacement, | |
| theme: IGardenTheme, | |
| fallbackPlacements?: Placement[] | |
| ): FloatingPlacement[] => { | |
| if (Array.isArray(fallbackPlacements) && fallbackPlacements.length > 0) { | |
| return fallbackPlacements.map(fallbackPlacement => | |
| toFloatingPlacement(fallbackPlacement, theme) | |
| ); | |
| } | |
| const side = primaryPlacement.split('-')[0]; | |
| const sameSideFallbackPlacements = [...SIDE_FALLBACKS_MAP[side]]; | |
| const oppositeSideFallbackPlacements = SIDE_FALLBACKS_MAP[SIDE_OPPOSITE_MAP[side]]; | |
| // Remove the primary placement from the list of same-side fallbacks to | |
| // prevent extra work for Floating-UI | |
| sameSideFallbackPlacements.splice(sameSideFallbackPlacements.indexOf(primaryPlacement), 1); | |
| return [...sameSideFallbackPlacements, ...oppositeSideFallbackPlacements]; | |
| }; | 
Should we set a sensible default (e.g.: ['bottom']) to both Tooltip and TooltipDialog?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't due to the fact that floating-ui already attempts to position within available space
| appendToNode: PropTypes.any, | ||
| referenceElement: PropTypes.any, | ||
| placement: PropTypes.any, | ||
| // @ts-expect-error Validation error due to incorrect type inference when component is wrapped in forwardRef | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably why George went with fallbackPlacements: PropTypes.arrayOf(PropTypes.any) on Menu.
| }); | ||
|  | ||
| const [floatingPlacement] = getFloatingPlacements( | ||
| const [floatingPlacement, fallbackPlacements] = getFloatingPlacements( | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't due to the fact that floating-ui already attempts to position within available space
| appendToNode: PropTypes.any, | ||
| referenceElement: PropTypes.any, | ||
| placement: PropTypes.any, | ||
| // @ts-expect-error Validation error due to incorrect type inference when component is wrapped in forwardRef | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably why George went with fallbackPlacements: PropTypes.arrayOf(PropTypes.any) on Menu.


Description
This PR adds
fallbackPlacementssupport to bothTooltipandTooltipModal, aligning their behavior withMenuList.Details
fallbackPlacementsprop inTooltipandTooltipModal.placementis not viable due to space constraints.Screen.Recording.2025-05-13.at.6.58.27.AM.mov
Checklist
[ ] 👌 design updates will be Garden Designer approved (add the designer as a reviewer)npm start)[ ] ⚫ renders as expected in dark mode[ ] 🤘 renders as expected with Bedrock CSS (?bedrock)[ ] 💂♂️ includes new unit tests. Maintain existing coverage (always >= 96%)