Skip to content

Incorrect accessibilityRole on Switch component #26873

Closed
@lewie9021

Description

@lewie9021

It appears the Switch component in iOS has an accessibilityRole prop of "button" instead of "switch". This became apparent when testing with Appium.

import React from "react";
import { Switch } from "react-native";

function SwitchExample() {
  return (
    <Switch
      testID="switch"
      value={true}
    />
  );
}

Screenshot 2019-10-16 at 08 05 17

React Native version:

System:
    OS: macOS Mojave 10.14.6
    CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
    Memory: 118.87 MB / 16.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 10.13.0 - ~/.nvm/versions/node/v10.13.0/bin/node
    Yarn: 1.19.1 - ~/.yarn/bin/yarn
    npm: 6.10.1 - ~/.nvm/versions/node/v10.13.0/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 12.4, macOS 10.14, tvOS 12.4, watchOS 5.3
    Android SDK:
      API Levels: 25, 26, 27, 28
      Build Tools: 27.0.3, 28.0.3
      System Images: android-27 | Intel x86 Atom_64, android-27 | Google Play Intel x86 Atom, android-28 | Google APIs Intel x86 Atom
  IDEs:
    Android Studio: 3.2 AI-181.5540.7.32.5056338
    Xcode: 10.3/10G8 - /usr/bin/xcodebuild
  npmPackages:
    react: 16.8.1 => 16.8.1 
    react-native: 0.61.2 => 0.61.2

Steps To Reproduce

  1. Run the example above.
  2. Notice the wrong type (XCUIElementTypeButton) in Appium Desktop
  3. Override accessibilityRole with "switch".
  4. Notice the type is now correct (XCUIElementTypeSwitch) in Appium Desktop.

Below is a screenshot of the expected result:
Screenshot 2019-10-16 at 08 06 05

I did some investigation myself and it looks like this line and this line are the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugComponent: SwitchStaleThere has been a lack of activity on this issue and it may be closed soon.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions