Skip to content

Commit 40574ba

Browse files
committed
feat(progress-indicator): add semantics label for status of progress indicator
1 parent 6df2f52 commit 40574ba

9 files changed

Lines changed: 77 additions & 28 deletions

ouds_core/lib/components/progress_indicator/internal/ouds_progress_indicator_utils.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
library;
1515

1616
import 'package:flutter/material.dart';
17+
import 'package:ouds_core/components/common/ouds_icon_status.dart';
1718
import 'package:ouds_core/components/progress_indicator/ouds_progress_indicator.dart';
19+
import 'package:ouds_core/l10n/gen/ouds_localizations.dart';
1820

1921
/// Utility methods used by OUDS progress indicators.
2022
///
@@ -76,4 +78,17 @@ class OudsProgressIndicatorUtils {
7678

7779
return '';
7880
}
81+
82+
static String? buildStatusSemanticsLabel(
83+
OudsLocalizations? localizations,
84+
OudsIconStatus status,
85+
) {
86+
return status is Warning
87+
? localizations?.core_common_warning_a11y
88+
: status is Negative
89+
? localizations?.core_common_error_a11y
90+
: status is Info
91+
? localizations?.core_common_info_a11y
92+
: null;
93+
}
7994
}

ouds_core/lib/components/progress_indicator/ouds_progress_indicator.dart

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import 'package:ouds_core/components/common/ouds_icon_status.dart';
1717
import 'package:ouds_core/components/progress_indicator/internal/ouds_progress_indicator_status_modifier.dart';
1818
import 'package:ouds_core/components/progress_indicator/internal/ouds_progress_indicator_style_modifier.dart';
1919
import 'package:ouds_core/components/progress_indicator/internal/ouds_progress_indicator_utils.dart';
20+
import 'package:ouds_core/l10n/gen/ouds_localizations.dart';
2021
import 'package:ouds_theme_contract/ouds_theme.dart';
2122

