Skip to content

Commit

Permalink
MDS Text Input Character Count Accessibility
Browse files Browse the repository at this point in the history
Summary:
### Context
In this diff we are adding the following changes to text input
* If there is no placeholder text then talkback will appent the character count to end of annoucement `Edit Box, 0 of 20 chracters remaining"
* When user double clicks on the input field the character count status will be announced.
* As the user types the remaining characters will be annouced after user stop typing

Differential Revision: D67131474

fbshipit-source-id: 4b0f69d177775c35462bb0501032b866cb8e231f
  • Loading branch information
Jose Garcia authored and facebook-github-bot committed Dec 16, 2024
1 parent 5851a74 commit 74f272d
Showing 1 changed file with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.content.res.ColorStateList;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.text.InputFilter;
import android.text.TextUtils;
import android.text.TextWatcher;
Expand Down Expand Up @@ -119,6 +120,7 @@ class MaterialTextInputSpec {
@PropDefault protected static final int editTextBottomPadding = UNSET;
@PropDefault protected static final int importantForAutofill = 0;
@PropDefault protected static final boolean disableAutofill = false;
@PropDefault protected static final String tooltipText = "";

@OnCreateInitialState
static void onCreateInitialState(
Expand Down Expand Up @@ -182,6 +184,7 @@ static void onMeasure(
@Prop(optional = true) @Nullable String[] autofillHints,
@Prop(optional = true) boolean disableAutofill,
@Prop(optional = true) @Nullable KeyListener keyListener,
@Prop(optional = true) @Nullable String tooltipText,
@State AtomicReference<CharSequence> savedText) {
EditText editText =
TextInputSpec.createAndMeasureEditText(
Expand Down Expand Up @@ -237,7 +240,8 @@ static void onMeasure(
editTextStartPadding,
editTextTopPadding,
editTextEndPadding,
editTextBottomPadding);
editTextBottomPadding,
tooltipText);
textInputLayout.addView(editText);

textInputLayout.measure(
Expand Down Expand Up @@ -285,6 +289,7 @@ static boolean shouldUpdate(
@Prop(optional = true, resType = ResType.DIMEN_OFFSET) Diff<Integer> editTextEndPadding,
@Prop(optional = true, resType = ResType.DIMEN_OFFSET) Diff<Integer> editTextBottomPadding,
@Prop(optional = true) Diff<KeyListener> keyListener,
@Prop(optional = true) Diff<String> tooltipText,
@State Diff<Integer> measureSeqNumber,
@State Diff<AtomicReference<EditTextWithEventHandlers>> mountedEditTextRef,
@State Diff<AtomicReference<CharSequence>> savedText) {
Expand Down Expand Up @@ -331,7 +336,8 @@ static boolean shouldUpdate(
|| !ObjectsCompat.equals(editTextTopPadding.getPrevious(), editTextTopPadding.getNext())
|| !ObjectsCompat.equals(editTextEndPadding.getPrevious(), editTextEndPadding.getNext())
|| !ObjectsCompat.equals(
editTextBottomPadding.getPrevious(), editTextBottomPadding.getNext())) {
editTextBottomPadding.getPrevious(), editTextBottomPadding.getNext())
|| !ObjectsCompat.equals(tooltipText.getPrevious(), tooltipText.getNext())) {
return true;
}

Expand Down Expand Up @@ -390,6 +396,7 @@ static void onMount(
@Prop(optional = true) int importantForAutofill,
@Prop(optional = true) @Nullable String[] autofillHints,
@Prop(optional = true) boolean disableAutofill,
@Prop(optional = true) @Nullable String tooltipText,
@State AtomicReference<CharSequence> savedText,
@State AtomicReference<EditTextWithEventHandlers> mountedEditTextRef) {
EditTextWithEventHandlers editText = (EditTextWithEventHandlers) textInputLayout.getEditText();
Expand Down Expand Up @@ -447,7 +454,8 @@ static void onMount(
editTextStartPadding,
editTextTopPadding,
editTextEndPadding,
editTextBottomPadding);
editTextBottomPadding,
tooltipText);
// NULLSAFE_FIXME[Nullable Dereference]
editText.setTextState(savedText);
// NULLSAFE_FIXME[Nullable Dereference]
Expand All @@ -466,7 +474,8 @@ static void setParams(
int editTextStartPadding,
int editTextTopPadding,
int editTextEndPadding,
int editTextBottomPadding) {
int editTextBottomPadding,
@Nullable String tooltipText) {
textInputLayout.setHint(hint);
textInputLayout.setCounterEnabled(counterEnabled);
textInputLayout.setCounterMaxLength(counterMaxLength);
Expand All @@ -475,6 +484,9 @@ static void setParams(
// vertical center issue
textInputLayout.setBoxBackgroundMode(boxBackgroundMode);
textInputLayout.setBoxStrokeWidth(boxStrokeWidth);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
editText.setTooltipText(tooltipText);
}
if (editTextStartPadding != UNSET
|| editTextTopPadding != UNSET
|| editTextEndPadding != UNSET
Expand Down

0 comments on commit 74f272d

Please sign in to comment.