Skip to content
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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

atomiks
Copy link
Contributor

@atomiks atomiks commented Dec 24, 2024

Closes #1195

@atomiks atomiks added component: select This is the name of the generic UI component, not the React module! component: menu This is the name of the generic UI component, not the React module! component: tooltip This is the name of the generic UI component, not the React module! component: popover The React component. component: preview card The React component. labels Dec 24, 2024
@mui-bot
Copy link

mui-bot commented Dec 24, 2024

Netlify deploy preview

https://deploy-preview-1223--base-ui.netlify.app/

Generated by 🚫 dangerJS against 5270eaa

Comment on lines 125 to 128
// Keep these reactive if they're not functions
const sideOffsetDep = typeof sideOffset !== 'function' ? sideOffset : 0;
const alignOffsetDep = typeof alignOffset !== 'function' ? alignOffset : 0;

Copy link
Contributor Author

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)

Comment on lines +21 to +23
"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."
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2024-12-24 at 7 24 35 pm

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 },
Copy link
Contributor Author

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

@atomiks atomiks marked this pull request as ready for review December 26, 2024 03:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: menu This is the name of the generic UI component, not the React module! component: popover The React component. component: preview card The React component. component: select This is the name of the generic UI component, not the React module! component: tooltip This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Popover] [Potential Feature Request] How to align the start of the popover with the center of the trigger?
2 participants