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

[Positioner] Not all sticky and positionMethod combos make sense #1207

Open
vladmoroz opened this issue Dec 20, 2024 · 1 comment
Open

[Positioner] Not all sticky and positionMethod combos make sense #1207

vladmoroz opened this issue Dec 20, 2024 · 1 comment
Labels
breaking change component: menu This is the name of the generic UI component, not the React module! component: popover The React component.

Comments

@vladmoroz
Copy link
Contributor

Finally got to test sticky and positionMethod options thoroughly:

https://p8xtr7.csb.app/
https://codesandbox.io/p/sandbox/postion-method-sticky-combos-p8xtr7

Testing in Safari on a M1 Pro device:

Props static container fixed container
positionMethod="absolute" sticky={false} Perfect Skips frames badly
positionMethod="absolute" sticky={true} Skips frames badly Skips frames badly
positionMethod="fixed" sticky={false} Skips frames mildly Perfect*
positionMethod="fixed" sticky={true} Skips frames mildly Perfect*

* Note: in fixed containers, sticky value has no effect

Screen.Recording.2024-12-20.at.16.41.12.mov

Chrome is better, as it skips fewer frames (but exactly in the same ways).
Firefox is similar/worse.

Effectively, there seems to be two combinations that make sense:

  • positionMethod="absolute" sticky={false}
    • Works great in a static container
  • positionMethod="fixed" sticky={true}
    • Works great in a fixed container
    • Works OK in a static container to achieve a sticky positioner

Am I missing the use cases for the rest?

  • positionMethod="fixed" sticky={false}
    • In static containers: just like positionMethod="absolute" sticky={false}, but worse because it can skip frames
    • In fixed containers: exactly like positionMethod="fixed" sticky={true}
  • positionMethod="absolute" sticky={true}
    • In static containers: skips frames when running up the edge
    • In fixed containers: skips frames all the time

If not missing any use cases, it looks like this API can be reduced to a single boolean prop or a single string prop with two values.


One more thing to consider is that it might be viable to implement a different positioning strategy for a better sticky popup experience in a static container: use position absolute while the element is attached to the trigger and switch to position fixed when it attaches to the edge of the viewport. This way, the only opportunity to skip frames would be during the position change, and not during the rest of the scroll events.

@vladmoroz vladmoroz added component: menu This is the name of the generic UI component, not the React module! breaking change component: popover The React component. labels Dec 20, 2024
@atomiks
Copy link
Contributor

atomiks commented Dec 21, 2024

this API can be reduced to a single boolean prop or a single string prop with two values.

Something like positionMethod="sticky", which dynamically switches between the two absolute and fixed states, is something I've thought about in Floating UI. But because their clipping ancestors can be different, it causes glitches/loops under certain conditions when the position property changes between them as it keeps switching back/forth when entering the new positioning context. If the popup is always portaled, this concern is way less of an issue and can be viable though I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change component: menu This is the name of the generic UI component, not the React module! component: popover The React component.
Projects
None yet
Development

No branches or pull requests

2 participants