Flutter Web App: adds a11y semantic attributes to slider (#151985)

added Semantics wrapper over slider to add appropriate a11y semantic attributes to slider

Before: https://screenshot.googleplex.com/8jmDh3RSB3oG5Z2
After: https://screenshot.googleplex.com/7Z4FdVgwcC4ZQxm

fixes b/340638215
This commit is contained in:
DBowen33 2024-07-25 10:58:24 -05:00 committed by GitHub
parent 3c0302c33d
commit 7d588feacd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 10 deletions

View File

@ -27,6 +27,7 @@ class MainWidget extends StatefulWidget {
class MainWidgetState extends State<MainWidget> {
double currentSliderValue = 20;
static const String accessibilityLabel = 'Accessibility Test Slider';
@override
Widget build(BuildContext context) {
@ -36,16 +37,19 @@ class MainWidgetState extends State<MainWidget> {
title: const Text('Slider'),
),
body: Center(
child: Slider(
value: currentSliderValue,
max: 100,
divisions: 5,
label: currentSliderValue.round().toString(),
onChanged: (double value) {
setState(() {
currentSliderValue = value;
});
},
child: Semantics(
label: accessibilityLabel,
child: Slider(
value: currentSliderValue,
max: 100,
divisions: 5,
label: currentSliderValue.round().toString(),
onChanged: (double value) {
setState(() {
currentSliderValue = value;
});
},
),
),
),
);

View File

@ -19,4 +19,9 @@ void main() {
final MainWidgetState state = tester.state<MainWidgetState>(find.byType(MainWidget));
expect(state.currentSliderValue, 60);
});
testWidgets('slider semantics wrapper exists', (WidgetTester tester) async {
await pumpsUseCase(tester, SliderUseCase());
final Finder semanticsWidget = find.bySemanticsLabel('Accessibility Test Slider');
expect(semanticsWidget, findsOneWidget);
});
}