Feature Request: allow autoPlacement to keep a preferred placement when it fits
Description
Currently, autoPlacement chooses the side with the most available space. This is useful, but in some cases it can move the floating element away from the placement the UI would prefer, even when that preferred placement has enough room to render without clipping.
Use case
I have a preferred placement, for example bottom, because it matches the intended layout and user experience. I still want automatic placement when the preferred side cannot fit.
The desired behavior is:
- Try the preferred placement first.
- If the floating element fits there, keep that placement.
- If it does not fit, fall back to the current
autoPlacementbehavior and choose the side with the most available space.
In other words, this would preserve the preferred placement when it is viable, while still keeping the adaptive behavior of autoPlacement for constrained layouts.
Possible API
One possible option could be something like:
autoPlacement({
preferredPlacement: 'bottom',
});or another API shape that better matches the existing middleware design.
Willing to contribute
If this feature makes sense for the project, I would be happy to submit a PR to implement it.
Source: floating-ui/floating-ui