Skip to content

Commit 2e79ff3

Browse files
authored
refactor: vocalization of badge component depending to its content (#957) (#958)
Signed-off-by: Pierre-Yves Lapersonne <pierreyves.lapersonne@orange.com>
1 parent 04a5969 commit 2e79ff3

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
- Swift package `SwiftLintPlugins` from v0.60.0 to v0.60.1
1212
- Update various GitHub Actions workflows dependencies
1313
- Tuning of themes (like rounded corners) (Orange-OpenSource/ouds-ios#951)
14+
1415
### Fixed
1516

17+
- Vocalisation of badge with icons (Orange-OpenSource/ouds-ios#956)
1618
- Badge component does not have bigger sizes if text sizes is increased (Orange-OpenSource#844)
1719

1820
## [0.18.0](https://github.com/Orange-OpenSource/ouds-ios/compare/0.17.0...0.18.0) - 2025-09-05

OUDS/Core/Components/Sources/Indicators/Badge/Internal/BadgeIcon.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ struct BadgeIcon: View {
3232
.renderingMode(.template)
3333
.aspectRatio(contentMode: .fit)
3434
.padding(.all, theme.badge.badgeSpaceInset)
35+
.accessibilityElement() // Otherwise label cannot be used in OUDSBadge body
3536
}
3637
}
3738

OUDS/Core/Components/Sources/Indicators/Badge/OUDSBadge.swift

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// Software description: A SwiftUI components library with code examples for Orange Unified Design System
1212
//
1313

14+
import OUDSFoundations
1415
import OUDSTokensSemantic
1516
import SwiftUI
1617

@@ -30,15 +31,22 @@ import SwiftUI
3031
/// OUDSBadge(count: 1, status: .negative, size: .large)
3132
///
3233
/// // Info badge in medium size (default size) with icon information
33-
/// OUDSBadge(icon: Image("ic_heart"), status: .info)
34+
/// OUDSBadge(icon: Image("ic_heart"), accessibilityLabel: "Like", status: .info)
3435
/// ```
3536
///
3637
/// ## Accessibility considerations
3738
///
39+
/// ### Sizes
40+
///
3841
/// Users may need to increase their text sizes. However by design their is no tokens for such cases.
3942
/// Thus, if large text is used, a factor is applied on the largest token value based on the size percentage rate.
4043
/// Thus it will make users able to have bigger badges.
4144
///
45+
/// ### Vocalizations
46+
///
47+
/// A badge without content will be ignored instead of a count badge for which its value wil be vocalized.
48+
/// For badge with icon, if the accessibility label is defined (and it should be) it will be vocalized.
49+
///
4250
/// ## Design documentation
4351
///
4452
/// [unified-design-system.orange.com](https://unified-design-system.orange.com/472794e18/p/73c701-components)
@@ -77,6 +85,7 @@ public struct OUDSBadge: View { // TODO: #514 - Add hyperlink for badge document
7785
private let size: StandardSize
7886
private let count: UInt?
7987
private let icon: Image?
88+
private let accessibilityLabel: String?
8089

8190
@Environment(\.theme) private var theme
8291
@Environment(\.sizeCategory) private var sizeCategory: ContentSizeCategory
@@ -148,7 +157,7 @@ public struct OUDSBadge: View { // TODO: #514 - Add hyperlink for badge document
148157

149158
// MARK: Initializers
150159

151-
/// Creates a basic standard neutral badge.
160+
/// Creates a basic badge.
152161
///
153162
/// - Parameters:
154163
/// - status: The status of this badge. The background color of the badge is based on this status, *neutral* by default
@@ -157,6 +166,7 @@ public struct OUDSBadge: View { // TODO: #514 - Add hyperlink for badge document
157166
self.status = status
158167
self.size = size
159168
icon = nil
169+
accessibilityLabel = nil
160170
count = nil
161171
}
162172

@@ -174,26 +184,36 @@ public struct OUDSBadge: View { // TODO: #514 - Add hyperlink for badge document
174184
self.size = size.standardSize
175185
self.count = count
176186
icon = nil
187+
accessibilityLabel = nil
177188
}
178189

179190
/// Creates a badge which displays an icon to visually reinforce meaning.
180191
/// It is used for status indicators (e.g., "New", "Pending", "Success").
181-
/// The size remains unchanged despite the increase in the interface size.
182192
/// The background color of the badge and the icon color are based on the given `status`.
183193
///
184194
/// - Parameters:
185195
/// - icon: The icon displayed in the badge
196+
/// - accessibilityLabel: The accessibility label the badge should have, describing the icon or brining meanings
186197
/// - status: The status of this badge, default set to *neutral*
187198
/// - size: The size of this badge, default set to *medium*
188-
public init(icon: Image, status: Status = .neutral, size: IllustrationSize = .medium) {
199+
public init(icon: Image,
200+
accessibilityLabel: String,
201+
status: Status = .neutral,
202+
size: IllustrationSize = .medium)
203+
{
204+
if accessibilityLabel.isEmpty {
205+
OL.warning("The OUDS Badge with an icon should not have an empty accessibility label, think about your disabled users!")
206+
}
189207
self.status = status
190208
self.size = size.standardSize
191209
count = nil
192210
self.icon = icon
211+
self.accessibilityLabel = accessibilityLabel
193212
}
194213

195214
// MARK: Body
196215

216+
// swiftlint:disable force_unwrapping
197217
public var body: some View {
198218
HStack(alignment: .center) {
199219
BadgeCount(count: count, size: size)
@@ -207,8 +227,12 @@ public struct OUDSBadge: View { // TODO: #514 - Add hyperlink for badge document
207227
alignment: .center)
208228
.oudsBackground(backgroundColor)
209229
.clipShape(RoundedRectangle(cornerRadius: theme.borders.borderRadiusPill))
230+
.accessibilityHidden(count == nil && icon == nil) // Hide badge from A11Y tools if no content inside
231+
.accessibilityLabel(accessibilityLabel ?? (count != nil ? "\(count!)" : ""))
210232
}
211233

234+
// swiftlint:enable force_unwrapping
235+
212236
// MARK: Private helpers
213237

214238
/// Returns the value to apply to compute frame wize.

0 commit comments

Comments
 (0)