Sitelet https://github.com/flutter/flutter/pull/55911
Skip to content

Text field height fix - #55911

Merged
fluttergithubbot merged 14 commits into
flutter:masterfrom
justinmc:text-field-minimum-height
May 7, 2020
Merged

fluttergithubbot merged 14 commits into
flutter:masterfrom
justinmc:text-field-minimum-height

Conversation

@justinmc

@justinmc justinmc commented Apr 28, 2020 •

Copy link
Copy Markdown
Contributor

Description

A regression was introduced in #42449 where inputs with InputDecoration.collapsed were forced to have a height of at least kMinInteractiveDimension. There was also a lot of confusion around collapsed, isDense, and contentPadding, as explained well in this issue comment. This PR fixes the regression and deals with the confusion by respecting contentPadding whenever it is passed in, regardless of whether isDense or collapsed were used. I've simplified the solution to simply allow small heights when isCollapsed is true due to breakages with the original solution.

Related Issues

Closes #46160

Tests

  • I updated a few expectations of minimum height for a collapsed field.
  • I added a test to show that contentPadding is not respected when isDense and isCollapsed are not set.

@justinmc justinmc added a: text input Entering text in a text field or keyboard related problems f: inspector Part of widget inspector in framework. labels Apr 28, 2020
@justinmc justinmc self-assigned this Apr 28, 2020
@fluttergithubbot fluttergithubbot added p: material_ui material_ui package in flutter/packages framework flutter/packages/flutter repository. See also f: labels. labels Apr 28, 2020
@justinmc
justinmc requested a review from HansMuller April 28, 2020 23:04
@justinmc

Copy link
Copy Markdown
Contributor Author

@HansMuller This makes an attempt at improving our problems with collapsed and isDense (while fixing a regression). The idea is to reduce confusion by always respecting contentPadding when it's given and not depending on isDense. I left a comment on the issue that summarizes the background of this problem.

@HansMuller HansMuller left a comment

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.

LGTM

final double minContainerHeight = decoration.isDense || expands
? 0.0
: kMinInteractiveDimension + densityOffset.dy;
final double minContainerHeight = decoration.isDense

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.

This expression and the following one might be a little easier to read if allowed the lines to get a little wider. Doing it this way makes the similarity of these statements easier to see.

final double minContainerHeight =  expands || decoration.isDense || decoration.contentPadding != null
  ? 0.0
  : kMinInteractiveDimension + densityOffset.dy;

? maxContainerHeight
: math.min(math.max(contentHeight, minContainerHeight), maxContainerHeight);

// Ensure the text is vertically centered in cases where the content is

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.

Do we really want to lose this comment?

: const EdgeInsets.fromLTRB(12.0, 24.0, 12.0, 16.0));
}
final double floatingLabelHeight = !decoration.isCollapsed && !border.isOutline
// 4.0: the vertical gap between the inline elements and the floating label.

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.

two space indent

@justinmc
justinmc force-pushed the text-field-minimum-height branch from 202f63f to 93f2a23 Compare May 1, 2020 00:12
@justinmc

justinmc commented May 1, 2020

Copy link
Copy Markdown
Contributor Author

@HansMuller Ready for re-review. I did a much simplified solution by just considering isCollapsed remove the minimum height, as we discussed. It fixes the regression.

I'm checking the internal tests now.

@justinmc

justinmc commented May 1, 2020

Copy link
Copy Markdown
Contributor Author

Seems like this doesn't cause any failures on internal tests.

int errorMaxLines,
bool hasFloatingPlaceholder,
FloatingLabelBehavior floatingLabelBehavior,
bool isCollapsed,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The doc comment is no longer accurate.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for catching that! It makes me worry about people relying on the old behavior, though I think technically it's not a breaking change. I wonder why isCollapsed was not passed through in the first place.

@HansMuller HansMuller left a comment

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.

LGTM

),
);

// Overall height should be 18dps, but the min is kMinInteractiveDimension

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.

The requested overall height is 18dps, however the min height is kMinInteractiveDimension
because neither isDense or isCollapsed are true.

});

testWidgets('contentPadding smaller than kMinInteractiveDimension', (WidgetTester tester) async {
const double verticalPadding = 1.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.

Please insert
// Regression test for #42449

expect(tester.getSize(find.text('text')).height, 16.0);
expect(tester.getTopLeft(find.text('text')).dy, 16.0);
expect(getOpacity(tester, 'hint'), 0.0);
expect(getBorderWeight(tester), 1.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.

For the sake of clarity, it would be nice to include a second part to this test that verifies that the height is 18 when collapsed is true. And a third part, same thing for isDense.

@fluttergithubbot
fluttergithubbot merged commit 8fbfe1c into flutter:master May 7, 2020
@justinmc
justinmc deleted the text-field-minimum-height branch May 7, 2020 16:06
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Jul 31, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

a: text input Entering text in a text field or keyboard related problems f: inspector Part of widget inspector in framework. framework flutter/packages/flutter repository. See also f: labels. p: material_ui material_ui package in flutter/packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TextField decoration InputDecoration.collapsed has extra padding in new flutter versions.

5 participants