Add accessibility_trait_for_button rule#3989
Conversation
|
@jpsim @SimplyDanny here's another proposed rule to help catch more accessibility issues in SwiftUI apps! There were some SourceKittenDictionary extensions for parsing SwiftUI modifiers that I copied over from the |
Generated by 🚫 Danger |
Codecov Report
@@ Coverage Diff @@
## master #3989 +/- ##
==========================================
- Coverage 92.53% 92.50% -0.03%
==========================================
Files 446 447 +1
Lines 22493 22613 +120
==========================================
+ Hits 20813 20918 +105
- Misses 1680 1695 +15
📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more |
SimplyDanny
left a comment
There was a problem hiding this comment.
Well done!
There were some SourceKittenDictionary extensions for parsing SwiftUI modifiers that I copied over from the accessibility_label_for_image rule since I was trying to keep the extensions private, but let me know if you think it would be better to move some of these extensions to an internal extension file to centralize them. Appreciate your help reviewing this!
I would definitely like to ask you to move them into a separate extension for reusability.
93495a3 to
5aeccb0
Compare
|
@SimplyDanny I tried to make a more generic way to check for modifiers with a given name and arguments that can hopefully scale for other SwiftUI linter rules. Happy to work through some revisions of it if you see room for improvement! |
|
Sorry for the late response! Could you please rebase your branch? Notice that the protocol |
abfac7d to
82f57b2
Compare
82f57b2 to
f412c85
Compare
Similar to the
accessibility_label_for_imagerule, this rule catches another common mistake developers make in SwiftUI that makes their apps less accessible.The accessibility button and link traits are used to tell assistive technologies that an element is tappable. When an element has one of these traits, VoiceOver will automatically read "button" or "link" after the element's label to let the user know that they can activate it. When using a UIKit
UIButtonor SwiftUIButtonorLink, the button trait is added by default, but when you manually add a tap gesture recognizer to an element, you need to explicitly add the button or link trait. In most cases the button trait should be used, but for buttons that open a URL in an external browser we use the link trait instead. This rule attempts to catch uses of the SwiftUI.onTapGesturemodifier where the.isButtonor.isLinktrait is not explicitly applied.Per @rwapp, Android will automatically add the button trait when a tap gesture is applied, but until iOS catches up with that I hope for this rule to help remind more people to add the proper accessibility traits!