Skip to content

Commit

Permalink
Fixes multi line textfield hint text gets ellipsized (#148423)
Browse files Browse the repository at this point in the history
  • Loading branch information
chunhtai authored Jun 3, 2024
1 parent 5e448f4 commit 6ec1c75
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/material/input_decorator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2164,7 +2164,7 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
hintText,
style: hintStyle,
textDirection: decoration.hintTextDirection,
overflow: hintStyle.overflow ?? TextOverflow.ellipsis,
overflow: hintStyle.overflow ?? (decoration.hintMaxLines == null ? null : TextOverflow.ellipsis),
textAlign: textAlign,
maxLines: decoration.hintMaxLines,
),
Expand Down
42 changes: 42 additions & 0 deletions packages/flutter/test/material/text_field_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1875,6 +1875,48 @@ void main() {
expect(find.text('Paste'), findsOneWidget);
}, skip: isContextMenuProvidedByPlatform); // [intended] only applies to platforms where we supply the context menu.

testWidgets('infinite multi-line text hint text is not ellipsized by default', (WidgetTester tester) async {
const String kLongString =
'Enter your email Enter your email Enter your '
'email Enter your email Enter your email Enter '
'your email Enter your email';
const double defaultLineHeight = 24;
await tester.pumpWidget(overlay(
child: const TextField(
maxLines: null,
decoration: InputDecoration(
labelText: 'Email',
hintText: kLongString,
),
),
));
final Text hintText = tester.widget<Text>(find.text(kLongString));
expect(hintText.overflow, isNull);
final RenderParagraph paragraph = tester.renderObject<RenderParagraph>(find.text(kLongString));
expect(paragraph.size.height > defaultLineHeight * 2, isTrue);
});

testWidgets('non-infinite multi-line hint text is ellipsized by default', (WidgetTester tester) async {
const String kLongString =
'Enter your email Enter your email Enter your '
'email Enter your email Enter your email Enter '
'your email Enter your email';
const double defaultLineHeight = 24;
await tester.pumpWidget(overlay(
child: const TextField(
maxLines: 2,
decoration: InputDecoration(
labelText: 'Email',
hintText: kLongString,
),
),
));
final Text hintText = tester.widget<Text>(find.text(kLongString));
expect(hintText.overflow, TextOverflow.ellipsis);
final RenderParagraph paragraph = tester.renderObject<RenderParagraph>(find.text(kLongString));
expect(paragraph.size.height < defaultLineHeight * 2 + precisionErrorTolerance, isTrue);
});

testWidgets('Entering text hides selection handle caret', (WidgetTester tester) async {
final TextEditingController controller = _textEditingController();

Expand Down

0 comments on commit 6ec1c75

Please sign in to comment.