Is there a way to apply accessibility identifier to an alert action button ? #2954
Replies: 2 comments
-
Hi @kristiyandobrev, can you confirm that even vanilla SwiftUI supports accessibility identifiers in buttons of alerts? There is a good chance that it does not. The complicated thing with let _: Text = Text("").accessibilityIdentifier("") // ❌
let _: Text = Text("").accessibilityLabel("") // ✅ So if vanilla SwiftUI does support accessibility identifiers in alert buttons, then in order for us to support it we would need to turn to some type erasure. It probably wouldn't be a huge deal though. But also at the end of the day you can always forgo |
Beta Was this translation helpful? Give feedback.
-
Hi @mbrandonw Thanks for the response ! It does seem like vanilla SwiftUI supports accessibility identifiers in buttons of alerts. As suggested we forwent the .alert(
Text("Title"),
isPresented: $store.showCancelAlert
) {
Button(role: .none) {
send(.confirmCancelButtonTapped)
} label: {
Text("Yes")
}
.accessibilityIdentifier("id1")
Button(role: .cancel) {} label: {
Text("No")
}
.accessibilityIdentifier("id2")
} message: {
Text("Subtitle")
} We can also verify the identifiers with the Accessibility Inspector tool. Definitely preferring the |
Beta Was this translation helpful? Give feedback.
-
Currently, our reducers utilize
AlertState
to manage alerts within our application. However, we've encountered a requirement to attach accessibility identifiers to the TextState within button actions. While we've noted the possibility of attaching anaccessibilityLabel
, we haven't found any mention of anaccessibilityIdentifier
.I'm curious if there's a method I might have overlooked or if there's an actual approach for achieving this. Any insights would be greatly appreciated! 🤔
Beta Was this translation helpful? Give feedback.
All reactions