user12941933
user12941933

Reputation:

How to cover SwiftUI Picker with a proper accessibility modifiers

I have a SwiftUI Picker:

Picker(selection: self.$selectedIndex, label: Text("")) {
    Text("△").font(.system(size: 20)).tag(0)
    Text("□").font(.system(size: 20)).tag(1)
    Text("○").font(.system(size: 20)).tag(2)
}.pickerStyle(SegmentedPickerStyle())

Want to make it accessible for VoiceOver. Tried to do the following:

Picker(selection: self.$selectedIndex, label: Text("")) {
    Text("△").font(.system(size: 20)).tag(0).accessibility(label: Text("Triangle label"))
    Text("□").font(.system(size: 20)).tag(1).accessibility(label: Text("Square label"))
    Text("○").font(.system(size: 20)).tag(2).accessibility(label: Text("Circle label"))
}.pickerStyle(SegmentedPickerStyle())

Accessibility inspector shows label="△" but I expect it should show label="Triangle label".

Please help to find out the proper solution.

Upvotes: 3

Views: 1332

Answers (1)

Timothy Sanders
Timothy Sanders

Reputation: 316

I have a similar problem, I filed it with Apple as FB8806682. I noticed two interesting factors, at least on iOS 14.

  1. This only happens when using the SegmentedPickerStyle(). A default picker will correctly read the provided labels.

  2. If you activate any control on the screen (including the picker itself!) then the segmented picker will start reading the proper labels.

As part of the Feedback Assistant entry I created a sample app that shows the two pickers and demonstrates the difference. It's available on GitHub as well.

Upvotes: 1

Related Questions