Skip to content

Commit 6bc058d

Browse files
ludovic35pylapp
andauthored
fix: accessibility label to vocalize the icon style style of button component (#460) (#483)
Closes #460 Co-authored-by: Pierre-Yves Lapersonne <[email protected]> Co-authored-by: Ludovic Pinel <[email protected]> Signed-off-by: Pierre-Yves Lapersonne <[email protected]>
1 parent 93172ed commit 6bc058d

File tree

6 files changed

+60
-11
lines changed

6 files changed

+60
-11
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2727

2828
### Fixed
2929

30+
- [Library] Add accessibility label to vocalize the IconOnly button style ([#460](https://github.com/Orange-OpenSource/ouds-ios/issues/460))
3031
- [Library] Chevron for link component pointing to bad direction in RTL mode ([#557](https://github.com/Orange-OpenSource/ouds-ios/issues/557))
3132
- [Library] Remove divider if outline effect is active in RadioItem component ([#564](https://github.com/Orange-OpenSource/ouds-ios/issues/564))
3233
- [DesignToolbox] In RTL mode code sample text not aligned on the left ([#554](https://github.com/Orange-OpenSource/ouds-ios/issues/554))

DesignToolbox/DesignToolbox.xcworkspace/xcshareddata/swiftpm/Package.resolved

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
"kind" : "remoteSourceControl",
4343
"location" : "https://github.com/pointfreeco/xctest-dynamic-overlay",
4444
"state" : {
45-
"revision" : "b444594f79844b0d6d76d70fbfb3f7f71728f938",
46-
"version" : "1.5.1"
45+
"revision" : "39de59b2d47f7ef3ca88a039dff3084688fe27f4",
46+
"version" : "1.5.2"
4747
}
4848
}
4949
],

DesignToolbox/DesignToolbox/Pages/Components/Button/ButtonPage.swift

+11-3
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,19 @@ private struct ButtonDemo: View {
8383
} else {
8484
switch model.layout {
8585
case .iconOnly:
86-
OUDSButton(icon: Image(decorative: "ic_heart"), hierarchy: model.hierarchy, style: model.style) {}
86+
OUDSButton(icon: Image(decorative: "ic_heart"),
87+
accessibilityLabel: "app_components_button_icon_a11y".localized(),
88+
hierarchy: model.hierarchy,
89+
style: model.style) {}
8790
case .textOnly:
88-
OUDSButton(text: model.text, hierarchy: model.hierarchy, style: model.style) {}
91+
OUDSButton(text: model.text,
92+
hierarchy: model.hierarchy,
93+
style: model.style) {}
8994
case .iconAndText:
90-
OUDSButton(icon: Image(decorative: "ic_heart"), text: model.text, hierarchy: model.hierarchy, style: model.style) {}
95+
OUDSButton(icon: Image(decorative: "ic_heart"),
96+
text: model.text,
97+
hierarchy: model.hierarchy,
98+
style: model.style) {}
9199
}
92100
}
93101

DesignToolbox/DesignToolboxSnapshotsTests/__Snapshots__/Components/OUDSButtonUITests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ private struct ButtonTest: View {
181181
case .textAndIcon:
182182
OUDSButton(icon: Image(decorative: "ic_heart"), text: "Button", hierarchy: hierarchy, style: style) {}
183183
case .icon:
184-
OUDSButton(icon: Image(decorative: "ic_heart"), hierarchy: hierarchy, style: style) {}
184+
OUDSButton(icon: Image(decorative: "ic_heart"), accessibilityLabel: "Icon", hierarchy: hierarchy, style: style) {}
185185
}
186186
}
187187
}

OUDS/Core/Components/Sources/Buttons/OUDSButton.swift

+20-4
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public struct OUDSButton: View {
7777

7878
private enum `Type` {
7979
case text(String)
80-
case icon(Image)
80+
case icon(Image, String)
8181
case textAndIcon(text: String, icon: Image)
8282
}
8383

@@ -123,11 +123,12 @@ public struct OUDSButton: View {
123123
///
124124
/// - Parameters:
125125
/// - icon: An image which shoud contains an icon
126+
/// - accessibilityLabel: The text to vocalize with *Voice Over* describing the button action
126127
/// - hierarchy: The button hierarchy
127128
/// - style: The button style
128129
/// - 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)
131132
self.hierarchy = hierarchy
132133
self.style = style
133134
self.action = action
@@ -158,7 +159,7 @@ public struct OUDSButton: View {
158159

159160
Button(action: action) {
160161
switch type {
161-
case let .icon(icon):
162+
case let .icon(icon, _):
162163
ButtonIcon(icon: icon)
163164
case let .text(text):
164165
ButtonText(text: text)
@@ -167,6 +168,21 @@ public struct OUDSButton: View {
167168
}
168169
}
169170
.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+
}
170186
}
171187
}
172188

OUDS/Core/Components/Sources/Resources/Localizable.xcstrings

+25-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,30 @@
44
"" : {
55
"shouldTranslate" : false
66
},
7+
"core_button_loading_a11y" : {
8+
"comment" : "Button",
9+
"extractionState" : "manual",
10+
"localizations" : {
11+
"ar" : {
12+
"stringUnit" : {
13+
"state" : "translated",
14+
"value" : "تحميل"
15+
}
16+
},
17+
"en" : {
18+
"stringUnit" : {
19+
"state" : "translated",
20+
"value" : "Loading"
21+
}
22+
},
23+
"fr" : {
24+
"stringUnit" : {
25+
"state" : "translated",
26+
"value" : "Chargement"
27+
}
28+
}
29+
}
30+
},
731
"core_checkbox_checked_a11y" : {
832
"comment" : "Checkbox",
933
"extractionState" : "manual",
@@ -239,7 +263,7 @@
239263
"fr" : {
240264
"stringUnit" : {
241265
"state" : "translated",
242-
"value" : "Non sélectionné"
266+
"value" : "Undéterminé"
243267
}
244268
}
245269
}

0 commit comments

Comments
 (0)