Skip to content

Commit dce4419

Browse files
leticiarossiveganafro
authored andcommitted
[TextInputLayout][a11y] Fixed text field's focused rect wrong behavior when using a11y magnification.
Before, in requestRectangleOnScreen we were setting the text input layout’s rectangle to a specific and constant position, which caused the zoomed in screen to be fixed to the left instead of following the input text as it was typed. We should use the edit text’s rectangle’s position first, then adjust for the text field’s height (which includes the helper/error text), then use that updated rectangle on the super call of the method. PiperOrigin-RevId: 435402032
1 parent 6cdf7b5 commit dce4419

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

lib/java/com/google/android/material/textfield/TextInputEditText.java

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -152,45 +152,42 @@ public boolean isTextInputLayoutFocusedRectEnabled() {
152152
return textInputLayoutFocusedRectEnabled;
153153
}
154154

155+
private boolean shouldUseTextInputLayoutFocusedRect(@Nullable TextInputLayout textInputLayout) {
156+
return textInputLayout != null && textInputLayoutFocusedRectEnabled;
157+
}
158+
155159
@Override
156160
public void getFocusedRect(@Nullable Rect r) {
157161
super.getFocusedRect(r);
158162
TextInputLayout textInputLayout = getTextInputLayout();
159-
if (textInputLayout != null
160-
&& textInputLayoutFocusedRectEnabled
161-
&& r != null) {
163+
if (shouldUseTextInputLayoutFocusedRect(textInputLayout) && r != null) {
162164
textInputLayout.getFocusedRect(parentRect);
163165
r.bottom = parentRect.bottom;
164166
}
165167
}
166168

167169
@Override
168170
public boolean getGlobalVisibleRect(@Nullable Rect r, @Nullable Point globalOffset) {
169-
boolean result = super.getGlobalVisibleRect(r, globalOffset);
170171
TextInputLayout textInputLayout = getTextInputLayout();
171-
if (textInputLayout != null
172-
&& textInputLayoutFocusedRectEnabled
173-
&& r != null) {
174-
textInputLayout.getGlobalVisibleRect(parentRect, globalOffset);
175-
r.bottom = parentRect.bottom;
176-
}
177-
return result;
172+
return shouldUseTextInputLayoutFocusedRect(textInputLayout)
173+
? textInputLayout.getGlobalVisibleRect(r, globalOffset)
174+
: super.getGlobalVisibleRect(r, globalOffset);
178175
}
179176

180177
@Override
181178
public boolean requestRectangleOnScreen(@Nullable Rect rectangle) {
182-
boolean result = super.requestRectangleOnScreen(rectangle);
183179
TextInputLayout textInputLayout = getTextInputLayout();
184-
if (textInputLayout != null && textInputLayoutFocusedRectEnabled) {
180+
if (shouldUseTextInputLayoutFocusedRect(textInputLayout) && rectangle != null) {
181+
int bottomOffset = textInputLayout.getHeight() - getHeight();
185182
parentRect.set(
186-
0,
187-
textInputLayout.getHeight()
188-
- getResources().getDimensionPixelOffset(R.dimen.mtrl_edittext_rectangle_top_offset),
189-
textInputLayout.getWidth(),
190-
textInputLayout.getHeight());
191-
textInputLayout.requestRectangleOnScreen(parentRect, true);
183+
rectangle.left,
184+
rectangle.top,
185+
rectangle.right,
186+
rectangle.bottom + bottomOffset);
187+
return super.requestRectangleOnScreen(parentRect);
188+
} else {
189+
return super.requestRectangleOnScreen(rectangle);
192190
}
193-
return result;
194191
}
195192

196193
@Override

lib/java/com/google/android/material/textfield/res/values/dimens.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
<dimen name="mtrl_textinput_box_stroke_width_focused">2dp</dimen>
3535
<dimen name="mtrl_textinput_box_label_cutout_padding">4dp</dimen>
3636

37-
<dimen name="mtrl_edittext_rectangle_top_offset">12dp</dimen>
38-
3937
<!-- Dimens for edit text's top and bottom padding adjustments for large font scale settings. -->
4038
<dimen name="material_filled_edittext_font_1_3_padding_top">23dp</dimen>
4139
<dimen name="material_filled_edittext_font_1_3_padding_bottom">12dp</dimen>

0 commit comments

Comments
 (0)