-
-
Notifications
You must be signed in to change notification settings - Fork 79
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
[useAnchorPositioning] Add OffsetFunction
for sideOffset
and alignOffset
#1223
base: master
Are you sure you want to change the base?
Conversation
Netlify deploy preview |
// Keep these reactive if they're not functions | ||
const sideOffsetDep = typeof sideOffset !== 'function' ? sideOffset : 0; | ||
const alignOffsetDep = typeof alignOffset !== 'function' ? alignOffset : 0; | ||
|
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.
Positioning reactivity is lost when they specify a function. We can't tell if they're going to React.useCallback
or not - usually the function gets inlined like:
<Popover.Positioner sideOffset={(sizes) => sizes.anchor.height / 2}>
So it can't be specified as a dependency as it's always changing. This means if they update the math inside the function, the position won't update live on fast refresh (but it will whenever the anchoring updates at some point)
"type": "number | (data) => number", | ||
"default": "0", | ||
"description": "Distance between the anchor and the popup." | ||
"description": "Distance between the anchor and the popup in pixels.\nAlso accepts a function that returns a number to read the dimensions of the anchor and popup,\nalong with its side and alignment.\n\n- `data.anchor`: the dimensions of the anchor element with properties `width` and `height`.\n- `data.popup`: the dimensions of the popup element with properties `width` and `height`.\n- `data.side`: which side of the anchor element the popup is aligned against.\n- `data.align`: how the popup is aligned relative to the specified side." |
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.
side: getLogicalSide(sideParam, getSide(currentPlacement), isRtl), | ||
align: getAlignment(currentPlacement) || 'center', | ||
anchor: { width: rects.reference.width, height: rects.reference.height }, | ||
popup: { width: rects.floating.width, height: rects.floating.height }, |
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.
Technically this is the Positioner
element, not Popup
, but in practically every case they should be the same since it's a presentational wrapper
Closes #1195