Skip to content

Commit 39c8556

Browse files
authored
refactor: improve types and internal codebase consistency (#2948)
1 parent ad06eb6 commit 39c8556

35 files changed

+1081
-1101
lines changed

.changeset/angry-monkeys-juggle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@floating-ui/react": patch
3+
---
4+
5+
fix(useInteractions): split prop getter dependencies so that only the relevant element changes when necessary. Previously `reference` and `floating` prop getters had dependencies grouped.

.changeset/brown-ducks-melt.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@floating-ui/react": patch
3+
---
4+
5+
fix(useFocus): prevent SyntheticEvent warning on React <17

.changeset/calm-carpets-tap.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@floating-ui/react": patch
3+
---
4+
5+
fix(inner): allow to make Derivable

.changeset/weak-apples-cover.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@floating-ui/react-dom': patch
3+
'@floating-ui/react': patch
4+
'@floating-ui/utils': patch
5+
'@floating-ui/core': patch
6+
'@floating-ui/dom': patch
7+
---
8+
9+
refactor: improve types and internal codebase consistency. All documented types are now exported.

packages/core/src/computePosition.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
import {computeCoordsFromPlacement} from './computeCoordsFromPlacement';
2-
import type {
3-
ComputePosition,
4-
ComputePositionReturn,
5-
Middleware,
6-
MiddlewareData,
7-
} from './types';
2+
import type {ComputePosition, Middleware, MiddlewareData} from './types';
83

94
/**
105
* Computes the `x` and `y` coordinates that will place the floating element
@@ -17,7 +12,7 @@ export const computePosition: ComputePosition = async (
1712
reference,
1813
floating,
1914
config,
20-
): Promise<ComputePositionReturn> => {
15+
) => {
2116
const {
2217
placement = 'bottom',
2318
strategy = 'absolute',

packages/core/src/detectOverflow.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,34 @@ import type {
99
RootBoundary,
1010
} from './types';
1111

12-
export type DetectOverflowOptions = Partial<{
12+
export interface DetectOverflowOptions {
1313
/**
1414
* The clipping element(s) or area in which overflow will be checked.
1515
* @default 'clippingAncestors'
1616
*/
17-
boundary: Boundary;
18-
17+
boundary?: Boundary;
1918
/**
2019
* The root clipping area in which overflow will be checked.
2120
* @default 'viewport'
2221
*/
23-
rootBoundary: RootBoundary;
24-
22+
rootBoundary?: RootBoundary;
2523
/**
2624
* The element in which overflow is being checked relative to a boundary.
2725
* @default 'floating'
2826
*/
29-
elementContext: ElementContext;
30-
27+
elementContext?: ElementContext;
3128
/**
3229
* Whether to check for overflow using the alternate element's boundary
3330
* (`clippingAncestors` boundary only).
3431
* @default false
3532
*/
36-
altBoundary: boolean;
37-
33+
altBoundary?: boolean;
3834
/**
3935
* Virtual padding for the resolved overflow detection offsets.
4036
* @default 0
4137
*/
42-
padding: Padding;
43-
}>;
38+
padding?: Padding;
39+
}
4440

4541
/**
4642
* Resolves with an object of overflow side offsets that determine how much the

packages/core/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,6 @@ export type {
5252
Strategy,
5353
VirtualElement,
5454
} from '@floating-ui/utils';
55+
// This export exists only for backwards compatibility. It will be removed in
56+
// the next major version.
5557
export {rectToClientRect} from '@floating-ui/utils';

packages/core/src/middleware/arrow.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ export interface ArrowOptions {
1717
* @default undefined
1818
*/
1919
element: any;
20-
2120
/**
2221
* The padding between the arrow element and the floating element edges.
2322
* Useful when the floating element has rounded corners.

packages/core/src/middleware/autoPlacement.ts

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -42,36 +42,31 @@ export function getPlacementList(
4242
});
4343
}
4444

45-
export type AutoPlacementOptions = Partial<
46-
DetectOverflowOptions & {
47-
/**
48-
* The axis that runs along the alignment of the floating element. Determines
49-
* whether to check for most space along this axis.
50-
* @default false
51-
*/
52-
crossAxis: boolean;
53-
54-
/**
55-
* Choose placements with a particular alignment.
56-
* @default undefined
57-
*/
58-
alignment: Alignment | null;
59-
60-
/**
61-
* Whether to choose placements with the opposite alignment if the preferred
62-
* alignment does not fit.
63-
* @default true
64-
*/
65-
autoAlignment: boolean;
66-
67-
/**
68-
* Which placements are allowed to be chosen. Placements must be within the
69-
* `alignment` option if explicitly set.
70-
* @default allPlacements (variable)
71-
*/
72-
allowedPlacements: Array<Placement>;
73-
}
74-
>;
45+
export interface AutoPlacementOptions extends DetectOverflowOptions {
46+
/**
47+
* The axis that runs along the alignment of the floating element. Determines
48+
* whether to check for most space along this axis.
49+
* @default false
50+
*/
51+
crossAxis?: boolean;
52+
/**
53+
* Choose placements with a particular alignment.
54+
* @default undefined
55+
*/
56+
alignment?: Alignment | null;
57+
/**
58+
* Whether to choose placements with the opposite alignment if the preferred
59+
* alignment does not fit.
60+
* @default true
61+
*/
62+
autoAlignment?: boolean;
63+
/**
64+
* Which placements are allowed to be chosen. Placements must be within the
65+
* `alignment` option if explicitly set.
66+
* @default allPlacements (variable)
67+
*/
68+
allowedPlacements?: Array<Placement>;
69+
}
7570

