fix(utils): don't duplicate base placements in get_opposite_axis_placements#340
Open
kno-raziel wants to merge 1 commit into
Open
fix(utils): don't duplicate base placements in get_opposite_axis_placements#340kno-raziel wants to merge 1 commit into
kno-raziel wants to merge 1 commit into
Conversation
…ements
`get_opposite_axis_placements` applied the flip-alignment duplication
unconditionally. In the JS source (`@floating-ui/utils`) this block is nested
inside `if (alignment)`, so base placements (Top/Bottom/Left/Right) must not be
duplicated. Without the guard, e.g.
get_opposite_axis_placements(Placement::Top, true, Some(Alignment::Start), None)
returned `[Left, Right, Left, Right]` instead of `[Left, Right]`.
Guard the block with `alignment.is_some()` to match the JS behaviour, and add a
`#[cfg(test)]` module porting `getOppositeAxisPlacements.test.ts` (16 cases);
`utils` previously had no tests.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
DanielleHuisman
requested changes
Jun 12, 2026
Comment on lines
+715
to
+717
| // The flip-alignment duplication only applies to aligned placements. In the | ||
| // JS source this block is nested inside `if (alignment)`; without that guard, | ||
| // base placements (e.g. Top/Bottom/Left/Right) are returned duplicated. |
Member
There was a problem hiding this comment.
Suggested change
| // The flip-alignment duplication only applies to aligned placements. In the | |
| // JS source this block is nested inside `if (alignment)`; without that guard, | |
| // base placements (e.g. Top/Bottom/Left/Right) are returned duplicated. |
DanielleHuisman
requested changes
Jun 12, 2026
Comment on lines
+769
to
+770
| #[cfg(test)] | ||
| mod opposite_axis_placements_tests { |
Member
There was a problem hiding this comment.
Suggested change
| #[cfg(test)] | |
| mod opposite_axis_placements_tests { | |
| #[cfg(test)] | |
| mod tests { |
Comment on lines
+771
to
+772
| // Ported from @floating-ui/utils | ||
| // packages/utils/test/getOppositeAxisPlacements.test.ts |
Member
There was a problem hiding this comment.
Suggested change
| // Ported from @floating-ui/utils | |
| // packages/utils/test/getOppositeAxisPlacements.test.ts |
| get_opposite_axis_placements(placement, flip, Some(dir), Some(true)) | ||
| } | ||
|
|
||
| // --- side --- |
Member
There was a problem hiding this comment.
Suggested change
| // --- side --- |
| assert_eq!(goap(Right, true, Alignment::End), vec![Bottom, Top]); | ||
| } | ||
|
|
||
| // --- start alignment --- |
Member
There was a problem hiding this comment.
Suggested change
| // --- start alignment --- |
| assert_eq!(goap(RightStart, true, Alignment::End), vec![BottomStart, TopStart, BottomEnd, TopEnd]); | ||
| } | ||
|
|
||
| // --- end alignment --- |
Member
There was a problem hiding this comment.
Suggested change
| // --- end alignment --- |
Comment on lines
+855
to
+856
| // NOTE: upstream JS test asserts left-end for the non-flip cases and | ||
| // (verbatim, an upstream copy-paste) left-start for the flip cases. |
Member
There was a problem hiding this comment.
Suggested change
| // NOTE: upstream JS test asserts left-end for the non-flip cases and | |
| // (verbatim, an upstream copy-paste) left-start for the flip cases. |
| assert_eq!(goap(RightEnd, true, Alignment::End), vec![BottomEnd, TopEnd, BottomStart, TopStart]); | ||
| } | ||
|
|
||
| // --- rtl --- |
Member
There was a problem hiding this comment.
Suggested change
| // --- rtl --- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
get_opposite_axis_placementsapplies the flip-alignment duplication unconditionally:In the JS source (
@floating-ui/utils) this block is nested insideif (alignment), so base placements (no alignment) are never duplicated:Without the guard, a base placement comes back duplicated:
Fix
Guard the flip-alignment block with
alignment.is_some()to match the JS behaviour (thelist.map(...)step is already a no-op for base placements viaget_placement(side, None), so only the duplication needed guarding).Tests
Adds a
#[cfg(test)]module porting the JS suitepackages/utils/test/getOppositeAxisPlacements.test.ts(16 cases: side / start-alignment / end-alignment / rtl).packages/utilshad no tests previously; these fail before the fix on the base-placement cases and pass after.Found while building a Leptos UI library on top of this crate — thanks for the Rust port!