mirror of
https://github.com/flutter/flutter
synced 2024-08-25 02:46:31 +00:00
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].*
This commit is contained in:
parent
b476e9674e
commit
16535924f2
|
@ -11,6 +11,7 @@ import 'colors.dart';
|
||||||
import 'icon_button.dart';
|
import 'icon_button.dart';
|
||||||
import 'icons.dart';
|
import 'icons.dart';
|
||||||
import 'material.dart';
|
import 'material.dart';
|
||||||
|
import 'material_localizations.dart';
|
||||||
import 'material_state.dart';
|
import 'material_state.dart';
|
||||||
import 'scaffold.dart';
|
import 'scaffold.dart';
|
||||||
import 'snack_bar_theme.dart';
|
import 'snack_bar_theme.dart';
|
||||||
|
@ -656,6 +657,7 @@ class _SnackBarState extends State<SnackBar> {
|
||||||
iconSize: 24.0,
|
iconSize: 24.0,
|
||||||
color: widget.closeIconColor ?? snackBarTheme.closeIconColor ?? defaults.closeIconColor,
|
color: widget.closeIconColor ?? snackBarTheme.closeIconColor ?? defaults.closeIconColor,
|
||||||
onPressed: () => ScaffoldMessenger.of(context).hideCurrentSnackBar(reason: SnackBarClosedReason.dismiss),
|
onPressed: () => ScaffoldMessenger.of(context).hideCurrentSnackBar(reason: SnackBarClosedReason.dismiss),
|
||||||
|
tooltip: MaterialLocalizations.of(context).closeButtonTooltip,
|
||||||
)
|
)
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
|
|
|
@ -3243,6 +3243,40 @@ void main() {
|
||||||
'snack_bar.goldenTest.floatingWithActionWithIcon.png'));
|
'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 {
|
testWidgets('Material2 - Fixed width snackbar can display optional icon', (WidgetTester tester) async {
|
||||||
await tester.pumpWidget(MaterialApp(
|
await tester.pumpWidget(MaterialApp(
|
||||||
theme: ThemeData(useMaterial3: false),
|
theme: ThemeData(useMaterial3: false),
|
||||||
|
|
Loading…
Reference in a new issue