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

View File

@ -19,4 +19,9 @@ void main() {
final MainWidgetState state = tester.state<MainWidgetState>(find.byType(MainWidget)); final MainWidgetState state = tester.state<MainWidgetState>(find.byType(MainWidget));
expect(state.currentSliderValue, 60); 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);
});
} }