-
Notifications
You must be signed in to change notification settings - Fork 122
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
fix(tooltip): add boundary padding #1065
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ import { useRef, useEffect, useCallback, ReactNode, useMemo } from 'react'; | |
import { createPortal } from 'react-dom'; | ||
|
||
import { mergePartial, isDefined } from '../../utils/common'; | ||
import { Padding } from '../../utils/dimensions'; | ||
import { TooltipPortalSettings, PortalAnchorRef } from './types'; | ||
import { DEFAULT_POPPER_SETTINGS, getOrCreateNode, isHTMLElement } from './utils'; | ||
|
||
|
@@ -56,6 +57,20 @@ type PortalTooltipProps = { | |
chartId: string; | ||
}; | ||
|
||
function addToPadding(padding?: Partial<Padding> | number, extra: number = 0): Padding | number | undefined { | ||
if (!padding) return undefined; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, I don't think this is critical but it should return just the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
if (typeof padding === 'number') return padding + extra; | ||
|
||
const { top = 0, right = 0, bottom = 0, left = 0 } = padding; | ||
|
||
return { | ||
top: top + extra, | ||
right: right + extra, | ||
bottom: bottom + extra, | ||
left: left + extra, | ||
}; | ||
} | ||
|
||
const TooltipPortalComponent = ({ | ||
anchor, | ||
scope, | ||
|
@@ -113,7 +128,7 @@ const TooltipPortalComponent = ({ | |
return; | ||
} | ||
|
||
const { fallbackPlacements, placement, boundary, offset } = popperSettings; | ||
const { fallbackPlacements, placement, boundary, offset, boundaryPadding } = popperSettings; | ||
popper.current = createPopper(anchorNode.current, portalNode.current, { | ||
strategy: 'absolute', | ||
placement, | ||
|
@@ -128,6 +143,7 @@ const TooltipPortalComponent = ({ | |
name: 'preventOverflow', | ||
options: { | ||
boundary, | ||
padding: boundaryPadding, | ||
}, | ||
}, | ||
{ | ||
|
@@ -138,7 +154,7 @@ const TooltipPortalComponent = ({ | |
boundary, | ||
// checks main axis overflow before trying to flip | ||
altAxis: false, | ||
padding: offset || 10, | ||
padding: addToPadding(boundaryPadding, offset || 10), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. with that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure why I had Anyways I removed this and only add the |
||
}, | ||
}, | ||
], | ||
|
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.
Do you want to expose also the
Padding
type?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.
Good idea 8d9f3f6