fix(limitShift): always apply offset regardless of the axis and the side#1868
fix(limitShift): always apply offset regardless of the axis and the side#1868ciampo wants to merge 2 commits intofloating-ui:masterfrom ciampo:fix/limit-shift-main-axis-offset
Conversation
…ft on the main axis
@floating-ui/core (1.0.1 → 1.0.2)Bug Fixes
Packages With No ChangesThe following packages have no user facing changes, so won't be released:
|
✅ Deploy Preview for vibrant-gates-22c214 canceled.
|
| (isOriginSide ? middlewareData.offset?.[crossAxis] ?? 0 : 0) + | ||
| (middlewareData.offset?.[crossAxis] ?? 0) + | ||
| (isOriginSide ? 0 : computedOffset.crossAxis); | ||
| const limitMax = | ||
| rects.reference[crossAxis] + | ||
| rects.reference[len] + | ||
| (isOriginSide ? 0 : middlewareData.offset?.[crossAxis] ?? 0) - |
There was a problem hiding this comment.
I don't really understand the current approach on master where middlewareData.offset is added depending on isOriginSide
|
For my case, I'm getting away by writing a custom Although I'd still be curious to understand why the offset from the
|
|
The current logic ensures that the offset does not impact the goal to stop shifting once the opposite edges of the reference and floating elements are aligned. With this change, the shifting stops based on the offset, not whether their edges are aligned. |
|
Thank you for the explanation, @atomiks ! I'll explain my use-case a bit more in depth: In the Gutenberg editor, there are situations in which the reference element is inside an iframe, while the floating element is rendered outside of the iframe. The iframe has an offset with respect to the document's viewport, which This causes problems with the We're now experimenting with adding the iframe offset via a separate custom middleware, and also using a custom version of the We're still testing that solution, but it seems to work for us — although I'm wondering if there's a better way around it. Do you have any thoughts? Probably the ideal case scenario would be that |
|
I think better handling of cross-document elements is likely required to get it working properly. Interestingly the future CSS anchor positioning proposal says it will forbid this:
Alternatively, a flag option in the |
I think so too — is that on the roadmap for It would be quite useful to the Gutenberg project too, so in that case it may be interesting to see if we can help move this feature forward.
That is something I wasn't aware of — it looks interesting, though! (and good point about document boundaries). I guess it would be great if there was an explicit way to remove those boundaries if both frames specially state it in some ways (maybe via CSP or something?)
That would be the quickest short-term solution — an additional flag that allows to pass an arbitrary offset value that always gets added to min/max limits. Would that be possible? Happy to open a PR to help get things moving! |
|
I probably won't work on it myself soon, but you're welcome to create a PR to better support cross-document elements for the |
|
I'm going to close this PR and the related issue, and instead I opened two new issues:
It would be great if we could continue the conversation in those two issues. |
Fixes #1859
This PR changes the
limitShiftfunction from theshiftmiddleware so that it always applies themiddlewareData.offsetwhen computing mix/max limits for both the main and the cross axis, regardless of the side (origin or not).See #1859 and WordPress/gutenberg#42950 for extra context