-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat: Upgrade to Floating UI v1 #24254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9b9c400
feat: Upgrade to Floating UI v1
ling1726 fbdfb3e
changefile
ling1726 d60e58a
update yarn.lock
ling1726 217ebbc
fix lint
ling1726 58a6916
'fix' unit tests
ling1726 0aa4e37
update md
ling1726 288a4c0
pr suggestions
ling1726 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-positioning-2c04f2a8-30a8-43b4-9b96-36b24f1fce36.json
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "minor", | ||
| "comment": "feat: Upgrade to Floating UI v1", | ||
| "packageName": "@fluentui/react-positioning", | ||
| "email": "[email protected]", | ||
| "dependentChangeType": "patch" | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,7 +39,6 @@ describe('Menu', () => { | |
|
|
||
| beforeEach(() => { | ||
| resetIdsForTests(); | ||
| jest.useRealTimers(); | ||
| }); | ||
|
|
||
| /** | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -111,8 +111,8 @@ export function resolvePositioningShorthand(shorthand: PositioningShorthand | un | |
|
|
||
| // Warning: (ae-internal-missing-underscore) The name "usePositioning" should be prefixed with an underscore because the declaration is marked as @internal | ||
| // | ||
| // @internal | ||
| export function usePositioning(options?: UsePopperOptions): { | ||
| // @internal (undocumented) | ||
| export function usePositioning(options: UsePositioningOptions): { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was not public before, are we making it public?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good catch 👍 |
||
| targetRef: React_2.MutableRefObject<any>; | ||
| containerRef: React_2.MutableRefObject<any>; | ||
| arrowRef: React_2.MutableRefObject<any>; | ||
|
|
||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| export const DATA_POSITIONING_INTERSECTING = 'data-popper-is-intersecting'; | ||
| export const DATA_POSITIONING_ESCAPED = 'data-popper-escaped'; | ||
| export const DATA_POSITIONING_HIDDEN = 'data-popper-reference-hidden'; | ||
| export const DATA_POSITIONING_PLACEMENT = 'data-popper-placement'; |
27 changes: 0 additions & 27 deletions
27
packages/react-components/react-positioning/src/isIntersectingModifier.ts
This file was deleted.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
packages/react-components/react-positioning/src/middleware/coverTarget.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import type { Middleware } from '@floating-ui/dom'; | ||
| import { parseFloatingUIPlacement } from '../utils/index'; | ||
|
|
||
| export function coverTarget(): Middleware { | ||
| return { | ||
| name: 'coverTarget', | ||
| fn: middlewareArguments => { | ||
| const { placement, rects, x, y } = middlewareArguments; | ||
| const basePlacement = parseFloatingUIPlacement(placement).side; | ||
| const newCoords = { x, y }; | ||
|
|
||
| switch (basePlacement) { | ||
| case 'bottom': | ||
| newCoords.y -= rects.reference.height; | ||
| break; | ||
| case 'top': | ||
| newCoords.y += rects.reference.height; | ||
| break; | ||
| case 'left': | ||
| newCoords.x += rects.reference.width; | ||
| break; | ||
| case 'right': | ||
| newCoords.x -= rects.reference.width; | ||
| break; | ||
| } | ||
|
|
||
| return newCoords; | ||
| }, | ||
| }; | ||
| } |
18 changes: 18 additions & 0 deletions
18
packages/react-components/react-positioning/src/middleware/flip.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { flip as baseFlip } from '@floating-ui/dom'; | ||
| import type { PositioningOptions } from '../types'; | ||
| import { getBoundary } from '../utils/index'; | ||
|
|
||
| export interface FlipMiddlewareOptions extends Pick<PositioningOptions, 'flipBoundary'> { | ||
| hasScrollableElement?: boolean; | ||
| container: HTMLElement | null; | ||
| } | ||
|
|
||
| export function flip(options: FlipMiddlewareOptions) { | ||
| const { hasScrollableElement, flipBoundary, container } = options; | ||
|
|
||
| return baseFlip({ | ||
| ...(hasScrollableElement && { boundary: 'clippingAncestors' }), | ||
| ...(flipBoundary && { altBoundary: true, boundary: getBoundary(container, flipBoundary) }), | ||
| fallbackStrategy: 'bestFit', | ||
| }); | ||
| } |
6 changes: 6 additions & 0 deletions
6
packages/react-components/react-positioning/src/middleware/index.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| export * from './coverTarget'; | ||
| export * from './flip'; | ||
| export * from './intersecting'; | ||
| export * from './maxSize'; | ||
| export * from './offset'; | ||
| export * from './shift'; |
23 changes: 23 additions & 0 deletions
23
packages/react-components/react-positioning/src/middleware/intersecting.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import type { Middleware } from '@floating-ui/dom'; | ||
| import { detectOverflow } from '@floating-ui/dom'; | ||
|
|
||
| export function intersecting(): Middleware { | ||
| return { | ||
| name: 'intersectionObserver', | ||
| fn: async middlewareArguments => { | ||
| const floatingRect = middlewareArguments.rects.floating; | ||
| const altOverflow = await detectOverflow(middlewareArguments, { altBoundary: true }); | ||
|
|
||
| const isIntersectingTop = altOverflow.top < floatingRect.height && altOverflow.top > 0; | ||
| const isIntersectingBottom = altOverflow.bottom < floatingRect.height && altOverflow.bottom > 0; | ||
|
|
||
| const isIntersecting = isIntersectingTop || isIntersectingBottom; | ||
|
|
||
| return { | ||
| data: { | ||
| intersecting: isIntersecting, | ||
| }, | ||
| }; | ||
| }, | ||
| }; | ||
| } |
39 changes: 39 additions & 0 deletions
39
packages/react-components/react-positioning/src/middleware/maxSize.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import { detectOverflow } from '@floating-ui/dom'; | ||
| import type { Middleware, Side } from '@floating-ui/dom'; | ||
| import type { PositioningOptions } from '../types'; | ||
| import { parseFloatingUIPlacement } from '../utils/index'; | ||
|
|
||
| export function maxSize(autoSize: PositioningOptions['autoSize']): Middleware { | ||
| return { | ||
| name: 'maxSize', | ||
| fn: async middlewareArguments => { | ||
| const { placement, rects, elements, middlewareData } = middlewareArguments; | ||
| const basePlacement = parseFloatingUIPlacement(placement).side; | ||
|
|
||
| const overflow = await detectOverflow(middlewareArguments); | ||
| const { x, y } = middlewareData.shift || { x: 0, y: 0 }; | ||
| const { width, height } = rects.floating; | ||
|
|
||
| const widthProp: Side = basePlacement === 'left' ? 'left' : 'right'; | ||
| const heightProp: Side = basePlacement === 'top' ? 'top' : 'bottom'; | ||
|
|
||
| const applyMaxWidth = | ||
| autoSize === 'always' || | ||
| autoSize === 'width-always' || | ||
| (overflow[widthProp] > 0 && (autoSize === true || autoSize === 'width')); | ||
| const applyMaxHeight = | ||
| autoSize === 'always' || | ||
| autoSize === 'height-always' || | ||
| (overflow[heightProp] > 0 && (autoSize === true || autoSize === 'height')); | ||
|
|
||
| if (applyMaxWidth) { | ||
| elements.floating.style.maxWidth = `${width - overflow[widthProp] - x}px`; | ||
| } | ||
| if (applyMaxHeight) { | ||
| elements.floating.style.maxHeight = `${height - overflow[heightProp] - y}px`; | ||
| } | ||
|
|
||
| return {}; | ||
| }, | ||
| }; | ||
| } |
11 changes: 11 additions & 0 deletions
11
packages/react-components/react-positioning/src/middleware/offset.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { offset as baseOffset } from '@floating-ui/dom'; | ||
| import type { PositioningOptions } from '../types'; | ||
| import { getFloatingUIOffset } from '../utils/getFloatingUIOffset'; | ||
|
|
||
| /** | ||
| * Wraps floating UI offset middleware to to transform offset value | ||
| */ | ||
| export function offset(offsetValue: PositioningOptions['offset']) { | ||
| const floatingUIOffset = getFloatingUIOffset(offsetValue); | ||
| return baseOffset(floatingUIOffset); | ||
| } |
25 changes: 25 additions & 0 deletions
25
packages/react-components/react-positioning/src/middleware/shift.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { shift as baseShift, limitShift } from '@floating-ui/dom'; | ||
| import type { PositioningOptions } from '../types'; | ||
| import { getBoundary } from '../utils/index'; | ||
|
|
||
| export interface ShiftMiddlewareOptions extends Pick<PositioningOptions, 'overflowBoundary'> { | ||
| hasScrollableElement?: boolean; | ||
| disableTether?: PositioningOptions['unstable_disableTether']; | ||
| container: HTMLElement | null; | ||
| } | ||
|
|
||
| /** | ||
| * Wraps the floating UI shift middleware for easier usage of our options | ||
| */ | ||
| export function shift(options: ShiftMiddlewareOptions) { | ||
| const { hasScrollableElement, disableTether, overflowBoundary, container } = options; | ||
|
|
||
| return baseShift({ | ||
| ...(hasScrollableElement && { boundary: 'clippingAncestors' }), | ||
| ...(disableTether && { | ||
| crossAxis: disableTether === 'all', | ||
| limiter: limitShift({ crossAxis: disableTether !== 'all', mainAxis: false }), | ||
| }), | ||
| ...(overflowBoundary && { altBoundary: true, boundary: getBoundary(container, overflowBoundary) }), | ||
| }); | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say that it's a patch, as we didn't bring anything new