Repository navigation
Commit 5b5c3b9
authored
[material_ui] Hit test the floating label of InputDecorator at its painted position (flutter#13326)
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](flutter/flutter#145324 (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.
## 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.
[^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.1 parent f631bb8 commit 5b5c3b9
3 files changed
Lines changed: 53 additions & 0 deletions
File tree
- packages/material_ui
- lib/src
- pending_changelogs
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1728 | 1728 | | |
1729 | 1729 | | |
1730 | 1730 | | |
| 1731 | + | |
| 1732 | + | |
| 1733 | + | |
| 1734 | + | |
| 1735 | + | |
| 1736 | + | |
| 1737 | + | |
| 1738 | + | |
| 1739 | + | |
| 1740 | + | |
| 1741 | + | |
| 1742 | + | |
| 1743 | + | |
| 1744 | + | |
1731 | 1745 | | |
1732 | 1746 | | |
1733 | 1747 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16208 | 16208 | | |
16209 | 16209 | | |
16210 | 16210 | | |
| 16211 | + | |
| 16212 | + | |
| 16213 | + | |
| 16214 | + | |
| 16215 | + | |
| 16216 | + | |
| 16217 | + | |
| 16218 | + | |
| 16219 | + | |
| 16220 | + | |
| 16221 | + | |
| 16222 | + | |
| 16223 | + | |
| 16224 | + | |
| 16225 | + | |
| 16226 | + | |
| 16227 | + | |
| 16228 | + | |
| 16229 | + | |
| 16230 | + | |
| 16231 | + | |
| 16232 | + | |
| 16233 | + | |
| 16234 | + | |
| 16235 | + | |
| 16236 | + | |
| 16237 | + | |
| 16238 | + | |
| 16239 | + | |
| 16240 | + | |
| 16241 | + | |
| 16242 | + | |
| 16243 | + | |
| 16244 | + | |
| 16245 | + | |
| 16246 | + | |
16211 | 16247 | | |
0 commit comments