Skip to content

[material_ui] Hit test the floating label of InputDecorator at its painted position - #13326

Merged
auto-submit[bot] merged 1 commit into
flutter:mainfrom
YeungKC:material-ui-label-hit-test
Nov 5, 2026
Merged

auto-submit[bot] merged 1 commit into
flutter:mainfrom
YeungKC:material-ui-label-hit-test

Conversation

@YeungKC

@YeungKC YeungKC commented Oct 19, 2026

Copy link
Copy Markdown
Member

When the label of an InputDecorator floats, _RenderDecoration.paint draws the label with _labelTransform (a translation and a scale of 0.75). applyPaintTransform reports the same transform. But hitTestChildren hit tests the label with only its layout offset. A comment there says "The label must be handled specially since we've transformed it", but the code does not do this. Thus the label is painted in one location and hit tested in a different location:

  • A tap on the visible floating label does not hit the label.
  • A tap below the visible label, inside its unscaled layout box, hits the label.

This is a problem when the label contains an interactive widget, for example a PopupMenuButton, as in the issue. A maintainer said in the issue: "we shouldn't have weird issues with the hit testing here. Flutter should be able to do this" (comment).

This change hit tests the label with the transform from applyPaintTransform when _labelTransform is set. The hit test order of the children does not change. Other children keep the offset-based hit test. There is no API change.

The code in packages/flutter/lib/src/material of flutter/flutter is frozen (see flutter/flutter#188444), so this change is only for material_ui.

Fixes flutter/flutter#145324

Test plan

  • Added Floating label hit test matches its painted position to test/input_decorator_test.dart, for TextDirection.ltr and TextDirection.rtl. The test taps the painted label two times (2 taps expected), then taps 10 px below the painted label, inside its layout box (no new tap expected).
    • Without the fix: both cases fail with Expected: <2> Actual: <0>.
    • With the fix: both cases pass.
  • flutter test test/input_decorator_test.dart (+555, all passed)
  • flutter test test/text_field_test.dart test/text_form_field_test.dart test/dropdown_menu_test.dart (all passed)
  • flutter analyze lib/src/input_decorator.dart test/input_decorator_test.dart (no issues)
  • dart format --output=none --set-exit-if-changed lib/src/input_decorator.dart test/input_decorator_test.dart (0 changed)

Pre-Review Checklist

The change uses the repository's pending changelog workflow (packages/material_ui/pending_changelogs/change_2026_10_20_floating_label_hit_test.yaml, version: patch). No public API documentation change is necessary.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2

@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Oct 19, 2026
@github-actions github-actions Bot added p: material_ui triage-design Should be looked at in design triage labels Oct 19, 2026

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request updates the hit testing behavior of InputDecorator for floating labels in packages/material_ui/lib/src/input_decorator.dart. When _labelTransform is not null, the paint transform is applied to the label child during hit testing, ensuring that taps target the label at its painted position. Additionally, a regression test has been added to packages/material_ui/test/input_decorator_test.dart to verify this behavior across different text directions, and a pending changelog entry has been created. There are no review comments, and I have no feedback to provide.

@QuncCccccc QuncCccccc 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.

@QuncCccccc
QuncCccccc force-pushed the material-ui-label-hit-test branch from 225fa37 to d238ac1 Compare November 5, 2026 20:08
@QuncCccccc QuncCccccc added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 5, 2026
@auto-submit
auto-submit Bot merged commit 5b5c3b9 into flutter:main Nov 5, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD p: material_ui triage-design Should be looked at in design triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PopupMenuButton click area is wrong when placed in an InputDecoration

2 participants