@@ -9,7 +9,14 @@ import React, { HTMLAttributes, useState, useContext, useEffect, useRef } from '
99import PropTypes from 'prop-types' ;
1010import { ThemeContext } from 'styled-components' ;
1111import { CSSTransition } from 'react-transition-group' ;
12- import { autoPlacement , autoUpdate , offset , platform , useFloating } from '@floating-ui/react-dom' ;
12+ import {
13+ autoPlacement ,
14+ autoUpdate ,
15+ flip ,
16+ offset ,
17+ platform ,
18+ useFloating
19+ } from '@floating-ui/react-dom' ;
1320import { useModal } from '@zendeskgarden/container-modal' ;
1421import { mergeRefs } from 'react-merge-refs' ;
1522import { TooltipDialogContext } from '../../utils/useTooltipDialogContext' ;
@@ -18,7 +25,7 @@ import {
1825 StyledTooltipDialog ,
1926 StyledTooltipDialogBackdrop
2027} from '../../styled' ;
21- import { ITooltipDialogProps } from '../../types' ;
28+ import { ITooltipDialogProps , PLACEMENT } from '../../types' ;
2229import { Title } from './Title' ;
2330import { Body } from './Body' ;
2431import { Close } from './Close' ;
@@ -35,6 +42,7 @@ const TooltipDialogComponent = React.forwardRef<HTMLDivElement, ITooltipDialogPr
3542 appendToNode,
3643 referenceElement,
3744 placement : _placement ,
45+ fallbackPlacements : _fallbackPlacements ,
3846 offset : _offset ,
3947 onClose,
4048 hasArrow,
@@ -64,9 +72,10 @@ const TooltipDialogComponent = React.forwardRef<HTMLDivElement, ITooltipDialogPr
6472 restoreFocus : false
6573 } ) ;
6674
67- const [ floatingPlacement ] = getFloatingPlacements (
75+ const [ floatingPlacement , fallbackPlacements ] = getFloatingPlacements (
6876 theme ,
69- _placement === 'auto' ? PLACEMENT_DEFAULT : _placement !
77+ _placement === 'auto' ? PLACEMENT_DEFAULT : _placement ! ,
78+ _fallbackPlacements
7079 ) ;
7180
7281 const {
@@ -83,7 +92,7 @@ const TooltipDialogComponent = React.forwardRef<HTMLDivElement, ITooltipDialogPr
8392 placement : floatingPlacement ,
8493 middleware : [
8594 offset ( _offset === undefined ? theme . space . base * 3 : _offset ) ,
86- _placement === 'auto' ? autoPlacement ( ) : undefined
95+ _placement === 'auto' ? autoPlacement ( ) : flip ( { fallbackPlacements } )
8796 ]
8897 } ) ;
8998
@@ -194,6 +203,10 @@ TooltipDialogComponent.propTypes = {
194203 appendToNode : PropTypes . any ,
195204 referenceElement : PropTypes . any ,
196205 placement : PropTypes . any ,
206+ // @ts -expect-error Validation error due to incorrect type inference when component is wrapped in forwardRef
207+ fallbackPlacements : PropTypes . arrayOf (
208+ PropTypes . oneOf ( PLACEMENT . filter ( placement => placement !== 'auto' ) )
209+ ) ,
197210 isAnimated : PropTypes . bool ,
198211 hasArrow : PropTypes . bool ,
199212 zIndex : PropTypes . number ,
0 commit comments