0

I'm writing a my first Swift app and want to use the convenient DisclosureGroups provided by SwiftUI. However I'm using the onTapGesture for the label to take me to another view and relegating the expand/collapse toggling to a button. While running VoiceOver for it though I noticed that all elements in the Disclosure Group label have their accessibility labels appended with "Double-Tap to Expand/Collapse" (depending on the isExpanded property). With my use case this is not true and would like to remove this additional line.

However I cannot find away to do this. Even setting up a simple dummy app and using any and every combination of the the. accessibility modifiers (hint, removeTraits, label, Element) results in the line still being included. The only way Ive gotten it to stop is .accessibilityHidden, but that shuts down even being able to focus on anything in the label with VoiceOver so that's a non starter.

import SwiftUI

struct ContentsView: View{
 var body: some View {
  DisclosureGroup( content: {Text("Content, does not have extra reading")},
   label: { Text("Label, can't get rid of extra reading")}
  )
 }
}

Is there ANY way to disable this default string? Or is this just a case of me trying to use it for something that it's not and I'm better off writing my own DisclosureGroup?

6
  • Have you tried overriding the accessibility label for the disclosure group with one you compose yourself? Commented Nov 15, 2024 at 19:26
  • Yes. I've tried .accessibilityLabel(Text("My text")) with my own text and as mentioned, it just appends the "Double-tap to collapse/expand" to the end. Same if I use .accessibilityHint(Text("")) or any of the other .accessibility modifiers. Commented Nov 15, 2024 at 20:06
  • In my experience SwiftUI's a11y (accessibility) support is still spotty. Some things are just about impossible. I'm thinking for your case the only way to go would be to put the View (DisclosureGroup) for who's View you want custom a11y inside another View, and give that View totally custom a11y properties (as well as custom gesture recognizers and animations if needed.) Commented Nov 16, 2024 at 0:42
  • (Other than building your own custom discosure group object from scratch.) Commented Nov 16, 2024 at 0:43
  • "Double-Tap to Expand/Collapse" is a hint, but it look you tried to override it yourself already. So the only way I can think of is by using the .accessibilityElement(children: .ignore) modifier with the ignore Accessibility Child Behavior, and then configure your own label, value, traits, etc. But at this point, and without fully knowing your use-case, I agree that it might be just easier to build your own component from scratch. Commented Nov 16, 2024 at 15:13

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.