-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
limitShift(): take middlewareData.offset into account when limiting the mainAxis #1859
Description
While working on WordPress/gutenberg#42950, I reliazed a discrepance in the limitShift logic (that is probably at the cause of this issue that I haven't been able to fix):
When limiting the crossAxis, any potential offset from previous offset middleware is taken into account when computing the min and max limits for the crossAxis:
floating-ui/packages/core/src/middleware/shift.ts
Lines 197 to 206 in 15d1f49
| const limitMin = | |
| rects.reference[crossAxis] - | |
| rects.floating[len] + | |
| (isOriginSide ? middlewareData.offset?.[crossAxis] ?? 0 : 0) + | |
| (isOriginSide ? 0 : computedOffset.crossAxis); | |
| const limitMax = | |
| rects.reference[crossAxis] + | |
| rects.reference[len] + | |
| (isOriginSide ? 0 : middlewareData.offset?.[crossAxis] ?? 0) - | |
| (isOriginSide ? computedOffset.crossAxis : 0); |
However, the offset from the offset middleware is NOT taken into account when computing the min and max limits for the mainAxis:
floating-ui/packages/core/src/middleware/shift.ts
Lines 178 to 185 in 15d1f49
| const limitMin = | |
| rects.reference[mainAxis] - | |
| rects.floating[len] + | |
| computedOffset.mainAxis; | |
| const limitMax = | |
| rects.reference[mainAxis] + | |
| rects.reference[len] - | |
| computedOffset.mainAxis; |
This means that the limitShift logic can't work properly on the mainAxis if there's an offset from the offset middleware on that axis — is there a reason why the offset is not taken into account?
Can the code be changed to include such offset? e.g.
const limitMin =
rects.reference[mainAxis] -
rects.floating[len] +
middlewareData.offset?.[mainAxis] ?? 0 +
computedOffset.mainAxis;
const limitMax =
rects.reference[mainAxis] +
rects.reference[len] +
middlewareData.offset?.[mainAxis] ?? 0 -
computedOffset.mainAxis;