fix(utils): don't duplicate base placements in get_opposite_axis_placements#340
Merged
DanielleHuisman merged 3 commits intoJun 28, 2026
Conversation
DanielleHuisman
requested changes
Jun 12, 2026
DanielleHuisman
requested changes
Jun 12, 2026
…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>
Co-authored-by: Daniëlle Huisman <danielle@huisman.me>
35eb379 to
8e9a448
Compare
DanielleHuisman
approved these changes
Jun 28, 2026
DanielleHuisman
added a commit
that referenced
this pull request
Jun 28, 2026
…ements (#340) * fix(utils): don't duplicate base placements in get_opposite_axis_placements `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. --------- * chore: remove unnecessary comments * chore: format Co-authored-by: Daniëlle Huisman <danielle@huisman.me> --------- Co-authored-by: kno-raziel <8211946+kno-raziel@users.noreply.github.com> Co-authored-by: Daniëlle Huisman <danielle@huisman.me>
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!