Fix web PaymentElement scrolling in constrained layouts#2423
Conversation
📝 WalkthroughWalkthroughThis PR adds two improvements to the Stripe Flutter web platform. WebStripe now explicitly blocks the ChangesWeb Platform Improvements
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
packages/stripe_web/lib/src/widgets/payment_element.dart (2)
119-121: ⚡ Quick winRemove redundant style assignments.
Lines 119-120 manually set
heightandminHeight, but line 121 immediately calls_applyHostHeight()which sets these same properties (along withmaxHeightand overflow). The manual assignments are redundant.♻️ Simplify by removing redundant assignments
_divElement = web.HTMLDivElement() ..id = 'payment-element' ..style.border = 'none' - ..style.width = '100%' - ..style.height = '${_effectiveHeight}px' - ..style.minHeight = '${_effectiveHeight}px'; + ..style.width = '100%'; _applyHostHeight();🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/stripe_web/lib/src/widgets/payment_element.dart` around lines 119 - 121, Remove the redundant manual style assignments of height and minHeight that use _effectiveHeight and rely on the existing _applyHostHeight() call to set height, minHeight, maxHeight and overflow; specifically, in the PaymentElement widget remove the two lines that set ..style.height = '${_effectiveHeight}px' and ..style.minHeight = '${_effectiveHeight}px' so that only _applyHostHeight() configures these properties (keep _effectiveHeight and _applyHostHeight() as-is).
185-195: ⚡ Quick winConsider allowing horizontal overflow when capped.
When the element is height-capped, line 193 sets
overflowX = 'hidden', which prevents horizontal scrolling. If the PaymentElement contains wide form fields, labels, or validation messages that exceed the container width, they would be clipped without any way to view them.Consider using
overflowX = 'auto'to enable horizontal scrolling when needed, or omit setting it entirely to inherit the default behavior.📜 Proposed change
_divElement.style ..height = heightCss ..minHeight = heightCss ..maxHeight = _isHeightCapped ? heightCss : '' - ..overflowX = _isHeightCapped ? 'hidden' : '' + ..overflowX = '' ..overflowY = _isHeightCapped ? 'auto' : '';Or if you want to enable horizontal scrolling when needed:
_divElement.style ..height = heightCss ..minHeight = heightCss ..maxHeight = _isHeightCapped ? heightCss : '' - ..overflowX = _isHeightCapped ? 'hidden' : '' + ..overflowX = _isHeightCapped ? 'auto' : '' ..overflowY = _isHeightCapped ? 'auto' : '';🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/stripe_web/lib/src/widgets/payment_element.dart` around lines 185 - 195, In _applyHostHeight(), when _isHeightCapped is true the code sets _divElement.style.overflowX = 'hidden' which can clip wide content; change that assignment to 'auto' (or remove the overflowX assignment entirely) so horizontal scrolling is allowed when needed; update the branch that references _isHeightCapped in _applyHostHeight to use overflowX = 'auto' instead of 'hidden' to ensure wide form fields/labels remain accessible.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/stripe_web/lib/src/widgets/payment_element.dart`:
- Around line 119-121: Remove the redundant manual style assignments of height
and minHeight that use _effectiveHeight and rely on the existing
_applyHostHeight() call to set height, minHeight, maxHeight and overflow;
specifically, in the PaymentElement widget remove the two lines that set
..style.height = '${_effectiveHeight}px' and ..style.minHeight =
'${_effectiveHeight}px' so that only _applyHostHeight() configures these
properties (keep _effectiveHeight and _applyHostHeight() as-is).
- Around line 185-195: In _applyHostHeight(), when _isHeightCapped is true the
code sets _divElement.style.overflowX = 'hidden' which can clip wide content;
change that assignment to 'auto' (or remove the overflowX assignment entirely)
so horizontal scrolling is allowed when needed; update the branch that
references _isHeightCapped in _applyHostHeight to use overflowX = 'auto' instead
of 'hidden' to ensure wide form fields/labels remain accessible.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: a4418c17-56cb-4370-bc44-01651db9d839
📒 Files selected for processing (2)
packages/stripe_web/lib/src/web_stripe.dartpackages/stripe_web/lib/src/widgets/payment_element.dart
Fixes
PaymentElementon web when it is placed inside a constrained layout. Fix #2045Add an optional
maxHeight. If Stripe reports content taller than that, the host div is capped and scrolls instead of growing past its parent.Also adds the missing web stub for
setConfirmHandlerto make the package compile.I tested the changes on our project, it is running on the old Flutter version (3.32.8), haven't verify on stable Flutter yet.
AI was used to help inspect the existing web implementation and draft the change. I manually reviewed the changes, tested the patched package in a Flutter web app using a constrained payment sheet, and ran package-level analysis/tests locally.
Summary by CodeRabbit
New Features
maxHeightparameter for improved layout flexibility.Improvements