Skip to content

Commit d438f09

Browse files
Material Design Teamkendrickumstattd
authored andcommitted
[TextField][A11y] Replace deprecated announceForAccessibility with accessibility live region
PiperOrigin-RevId: 762446288
1 parent c1a432f commit d438f09

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2453,14 +2453,26 @@ public void setPlaceholderText(@Nullable final CharSequence placeholderText) {
24532453
if (placeholderTextView == null) {
24542454
placeholderTextView = new AppCompatTextView(getContext());
24552455
placeholderTextView.setId(R.id.textinput_placeholder);
2456-
placeholderTextView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
2456+
placeholderTextView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES);
2457+
placeholderTextView.setAccessibilityLiveRegion(ViewCompat.ACCESSIBILITY_LIVE_REGION_POLITE);
24572458

24582459
placeholderFadeIn = createPlaceholderFadeTransition();
24592460
placeholderFadeIn.setStartDelay(PLACEHOLDER_START_DELAY);
24602461
placeholderFadeOut = createPlaceholderFadeTransition();
24612462

24622463
setPlaceholderTextAppearance(placeholderTextAppearance);
24632464
setPlaceholderTextColor(placeholderTextColor);
2465+
2466+
ViewCompat.setAccessibilityDelegate(
2467+
placeholderTextView,
2468+
new AccessibilityDelegateCompat() {
2469+
@Override
2470+
public void onInitializeAccessibilityNodeInfo(
2471+
@NonNull View host, @NonNull AccessibilityNodeInfoCompat info) {
2472+
super.onInitializeAccessibilityNodeInfo(host, info);
2473+
info.setVisibleToUser(false);
2474+
}
2475+
});
24642476
}
24652477

24662478
// If placeholder text is null, disable placeholder.
@@ -2531,7 +2543,6 @@ private void showPlaceholderText() {
25312543
TransitionManager.beginDelayedTransition(inputFrame, placeholderFadeIn);
25322544
placeholderTextView.setVisibility(VISIBLE);
25332545
placeholderTextView.bringToFront();
2534-
announceForAccessibility(placeholderText);
25352546
}
25362547
}
25372548

0 commit comments

Comments
 (0)