Fix: Modal rendering across different Iframe contexts #7435
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.
Resolves: GIVE-810
Description
This PR addresses the issues related to the Consent field modal rendering within different contexts on the donation forms.
Originally the modal was rendered with
react.createPortal('document.body)
. This limits the modal to its own iframe. Depending on how to the donation form is being viewed the modal placement will have different positions. To help with this concern our original implementation had scrolled to the middle of the form and rendered the modal. However this was not the modal ideal UI/UX.To further address the issue we have implemented the following changes:
Updated portal element:
react.createPortal('window.top.document.body)
ensures that the modal is inserted at the Top-Level document above all other Iframes. While displayed in either a donation-form-block, the Frontend, in WP editor or on the VisualFormBuilder the form size is different, the element scrolling the form can change and these cause different scroll positions for the modal . By inserting the element above all other documents we can ensure consistent styling across multiple views..Iframe Handling:
Because the modal is now being inserted at the Top-Level document I created a new utility function
createIframePortal()
to handle rendering of child elements within an Iframe. It acts as a wrapper aroundreact.createPortal()
. It will create a new Iframe around the modal and copy the existing Iframe's stylesheets prior to inserting it at the Top-Level. This ensures stylesheets provided by users are still applicable to the Consent field modal & that styling conflicts do not arise from rendering in a new document context.UI/UX improvements
Affects
The terms & conditions block.
The Consent block.
Visuals
Testing Instructions
Pre-review Checklist
@unreleased
tags included in DocBlocks