2223
/// Defines whether a progress indicator shows a known progress value
@@ -196,8 +197,12 @@ class _OudsCircularProgressIndicatorState
196197
required double gapSize,
197198
required StrokeCap strokeCap,
198199
}) {
200+
final localizations = OudsLocalizations.of(context);
201+
final semanticsLabel =
202+
'${widget.semanticLabel} , ${OudsProgressIndicatorUtils.buildStatusSemanticsLabel(localizations, widget.status) ?? ''}, ';
203+
199204
return CircularProgressIndicator(
200-
semanticsLabel: widget.semanticLabel,
205+
semanticsLabel: semanticsLabel,
201206
year2023: false,
202207
constraints: BoxConstraints(
203208
minWidth: defaultSize,
@@ -299,33 +304,39 @@ class _OudsLinearProgressIndicatorState
299304

300305
@override
301306
Widget build(BuildContext context) {
302-
return Column(
303-
spacing: OudsTheme.of(
304-
context,
305-
).componentsTokens(context).progressIndicator.spacePaddingBlock,
306-
children: [
307-
_buildLinearProgressIndicator(),
308-
Align(
309-
alignment: OudsProgressIndicatorUtils.getTextAlign(
310-
widget.helperTextAlignment,
311-
),
312-
child: Text(
313-
OudsProgressIndicatorUtils.buildHelperText(
314-
widget.percentage,
315-
widget.spaceBeforePercentage,
316-
widget.progress,
317-
widget.helperText,
307+
return MergeSemantics(
308+
child: Column(
309+
spacing: OudsTheme.of(
310+
context,
311+
).componentsTokens(context).progressIndicator.spacePaddingBlock,
312+
children: [
313+
_buildLinearProgressIndicator(),
314+
Align(
315+
alignment: OudsProgressIndicatorUtils.getTextAlign(
316+
widget.helperTextAlignment,
318317
),
319-
style: OudsTheme.of(context).typographyTokens
320-
.typeLabelDefaultMedium(context)
321-
.copyWith(
322-
color: OudsTheme.of(
323-
context,
324-
).colorScheme(context).contentDefault,
325-
),
318+
child: widget.percentage
319+
? ExcludeSemantics(child: _buildHelperTextWidget())
320+
: _buildHelperTextWidget(),
321+
),
322+
],
323+
),
324+
);
325+
}
326+
327+
Widget _buildHelperTextWidget() {
328+
return Text(
329+
OudsProgressIndicatorUtils.buildHelperText(
330+
widget.percentage,
331+
widget.spaceBeforePercentage,
332+
widget.progress,
333+
widget.helperText,
334+
),
335+
style: OudsTheme.of(context).typographyTokens
336+
.typeLabelDefaultMedium(context)
337+
.copyWith(
338+
color: OudsTheme.of(context).colorScheme(context).contentDefault,
326339
),
327-
),
328-
],
329340
);
330341
}
331342

@@ -410,9 +421,14 @@ class _OudsLinearProgressIndicatorState
410421
required double gapSize,
411422
required BorderRadiusGeometry borderRadius,
412423
}) {
424+
final localizations = OudsLocalizations.of(context);
425+
426+
final semanticsLabel =
427+
'${widget.semanticLabel} , ${OudsProgressIndicatorUtils.buildStatusSemanticsLabel(localizations, widget.status) ?? ''}, ';
428+
413429
return LinearProgressIndicator(
414430
minHeight: minHeight,
415-
semanticsLabel: widget.semanticLabel,
431+
semanticsLabel: semanticsLabel,
416432
year2023: false,
417433
value: value,
418434
valueColor: AlwaysStoppedAnimation<Color>(indicatorColor),

ouds_core/lib/l10n/gen/ouds_localizations.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ abstract class OudsLocalizations {
115115
/// **'Warning'**
116116
String get core_common_warning_a11y;
117117

118+
/// No description provided for @core_common_info_a11y.
119+
///
120+
/// In en, this message translates to:
121+
/// **'Information'**
122+
String get core_common_info_a11y;
123+
118124
/// No description provided for @core_common_selected_a11y.
119125
///
120126
/// In en, this message translates to:

ouds_core/lib/l10n/gen/ouds_localizations_ar.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ class OudsLocalizationsAr extends OudsLocalizations {
1717
@override
1818
String get core_common_warning_a11y => 'تحذير';
1919

20+
@override
21+
String get core_common_info_a11y => 'معلومة';
22+
2023
@override
2124
String get core_common_selected_a11y => 'محدد';
2225

ouds_core/lib/l10n/gen/ouds_localizations_en.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ class OudsLocalizationsEn extends OudsLocalizations {
1717
@override
1818
String get core_common_warning_a11y => 'Warning';
1919

20+
@override
21+
String get core_common_info_a11y => 'Information';
22+
2023
@override
2124
String get core_common_selected_a11y => 'Selected';
2225

ouds_core/lib/l10n/gen/ouds_localizations_fr.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ class OudsLocalizationsFr extends OudsLocalizations {
1717
@override
1818
String get core_common_warning_a11y => 'Avertissement';
1919

20+
@override
21+
String get core_common_info_a11y => 'Information';
22+
2023
@override
2124
String get core_common_selected_a11y => 'Sélectionné';
2225

ouds_core/lib/l10n/ouds_flutter_ar.arb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"@_OUDS_COMMON": {},
33
"core_common_error_a11y": "خطأ",
44
"core_common_warning_a11y": "تحذير",
5+
"core_common_info_a11y": "معلومة",
56
"core_common_selected_a11y": "محدد",
67
"core_common_unselected_a11y": "غير محدد",
78
"core_common_loading_a11y": "جاري التحميل",

ouds_core/lib/l10n/ouds_flutter_en.arb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"@_OUDS_COMMON": {},
33
"core_common_error_a11y": "Error",
44
"core_common_warning_a11y": "Warning",
5+
"core_common_info_a11y": "Information",
56
"core_common_selected_a11y": "Selected",
67
"core_common_unselected_a11y": "Unselected",
78
"core_common_loading_a11y": "Loading",

ouds_core/lib/l10n/ouds_flutter_fr.arb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"@_OUDS_COMMON": {},
33
"core_common_error_a11y": "Erreur",
44
"core_common_warning_a11y": "Avertissement",
5-
"core_common_selected_a11y": "Sélectionné",
5+
"core_common_info_a11y": "Information",
6+
"core_common_selected_a11y": "Sélectionné",
67
"core_common_unselected_a11y": "Non sélectionné",
78
"core_common_loading_a11y": "Chargement",
89
"core_common_disabled_a11y": "Désactivé",

0 commit comments

Comments
 (0)