7671
/**
7772
* Optimizes the visibility of the floating element by choosing the placement

packages/core/src/middleware/flip.ts

Lines changed: 36 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -13,49 +13,42 @@ import type {DetectOverflowOptions} from '../detectOverflow';
1313
import {detectOverflow} from '../detectOverflow';
1414
import type {Derivable, Middleware} from '../types';
1515

16-
export type FlipOptions = Partial<
17-
DetectOverflowOptions & {
18-
/**
19-
* The axis that runs along the side of the floating element. Determines
20-
* whether overflow along this axis is checked to perform a flip.
21-
* @default true
22-
*/
23-
mainAxis: boolean;
24-
25-
/**
26-
* The axis that runs along the alignment of the floating element. Determines
27-
* whether overflow along this axis is checked to perform a flip.
28-
* @default true
29-
*/
30-
crossAxis: boolean;
31-
32-
/**
33-
* Placements to try sequentially if the preferred `placement` does not fit.
34-
* @default [oppositePlacement] (computed)
35-
*/
36-
fallbackPlacements: Array<Placement>;
37-
38-
/**
39-
* What strategy to use when no placements fit.
40-
* @default 'bestFit'
41-
*/
42-
fallbackStrategy: 'bestFit' | 'initialPlacement';
43-
44-
/**
45-
* Whether to allow fallback to the perpendicular axis of the preferred
46-
* placement, and if so, which side direction along the axis to prefer.
47-
* @default 'none' (disallow fallback)
48-
*/
49-
fallbackAxisSideDirection: 'none' | 'start' | 'end';
50-
51-
/**
52-
* Whether to flip to placements with the opposite alignment if they fit
53-
* better.
54-
* @default true
55-
*/
56-
flipAlignment: boolean;
57-
}
58-
>;
16+
export interface FlipOptions extends DetectOverflowOptions {
17+
/**
18+
* The axis that runs along the side of the floating element. Determines
19+
* whether overflow along this axis is checked to perform a flip.
20+
* @default true
21+
*/
22+
mainAxis?: boolean;
23+
/**
24+
* The axis that runs along the alignment of the floating element. Determines
25+
* whether overflow along this axis is checked to perform a flip.
26+
* @default true
27+
*/
28+
crossAxis?: boolean;
29+
/**
30+
* Placements to try sequentially if the preferred `placement` does not fit.
31+
* @default [oppositePlacement] (computed)
32+
*/
33+
fallbackPlacements?: Array<Placement>;
34+
/**
35+
* What strategy to use when no placements fit.
36+
* @default 'bestFit'
37+
*/
38+
fallbackStrategy?: 'bestFit' | 'initialPlacement';
39+
/**
40+
* Whether to allow fallback to the perpendicular axis of the preferred
41+
* placement, and if so, which side direction along the axis to prefer.
42+
* @default 'none' (disallow fallback)
43+
*/
44+
fallbackAxisSideDirection?: 'none' | 'start' | 'end';
45+
/**
46+
* Whether to flip to placements with the opposite alignment if they fit
47+
* better.
48+
* @default true
49+
*/
50+
flipAlignment?: boolean;
51+
}
5952

6053
/**
6154
* Optimizes the visibility of the floating element by flipping the `placement`

0 commit comments

Comments
 (0)