Skip to content

feat(FloatingUI): Migrate from popperjs to FloatingUI - #4028

Open
ollie-sutton wants to merge 1 commit into
masterfrom
feat/migrate-to-floating-ui
Open

feat(FloatingUI): Migrate from popperjs to FloatingUI#4028
ollie-sutton wants to merge 1 commit into
masterfrom
feat/migrate-to-floating-ui

Conversation

@ollie-sutton

@ollie-sutton ollie-sutton commented Nov 25, 2025

Copy link
Copy Markdown
Collaborator

Overview

Migrate from popperjs to FloatingUI

Reason

FloatingUI is the replacement for popperjs and it provides some useful util hooks that can be used else where in the design-system (initially the Popover)

Work carried out

  • Migrate from popperjs to FloatingUI
  • Update Popover to use hooks provided by FloatingUI (This will come in a follow up PR as this might require a re-work of the Floating box)

Developer notes

Seems like the functionality is the same between the components, maybe a few things are a pixel or two difference

@ollie-sutton ollie-sutton self-assigned this Nov 25, 2025
@netlify

netlify Bot commented Nov 25, 2025

Copy link
Copy Markdown

Deploy Preview for storybook-navy-digital-mod-uk ready!

Name Link
🔨 Latest commit a9ee5dd
🔍 Latest deploy log https://app.netlify.com/projects/storybook-navy-digital-mod-uk/deploys/6925b4e10a08f80008e85686
😎 Deploy Preview https://deploy-preview-4028--storybook-navy-digital-mod-uk.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@ollie-sutton
ollie-sutton force-pushed the feat/migrate-to-floating-ui branch from 5c5a4ce to a9ee5dd Compare November 25, 2025 13:53
@sonarqubecloud

Copy link
Copy Markdown

@ollie-sutton
ollie-sutton marked this pull request as ready for review November 25, 2025 14:30

@thyhjwb6 thyhjwb6 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good, just a few comments.. maybe we need to chat about what is technically a breaking change.

useFloatingElement is used by useContextMenu which is used by the ContextMenu and that looks like this:

Screenshot 2025-11-26 at 09 35 35

Maybe we just need to make sure FloatingBox is working as expected.

export const useFloatingElement = (
placement: Placement = 'bottom',
strategy: PositioningStrategy = 'fixed',
placement: Placement | 'auto' = 'bottom',

@thyhjwb6 thyhjwb6 Nov 26, 2025

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically this is a breaking change because we export useFloatingElement at the root of the component library. We don't actually document the use of useFloatingElement but we don't document other hooks either and I know they are being used in downstream apps. I wonder if we need to still reference the old types and do some mapping, so the types for the function parameters can be changed in v5 of the Design System.

const isAutoPlacement = placement === 'auto'
const actualPlacement: Placement = isAutoPlacement ? 'bottom' : placement

// Build middleware array

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can remove this set of comments as they are also commented below.


const arrowData = middlewareData.arrow

// Calculate arrow position based on Floating UI's coordinate system

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we could abstract a calculateArrowPosition function which would make this more self-documenting and negate the need for the comment.

// depending on available space. Just verify it has positioning applied.
const floatingBox = screen.getByTestId('floating-box')
const style = floatingBox.style.transform
expect(style).toContain('translate')

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we be more specific with the assertion? Isn't the test positioning always the same?

expect(screen.getByTestId('floating-box')).toHaveStyle({
transform: `translate(0px, ${offsetHeight}px)`,
})
// Floating UI with flip middleware may position the box above or below

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment about assertion.

@github-actions github-actions Bot added the Stale label Jan 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants