Unverified Commit b9af6551 authored by Justin McCandless's avatar Justin McCandless Committed by GitHub

Label unnecessarily ellided (#59807)

parent 65b19560
......@@ -986,9 +986,15 @@ class _RenderDecoration extends RenderBox {
+ contentPadding.right));
// Increase the available width for the label when it is scaled down.
final double invertedLabelScale = lerpDouble(1.00, 1 / _kFinalLabelScale, decoration.floatingLabelProgress);
final double labelWidth = math.max(0.0, constraints.maxWidth - (
_boxSize(icon).width
+ contentPadding.left
+ _boxSize(prefixIcon).width
+ _boxSize(suffixIcon).width
+ contentPadding.right));
boxToBaseline[label] = _layoutLineBox(
label,
boxConstraints.copyWith(maxWidth: inputWidth * invertedLabelScale),
boxConstraints.copyWith(maxWidth: labelWidth * invertedLabelScale),
);
boxToBaseline[hint] = _layoutLineBox(
hint,
......
......@@ -4158,4 +4158,64 @@ void main() {
expect(tester.getTopLeft(find.text(hintText)).dy, topPosition);
});
testWidgets("InputDecorator label width isn't affected by prefix or suffix", (WidgetTester tester) async {
const String labelText = 'My Label';
const String prefixText = 'The five boxing wizards jump quickly.';
const String suffixText = 'Suffix';
Widget getLabeledInputDecorator(bool showFix) {
return MaterialApp(
home: Material(
child: Builder(
builder: (BuildContext context) {
return Theme(
data: Theme.of(context),
child: Align(
alignment: Alignment.topLeft,
child: TextField(
decoration: InputDecoration(
icon: const Icon(Icons.assistant),
prefixText: showFix ? prefixText : null,
suffixText: showFix ? suffixText : null,
suffixIcon: const Icon(Icons.threesixty),
labelText: labelText,
),
),
),
);
},
),
),
);
}
// Build with no prefix or suffix.
await tester.pumpWidget(getLabeledInputDecorator(false));
// Get the width of the label when there is no prefix/suffix.
expect(find.text(prefixText), findsNothing);
expect(find.text(suffixText), findsNothing);
final double labelWidth = tester.getSize(find.text(labelText)).width;
// Build with a prefix and suffix.
await tester.pumpWidget(getLabeledInputDecorator(true));
// The prefix and suffix exist but aren't visible. They have not affected
// the width of the label.
expect(find.text(prefixText), findsOneWidget);
expect(getOpacity(tester, prefixText), 0.0);
expect(find.text(suffixText), findsOneWidget);
expect(getOpacity(tester, suffixText), 0.0);
expect(tester.getSize(find.text(labelText)).width, labelWidth);
// Tap to focus.
await tester.tap(find.byType(TextField));
await tester.pumpAndSettle();
// The prefix and suffix are visible, and the label is floating and still
// hasn't had its width affected.
expect(tester.getSize(find.text(labelText)).width, labelWidth);
expect(getOpacity(tester, prefixText), 1.0);
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment