File tree Expand file tree Collapse file tree 4 files changed +31
-0
lines changed
Expand file tree Collapse file tree 4 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -43,6 +43,8 @@ interface PopoverContainerProps {
4343 allowVerticalOverflow ?: boolean ;
4444 // Whether the popover should be hidden when the trigger is scrolled away.
4545 hideOnOverscroll ?: boolean ;
46+ // Callback fired when the popover detects it has been scrolled away (overscrolled).
47+ onOverscroll ?: ( ) => void ;
4648 hoverArea ?: boolean ;
4749 className ?: string ;
4850}
@@ -64,6 +66,7 @@ export default function PopoverContainer({
6466 allowScrollToFit,
6567 allowVerticalOverflow,
6668 hideOnOverscroll,
69+ onOverscroll,
6770 hoverArea,
6871 className,
6972} : PopoverContainerProps ) {
@@ -101,6 +104,15 @@ export default function PopoverContainer({
101104 minVisibleBlockSize,
102105 } ) ;
103106
107+ // Call onOverscroll callback when isOverscrolling becomes true
108+ const prevIsOverscrolling = useRef ( false ) ;
109+ useLayoutEffect ( ( ) => {
110+ if ( isOverscrolling && ! prevIsOverscrolling . current && onOverscroll ) {
111+ onOverscroll ( ) ;
112+ }
113+ prevIsOverscrolling . current = isOverscrolling ;
114+ } , [ isOverscrolling , onOverscroll ] ) ;
115+
104116 // Recalculate position when properties change.
105117 useLayoutEffect ( ( ) => {
106118 updatePositionHandler ( ) ;
Original file line number Diff line number Diff line change @@ -122,6 +122,7 @@ const Item = (
122122 content = { disabledReason ! }
123123 position = "right"
124124 __dismissOnScroll = { true }
125+ __onDismissOnScroll = { ( ) => setCanShowTooltip ( false ) }
125126 onEscape = { ( ) => setCanShowTooltip ( false ) }
126127 />
127128 ) }
Original file line number Diff line number Diff line change @@ -52,6 +52,12 @@ export interface InternalTooltipProps extends TooltipProps {
5252 */
5353 __dismissOnScroll ?: boolean ;
5454
55+ /**
56+ * Callback fired when the tooltip is dismissed due to scroll.
57+ * @internal
58+ */
59+ __onDismissOnScroll ?: NonCancelableEventHandler ;
60+
5561 /**
5662 * Additional CSS class for the tooltip container.
5763 * @internal
Original file line number Diff line number Diff line change @@ -24,12 +24,14 @@ export default function InternalTooltip({
2424 trackKey,
2525 position = 'top' ,
2626 __dismissOnScroll,
27+ __onDismissOnScroll,
2728 onEscape,
2829 __internalRootRef,
2930 ...restProps
3031} : InternalTooltipComponentProps ) {
3132 const baseProps = getBaseProps ( restProps ) ;
3233 const trackRef = React . useRef < HTMLElement | SVGElement | null > ( null ) ;
34+ const [ isVisible , setIsVisible ] = React . useState ( true ) ;
3335
3436 // Update the ref with the current tracked element
3537 React . useEffect ( ( ) => {
@@ -64,6 +66,15 @@ export default function InternalTooltip({
6466 } ;
6567 } , [ onEscape ] ) ;
6668
69+ const handleDismissOnScroll = React . useCallback ( ( ) => {
70+ setIsVisible ( false ) ;
71+ fireNonCancelableEvent ( __onDismissOnScroll ) ;
72+ } , [ __onDismissOnScroll ] ) ;
73+
74+ if ( ! isVisible ) {
75+ return null ;
76+ }
77+
6778 return (
6879 < Portal >
6980 < div
@@ -83,6 +94,7 @@ export default function InternalTooltip({
8394 zIndex = { 7000 }
8495 arrow = { position => < PopoverArrow position = { position } /> }
8596 hideOnOverscroll = { __dismissOnScroll }
97+ onOverscroll = { handleDismissOnScroll }
8698 >
8799 < PopoverBody dismissButton = { false } dismissAriaLabel = { undefined } onDismiss = { undefined } header = { undefined } >
88100 { content }
You can’t perform that action at this time.
0 commit comments