Repository navigation
Keep a read-only TextInput focusable on Android - #59156
Draft
YevheniiKotyrlo wants to merge 1 commit into
Draft
YevheniiKotyrlo wants to merge 1 commit into
YevheniiKotyrlo wants to merge 1 commit into
Conversation
editable={false} disabled the EditText, so a hardware keyboard's Tab
skipped it, TalkBack announced it as disabled, and its text could not be
selected. Refuse input the way TextView does instead: the input drops
its key listener while it is read-only, which leaves no input method,
hardware key or cut and paste able to edit it and keeps it focusable.
TextView reports TYPE_NULL for such a view and marks every EditText
editable for accessibility, so the multiline, secure-text and input-type
reads use the configured type, and the accessibility delegate drops the
editable flag and ACTION_SET_TEXT while the input is read-only.
Contributor
Author
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.




Summary:
On Android,
editable={false}disables theEditText:ReactTextInputManager.setEditablewrites the prop ontoView.isEnabled. A disabled view takes no focus, so a hardware keyboard's Tab skips a read-only input, TalkBack announces it as disabled, and its text cannot be selected or copied.readOnlyreaches native aseditable={!readOnly}, so it is the same view. On the web areadonlyinput keeps its tab stop, its focus and its selection and refuses only edits.This refuses input the way
TextViewdoes instead:ReactEditTextdrops its key listener while it is read-only. ATextViewwith no key listener is no text editor, so no input method serves it, hardware keys do not edit it and cut and paste leave its selection menu, while its movement method keeps it focusable and selectable. The view stays enabled, andaria-disabled/accessibilityState={{disabled: true}}still disable it throughBaseViewManager.Two
TextViewbehaviours follow from a missing key listener:getInputType()reportsTYPE_NULL, soisMultiline,isSecureTextandcommitStagedInputTyperead the input type the props configured.TextViewmarks everyEditTexteditable for accessibility and performsACTION_SET_TEXTwhatever its key listener, so the input's accessibility delegate clears the flag, removes the action and refuses it while the input is read-only.The soft-keyboard guard checks
isEditableas well, so the paths that focus an input on their own —autoFocus, the accessibility delegate's click and a long-press selection — raise no keyboard for a read-only input.focus()keeps its contract:TextInputState.focusTextInputstill refuses a non-editable input (#30695).Related: #7437, #30597.
Changelog:
[ANDROID] [FIXED] - A
TextInputwitheditable={false}orreadOnlykeeps its focus, its tab stop and its text selectionTest Plan:
ReactTextInputPropertyTest: onmain,testEditable,testNonEditableTakesFocusandtestNonEditableRefusesAccessibilitySetTextfail; with this change the class passes (34 tests). New cases cover refused hardware keys, the refusedACTION_SET_TEXT, and the keyboard type, multiline and secure entry kept across a read-only window../gradlew :packages:react-native:ReactAndroid:testDebugUnitTest -Preact.internal.useHermesStable=truepasses (769 tests), andnode ./scripts/format-kotlin.js --checkis clean.