Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set accessibilityLabel on UIMenuItem

I am trying to set the accessibilityLabel of a UIMenuItem and it seems to have no effect. VoiceOver simply reads the title of the item no matter what:

    let foo = UIMenuItem(title: "foo", action: #selector(doSomething))
    item.isAccessibilityElement = true
    item.accessibilityLabel = "bar"

For this item, VoiceOver reads "foo" instead of "bar." Also, the accessibilityHint seems to be ignored as well.

like image 206
Jon Brooks Avatar asked Oct 30 '22 00:10

Jon Brooks


1 Answers

The UIMenuItem element is actually a UICalloutBarButton private class containing a UIButtonLabel (iOS 13) and, as is, you can't custom its a11y properties even if you can easily code it (informal protocol).
That's insane because, in order to vend an a11y app, you MUST adapt it to the users and that's definitely not the case here.😨

However, a workaround may be implemented as follows to reach your goal:

  • Render the menu controller inaccessible (a11yTraits = .none).
  • Get the menu controller frame (menuFrame property) for the next step.
  • Create an accessible element that wraps the menu when displayed (UIAccessibilityElement init + accessibilityFrameInContainerSpace).
  • For this new accessible element, create a11y custom actions that match each element of the [menuItems] ⟹ here you can provide the VoiceOver label.🤯

It would have been better to create an accessible element for each menuItem (and then provide a better customization) but I didn't find out the way to get the frame of each individual item. 😥

And, unfortunately, this problem is still current for the last 3 years. 😤

⚠️ ⬛️◼️🔳▪️ EDIT ▪️🔳◼️⬛️ ⚠️ (2020/03/19)

I wrote a Developer Technical Support Incident (no 731229763) for this problem and here's the answer from Apple:

Our engineers have reviewed your request and have determined that you are experiencing a known issue for which there is no known workaround at this time.

I submitted a bug report entitled VoiceOver: accessibilityLabel can't be implemented on a UIMenuItem element with the reference FB7623526.

Now, you know why accessibilityLabel is useless and without effects on a UIMenuItem element. 😥

like image 172
XLE_22 Avatar answered Nov 15 '22 06:11

XLE_22