Day 73

isAccessibilityElement vs accessibilityElementsHidden

30 Jul 2022

What is the difference between isAccessibilityElement and accessibilityElementsHidden? The first one makes the view not accessible, but its subviews can still be accessible. The second one hides the view and all its subviews from assistive tech.

There is a view containing 4 subviews. Three examples. In the three of them, all the subviews (that we'll refer to as 1, 2, 3 and 4) have the isAccessibilityElement property set to true. In the first example, the superview (that we'll refer to as A) also has the isAccessibilityElement property to true. That means that A is accessible, but 1, 2, 3 and 4 aren't. In the second example A has the isAccessibilityElement property set to false. That means that A isn't accessible, but 1, 2, 3 and 4 are accessible. In the third example, A has isAccessibilityElement to false and accessibilityElementsHidden to true. That means that A, 1, 2, 3 and 4 will not be accessible.

Some of you have asked me how you can support what I do. This would really help, and would be hugely appreciated:

  • Find these posts useful? Share them at work, on social media, or with anyone that might find them interesting. Let's spread the word!

  • Check out any of my apps or games: Xarra!, RetroRapid!, or Mestre!.

    • A download and a review go a long way. They're free by default. On the App Store, ratings and reviews really help more people discover them.

    • Finding any of them useful? If so, and if you can afford it, purchasing lifetime access to all features or subscribing lets me buy the coffee that keeps me caffeinated. Caffeine keeps me going to maintain the apps, bring in new features that I hope you'll love, and keep writing.

You may also find interesting...

If you need for a view (and all its subviews) not to be focusable by assistive tech like VoiceOver, you can set its accessibilityElementsHidden property to true. This isn't needed very often, but it can be useful for certain custom experiences.

When making charts accessible, sometimes you may have just too many data points for the user to have to go one by one through all of them. In those cases, you can create accessibility elements that represent meaningful chunks of the graph.

It is possible to change the traversing order of accessibility elements by configuring the accessibilityElements array. You should try to avoid it, but one good reason for doing it is if the default order is illogical because of the visual layout.


Content © Daniel Devesa Derksen-Staats on Accessibility up to 11! is licensed under CC BY 4.0. License details