Skip to content

limitShift(): take middlewareData.offset into account when limiting the mainAxis #1859

@ciampo

Description

@ciampo

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:

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:

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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions