Skip to content

fix(android): make EditText accessible with display: contents#6

Merged
janicduplessis merged 1 commit intomainfrom
@janic/android-display-contents-accessibility
Apr 27, 2026
Merged

fix(android): make EditText accessible with display: contents#6
janicduplessis merged 1 commit intomainfrom
@janic/android-display-contents-accessibility

Conversation

@janicduplessis
Copy link
Copy Markdown
Contributor

@janicduplessis janicduplessis commented Apr 25, 2026

Description

The decorator view uses style={{ display: 'contents' }} so it doesn't take layout space. On Android Fabric this caused the inner EditText to be missing from the accessibility tree entirely. The visible symptom: keyboardType=\"number-pad\" and \"phone-pad\" inputs silently rejected every keystroke (the IME has nothing to commit text into). Default keyboard inputs happened to work because they go through a different commit path, which is why this stayed hidden.

Reproduced with agent-device on a fresh build of the example app: only the manually-added plain RN <TextInput> showed up in the AX tree as [text-field]. Every TransformerTextInput-wrapped input was missing the EditText node — the entire input slot was empty in the AX tree.

Solution

The shadow node already removed the ForceFlattenView trait so RN creates a host view despite display: contents. What was missing was propagating the child's Yoga-computed metrics to the now-non-flat decorator. Override layout() in the C++ shadow node to copy the child's metrics onto the decorator and zero out the child's origin (which is now relative to the decorator). Mirrors react-native-live-markdown's approach for the same setup.

After the fix, all four EditText nodes show up in the AX tree and number-pad/phone-pad typing works.

Test plan

  • Gradle rebuild Android (native code changed).
  • In the example app, focus Phone Number, Credit Card, and Date cards (all use number/phone pad). Type a digit on the soft keyboard. Confirm the digit appears (was rejected before).
  • Confirm regular keyboard inputs (Username) still work.

The decorator view uses style={{ display: 'contents' }} so it doesn't
take layout space, but on Android Fabric this caused the inner EditText
to be missing from the accessibility tree. Number-pad/phone-pad inputs
silently rejected all keystrokes (the IME has nothing to commit text
into). Default keyboard inputs happened to work because they go through
a different commit path.

The shadow node already removed the ForceFlattenView trait so a host
view is created, but the child's Yoga-computed metrics weren't being
propagated to the now-non-flat decorator. Override layout() to copy
the child's metrics onto the decorator and zero out the child's origin
(now relative to the decorator). Mirrors react-native-live-markdown's
approach for the same setup.
@janicduplessis janicduplessis merged commit a5bb4ef into main Apr 27, 2026
5 checks passed
@janicduplessis janicduplessis deleted the @janic/android-display-contents-accessibility branch April 27, 2026 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant