Unverified Commit 16535924 authored by dsanagustin's avatar dsanagustin Committed by GitHub

Add CloseButtonTooltip to the 'X' button on a SnackBar (#143934)

Adds a localized Close Button tooltip to the 'X' Button on a SnackBar, making it readable by screen readers.

Github Issue #143793 

*If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].*
parent b476e967
......@@ -11,6 +11,7 @@ import 'colors.dart';
import 'icon_button.dart';
import 'icons.dart';
import 'material.dart';
import 'material_localizations.dart';
import 'material_state.dart';
import 'scaffold.dart';
import 'snack_bar_theme.dart';
......@@ -656,6 +657,7 @@ class _SnackBarState extends State<SnackBar> {
iconSize: 24.0,
color: widget.closeIconColor ?? snackBarTheme.closeIconColor ?? defaults.closeIconColor,
onPressed: () => ScaffoldMessenger.of(context).hideCurrentSnackBar(reason: SnackBarClosedReason.dismiss),
tooltip: MaterialLocalizations.of(context).closeButtonTooltip,
)
: null;
......
......@@ -3243,6 +3243,40 @@ void main() {
'snack_bar.goldenTest.floatingWithActionWithIcon.png'));
});
testWidgets('SnackBar has tooltip for Close Button', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/143793
await tester.pumpWidget(MaterialApp(
theme: ThemeData(useMaterial3: false),
debugShowCheckedModeBanner: false, // https://github.com/flutter/flutter/issues/143616
home: const Scaffold(
bottomSheet: SizedBox(
width: 200,
height: 50,
child: ColoredBox(
color: Colors.pink,
),
),
),
));
final ScaffoldMessengerState scaffoldMessengerState = tester.state(find.byType(ScaffoldMessenger));
scaffoldMessengerState.showSnackBar(
SnackBar(
content: const Text('Snackbar with close button'),
duration: const Duration(days: 365),
action: SnackBarAction(label: 'ACTION', onPressed: () {}),
behavior: SnackBarBehavior.floating,
showCloseIcon: true,
),
);
await tester.pumpAndSettle(); // Have the SnackBar fully animate in.
expect(
find.byTooltip(MaterialLocalizations.of(scaffoldMessengerState.context).closeButtonLabel),
findsOneWidget
);
});
testWidgets('Material2 - Fixed width snackbar can display optional icon', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(
theme: ThemeData(useMaterial3: false),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment