fix: SubMenu overflows on small screen widths #8123
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #7986
Submenu Positioning with Floating UI
Overview of Floating UI
flip(): Adjusts placement (e.g.,
top
tobottom
) to prevent overflow.shift(): Moves the floating element along the x or y axis to stay within the viewport. By default, only
mainAxis=true
.Problem Description
Since the submenu is set to
position=right-start
, themainAxis
changes to the y-axis in this horizontal placement. By default,shift()
only adjusts themainAxis
, which may lead to inconsistent behavior due to Floating UI's handling.Solution
Enable
crossAxis: true
inshift()
to allow x-axis adjustments, aligning the submenu to the viewport's right boundary. Asshift()
precedesflip()
in theusePopover
middleware order,flip()
does not trigger horizontal placement changes. The current middleware order inusePopover
is sufficient, ensuring a visually consistent right-aligned submenu.Visual Results
Per Floating UI docs: "Enabling this can lead to the floating element overlapping the reference element, which may not be desired and is often replaced by the flip() middleware."
However, this approach is effective for our use case.
Alternative Approach
Updating the middleware order to

[flip(), shift()]
would flip the submenu toleft-start
on overflow before shifting. The results would appear as follows:Conclusion
Both solutions are effective. I opted for the minimal code change by enabling
crossAxis: true
inshift()
for the align-right approach. Users can modify position and middleware but should be familiar with Floating UI middleware to understand the implications of their changes.