fix(ios): report the focused input an accessible container hides

DV
13d ago
+359-9

Summary

In a React Native app whose TextInput sits inside a Pressable, the Pressable is one accessibility element. While the input shows (focused or filled), the AX server lists only the container's identified wrappers and reports the container as the app's responder. The XCTest tree, queries, and the Simulator AX bridge all miss the input: snapshot omits the focused field and focused=true matches nothing.

With no focused node, the runner now reads the responder element, hit-tests up to 8 points inside it, and grafts the element holding keyboard focus under it with its own type and identifier. The bridge refuses a tree with a docked keyboard and no focused node (keyboard-focus-outside-tree, capture-scoped), so the runner serves that capture.

Not covered:

  • An unfocused filled input stays absent.
  • fill on such an input still fails; bare type works.
  • With a hardware keyboard, the bridge does not refuse.
  • A UIKit fixture (accessible UIView around a UITextField) keeps the input in the tree, so no XCTest exercises the recovery.

Reproduction (React Native 0.83, iOS 26.3 simulator):

import { useRef } from 'react';
import { Pressable, Text, TextInput, View } from 'react-native';

export default function App() {
  const input = useRef<TextInput>(null);
  return (
    <View style={{ padding: 24, paddingTop: 120 }}>
      <Pressable testID="password-field" onPress={() => input.current?.focus()}>
        <View testID="password-field-row">
          <Text>Password</Text>
          <View testID="password-field-input-row">
            <TextInput ref={input} testID="password-field-input" secureTextEntry autoFocus />
          </View>
        </View>
      </Pressable>
    </View>
  );
}
agent-device open <bundle-id> --platform ios
agent-device snapshot -i
agent-device get attrs 'focused=true'

Before / after

Observed in an app with this structure; identifiers renamed.

# base 098c1780b
$ agent-device snapshot -i
@e6 [other] "Password"
@e11 [other] "password-field-input-row"
$ agent-device get attrs 'focused=true'
Error (COMMAND_FAILED): Selector did not match: focused=true.

# head
$ agent-device snapshot -i
@e48 [other] "Password"
@e49 [securetextfield] "password-field-input" [focused]
Warning: Simulator AX snapshot unavailable (keyboard-focus-outside-tree); used XCTest for this capture, while the focused input was outside the bridge tree.
$ agent-device get attrs 'focused=true'
"type": "SecureTextField", "identifier": "password-field-input", "focused": true, "password": true

Validation

  • pnpm check:affected --run --head: all local gates passed except one unit test (daemon-process-takeover.test.ts), which also fails at base on the test Mac; xctest-selection, packaged-runner-swift, and test:integration:provider then passed.
  • 27 snapshot runner XCTests passed on iOS 26.3.
  • iOS and macOS runners compiled; tvOS, visionOS, and watchOS were not installed.
  • Risk: the reproduction was not built itself.

Prove it works
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.