Skip to content

Keep multiline CupertinoTextField placeholders in bounds#183622

Closed
mayanksharma9 wants to merge 3 commits intoflutter:masterfrom
mayanksharma9:fix-183529-cupertino-multiline-placeholder
Closed

Keep multiline CupertinoTextField placeholders in bounds#183622
mayanksharma9 wants to merge 3 commits intoflutter:masterfrom
mayanksharma9:fix-183529-cupertino-multiline-placeholder

Conversation

@mayanksharma9
Copy link
Copy Markdown

@mayanksharma9 mayanksharma9 commented Mar 13, 2026

This fixes a recent regression in CupertinoTextField placeholder layout.

When a CupertinoTextField has a multiline placeholder and maxLines: null, the placeholder is baseline-aligned relative to the editable text, but the stack was vertically aligning only the editable child. That could place the placeholder partially outside the text field bounds.

This change keeps the baseline alignment behavior, but vertically aligns the combined placeholder/editable-text group instead of just the editable child. That keeps multiline placeholders inside the field bounds while preserving the existing baseline-alignment behavior for single-line placeholders.

Fixes #183529

Tests

  • ./bin/flutter test packages/flutter/test/cupertino/text_field_test.dart --plain-name 'Multiline placeholder remains within text field bounds when maxLines is null'
  • ./bin/flutter test packages/flutter/test/cupertino/text_field_test.dart --plain-name 'Placeholder is baseline aligned with text'

Pre-launch Checklist

@github-actions github-actions Bot added a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. f: cupertino flutter/packages/flutter/cupertino repository labels Mar 13, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses a layout regression in CupertinoTextField where a multiline placeholder could be rendered partially out of bounds. The fix adjusts the layout logic in _RenderBaselineAlignedStack to consider the combined height of the editable text and the placeholder for vertical alignment, ensuring both remain within the field's bounds. A new widget test has been added to verify this behavior and prevent future regressions.

Copy link
Copy Markdown
Contributor

@victorsanni victorsanni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, this should target master not main.

@mayanksharma9
Copy link
Copy Markdown
Author

Retargeted to master. Thanks for catching that.

@victorsanni victorsanni added the CICD Run CI/CD label Mar 14, 2026
final double dy = Alignment(
0.0,
textAlignVertical.y,
).alongOffset(Offset(0.0, size.height - alignedGroupHeight)).dy;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we losing information about size.width by using zero horizontal offset? Might this affect positioning in RTL scenarios?

final double placeholderBottom = placeholderTop + (placeholder?.size.height ?? 0.0);
final double alignedGroupTop = math.min(0.0, placeholderTop);
final double alignedGroupBottom = math.max(editableText.size.height, placeholderBottom);
final double alignedGroupHeight = alignedGroupBottom - alignedGroupTop;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of these manual calculations, can we use Rect.expandToInclude to create the aligned group box?

@mayanksharma9
Copy link
Copy Markdown
Author

Thanks for the detailed feedback. I pushed e9ff419 and updated the layout math to build the combined bounds with Rect.expandToInclude, then compute vertical placement directly from textAlignVertical.y so we do not rely on Alignment with a synthetic horizontal offset. I also added an RTL regression test for the multiline placeholder bounds case. Could you take another look?

@github-actions github-actions Bot removed the CICD Run CI/CD label Mar 16, 2026
@stuartmorgan-g
Copy link
Copy Markdown
Contributor

Note to reviewers: this user appears to be running an unsupervised or poorly-supervised agent, and has received a warning and temporary ban. If interaction resumes next week, approach the review with caution.

@victorsanni victorsanni added the CICD Run CI/CD label Mar 23, 2026
@victorsanni victorsanni self-requested a review March 23, 2026 17:44
@Piinks
Copy link
Copy Markdown
Contributor

Piinks commented Mar 23, 2026

Hi @mayanksharma9 thank you for contributing. Given the velocity and quality of changes we received from this account recently, we put a 7 day hold on actions in the Flutter org. Please review our AI contribution guidelines before continuing to contribute. We'll be happy to continue accepting contributions that follow these guidelines once the hold lifts. Thank you! 💙

@github-actions github-actions Bot removed the CICD Run CI/CD label Mar 25, 2026
@victorsanni victorsanni added the CICD Run CI/CD label Apr 1, 2026
final Rect placeholderRect = Offset(0.0, placeholderTop) & (placeholder?.size ?? Size.zero);
final Rect alignedGroupRect = editableTextRect.expandToInclude(placeholderRect);
final double availableDy = size.height - alignedGroupRect.height;
final double dy = (textAlignVertical.y + 1.0) * availableDy / 2.0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain the arithmetic here?

@victorsanni
Copy link
Copy Markdown
Contributor

Thanks for your contribution! We are not able to merge this PR at the moment due to the Material/Cupertino code freeze (#184093). As soon as the decoupling is complete, we will post a way to port this PR to the new packages to land. In the meantime, I'll convert this PR to a draft and apply a label so that we can quickly find it when the freeze is lifted.

@victorsanni victorsanni marked this pull request as draft April 8, 2026 22:32
@victorsanni victorsanni added the waiting for code freeze This PR is waiting for a code freeze to resolve. label Apr 8, 2026
@flutter-dashboard
Copy link
Copy Markdown

This pull request has been changed to a draft. The currently pending flutter-gold status will not be able to resolve until a new commit is pushed or the change is marked ready for review again.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@stuartmorgan-g
Copy link
Copy Markdown
Contributor

Closing as the submitting account has been banned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: text input Entering text in a text field or keyboard related problems CICD Run CI/CD f: cupertino flutter/packages/flutter/cupertino repository framework flutter/packages/flutter repository. See also f: labels. waiting for code freeze This PR is waiting for a code freeze to resolve.

Projects

None yet

5 participants