@@ -77,7 +77,7 @@ public struct OUDSButton: View {
77
77
78
78
private enum `Type` {
79
79
case text( String )
80
- case icon( Image )
80
+ case icon( Image , String )
81
81
case textAndIcon( text: String , icon: Image )
82
82
}
83
83
@@ -123,11 +123,12 @@ public struct OUDSButton: View {
123
123
///
124
124
/// - Parameters:
125
125
/// - icon: An image which shoud contains an icon
126
+ /// - accessibilityLabel: The text to vocalize with *Voice Over* describing the button action
126
127
/// - hierarchy: The button hierarchy
127
128
/// - style: The button style
128
129
/// - action: The action to perform when the user triggers the button
129
- public init ( icon: Image , hierarchy: Hierarchy , style: Style , action: @escaping ( ) -> Void ) {
130
- self . type = . icon( icon)
130
+ public init ( icon: Image , accessibilityLabel : String , hierarchy: Hierarchy , style: Style , action: @escaping ( ) -> Void ) {
131
+ self . type = . icon( icon, accessibilityLabel )
131
132
self . hierarchy = hierarchy
132
133
self . style = style
133
134
self . action = action
@@ -158,7 +159,7 @@ public struct OUDSButton: View {
158
159
159
160
Button ( action: action) {
160
161
switch type {
161
- case let . icon( icon) :
162
+ case let . icon( icon, _ ) :
162
163
ButtonIcon ( icon: icon)
163
164
case let . text( text) :
164
165
ButtonText ( text: text)
@@ -167,6 +168,21 @@ public struct OUDSButton: View {
167
168
}
168
169
}
169
170
. buttonStyle ( OUDSButtonStyle ( hierarchy: hierarchy, style: style) )
171
+ . accessibilityLabel ( accessibilityLabel)
172
+ }
173
+
174
+ /// Forges a string to vocalize with *Voice Over* describing the button style `loading`
175
+ /// or the text according to the button type. For iconOnly the `accessibilityLabel` is used,
176
+ /// else the button text is used.
177
+ private var accessibilityLabel : String {
178
+ if style == . loading {
179
+ return " core_button_loading_a11y " . localized ( )
180
+ } else {
181
+ switch type {
182
+ case . text( let text) , . textAndIcon( let text, _) , . icon( _, let text) :
183
+ return text
184
+ }
185
+ }
170
186
}
171
187
}
172
188
0 commit comments