Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions packages/material_ui/lib/src/drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -727,15 +727,6 @@ class DrawerControllerState extends State<DrawerController> with SingleTickerPro
return const SizedBox.shrink();
}
} else {
final bool platformHasBackButton = switch (defaultTargetPlatform) {
TargetPlatform.android => true,
TargetPlatform.iOS ||
TargetPlatform.macOS ||
TargetPlatform.fuchsia ||
TargetPlatform.linux ||
TargetPlatform.windows => false,
};

final Color scrimColor =
widget.scrimColor ??
DrawerTheme.of(context).scrimColor ??
Expand All @@ -757,8 +748,7 @@ class DrawerControllerState extends State<DrawerController> with SingleTickerPro
children: <Widget>[
BlockSemantics(
child: ExcludeSemantics(
// On Android, the back button is used to dismiss a modal.
excluding: platformHasBackButton,
excluding: !widget.drawerBarrierDismissible,
child: GestureDetector(
onTap: widget.drawerBarrierDismissible ? close : null,
child: Semantics(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
changelog: |
- Exposes modal barrier dismiss semantics for `Drawer` on Android to support Switch Access.
version: patch
183 changes: 83 additions & 100 deletions packages/material_ui/test/drawer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,37 +130,34 @@ void main() {
expect(find.text('Archive'), findsNothing);
});

testWidgets(
'Drawer dismiss barrier has label',
(WidgetTester tester) async {
final semantics = SemanticsTester(tester);
await tester.pumpWidget(const MaterialApp(home: Scaffold(drawer: Drawer())));
testWidgets('Drawer dismiss barrier has label', (WidgetTester tester) async {
final semantics = SemanticsTester(tester);
await tester.pumpWidget(const MaterialApp(home: Scaffold(drawer: Drawer())));

final ScaffoldState state = tester.firstState(find.byType(Scaffold));
state.openDrawer();
final ScaffoldState state = tester.firstState(find.byType(Scaffold));
state.openDrawer();

await tester.pump();
await tester.pump(const Duration(seconds: 1));
await tester.pump();
await tester.pump(const Duration(seconds: 1));

expect(
semantics,
includesNodeWith(
label: const DefaultMaterialLocalizations().modalBarrierDismissLabel,
actions: <SemanticsAction>[SemanticsAction.tap],
),
);
expect(
semantics,
includesNodeWith(
label: const DefaultMaterialLocalizations().modalBarrierDismissLabel,
actions: <SemanticsAction>[SemanticsAction.tap],
),
);

semantics.dispose();
},
variant: const TargetPlatformVariant(<TargetPlatform>{
TargetPlatform.iOS,
TargetPlatform.macOS,
}),
);
semantics.dispose();
}, variant: TargetPlatformVariant.all());

testWidgets('Drawer dismiss barrier has no label', (WidgetTester tester) async {
testWidgets('Drawer dismiss barrier has no label when drawerBarrierDismissible is false', (
WidgetTester tester,
) async {
final semantics = SemanticsTester(tester);
await tester.pumpWidget(const MaterialApp(home: Scaffold(drawer: Drawer())));
await tester.pumpWidget(
const MaterialApp(home: Scaffold(drawerBarrierDismissible: false, drawer: Drawer())),
);

final ScaffoldState state = tester.firstState(find.byType(Scaffold));
state.openDrawer();
Expand All @@ -179,7 +176,7 @@ void main() {
);

semantics.dispose();
}, variant: TargetPlatformVariant.only(TargetPlatform.android));
}, variant: TargetPlatformVariant.all());

testWidgets('Drawer tap test', (WidgetTester tester) async {
final scaffoldKey = GlobalKey<ScaffoldState>();
Expand Down Expand Up @@ -1308,69 +1305,70 @@ void main() {
expect(find.byType(Drawer), findsExactly(0));
});

testWidgets(
'Dismissible Drawer includes button in semantic tree',
(WidgetTester tester) async {
final semantics = SemanticsTester(tester);
final scaffoldKey = GlobalKey<ScaffoldState>();
testWidgets('Dismissible Drawer includes button in semantic tree', (WidgetTester tester) async {
final semantics = SemanticsTester(tester);
final scaffoldKey = GlobalKey<ScaffoldState>();

await tester.pumpWidget(
MaterialApp(
home: Builder(
builder: (BuildContext context) {
return Scaffold(key: scaffoldKey, drawer: const Drawer());
},
),
await tester.pumpWidget(
MaterialApp(
home: Builder(
builder: (BuildContext context) {
return Scaffold(key: scaffoldKey, drawer: const Drawer());
},
),
);
),
);

// Open the drawer.
scaffoldKey.currentState!.openDrawer();
await tester.pump(const Duration(milliseconds: 100));
// Open the drawer.
scaffoldKey.currentState!.openDrawer();
await tester.pump(const Duration(milliseconds: 100));

expect(semantics, includesNodeWith(actions: <SemanticsAction>[SemanticsAction.tap]));
expect(semantics, includesNodeWith(label: 'Dismiss'));
expect(semantics, includesNodeWith(actions: <SemanticsAction>[SemanticsAction.tap]));
expect(
semantics,
includesNodeWith(label: const DefaultMaterialLocalizations().modalBarrierDismissLabel),
);

semantics.dispose();
},
variant: const TargetPlatformVariant(<TargetPlatform>{
TargetPlatform.iOS,
TargetPlatform.macOS,
}),
);
semantics.dispose();
}, variant: TargetPlatformVariant.all());

testWidgets(
'Dismissible Drawer barrier is hidden from semantics on Android (back button is used to dismiss)',
(WidgetTester tester) async {
final semantics = SemanticsTester(tester);
final scaffoldKey = GlobalKey<ScaffoldState>();
testWidgets('Non-dismissible Drawer barrier is hidden from semantics', (
WidgetTester tester,
) async {
final semantics = SemanticsTester(tester);
final scaffoldKey = GlobalKey<ScaffoldState>();

await tester.pumpWidget(
MaterialApp(
home: Builder(
builder: (BuildContext context) {
return Scaffold(key: scaffoldKey, drawer: const Drawer(), body: Container());
},
),
await tester.pumpWidget(
MaterialApp(
home: Builder(
builder: (BuildContext context) {
return Scaffold(
key: scaffoldKey,
drawerBarrierDismissible: false,
drawer: const Drawer(),
);
},
),
);
),
);

// Open the drawer.
scaffoldKey.currentState!.openDrawer();
await tester.pump(const Duration(milliseconds: 100));
// Open the drawer.
scaffoldKey.currentState!.openDrawer();
await tester.pump(const Duration(milliseconds: 100));

expect(
semantics,
isNot(
includesNodeWith(actions: <SemanticsAction>[SemanticsAction.tap, SemanticsAction.focus]),
),
);
expect(semantics, isNot(includesNodeWith(label: 'Dismiss')));
expect(
semantics,
isNot(
includesNodeWith(actions: <SemanticsAction>[SemanticsAction.tap, SemanticsAction.focus]),
),
);
expect(
semantics,
isNot(includesNodeWith(label: const DefaultMaterialLocalizations().modalBarrierDismissLabel)),
);

semantics.dispose();
},
variant: TargetPlatformVariant.only(TargetPlatform.android),
);
semantics.dispose();
}, variant: TargetPlatformVariant.all());

testWidgets('Drawer can be configured as not dismissible', (WidgetTester tester) async {
await tester.pumpWidget(
Expand Down Expand Up @@ -1530,28 +1528,13 @@ void main() {

// Test barrier semantics.
final semantics = SemanticsTester(tester);
final expectBarrierExcluded = defaultTargetPlatform == TargetPlatform.android;

if (expectBarrierExcluded) {
expect(
semantics,
isNot(
includesNodeWith(
label: localizations.modalBarrierDismissLabel,
actions: <SemanticsAction>[SemanticsAction.tap, SemanticsAction.focus],
),
),
);
} else {
expect(
semantics,
includesNodeWith(
label: localizations.modalBarrierDismissLabel,
actions: <SemanticsAction>[SemanticsAction.tap],
),
);
}

expect(
semantics,
includesNodeWith(
label: localizations.modalBarrierDismissLabel,
actions: <SemanticsAction>[SemanticsAction.tap],
),
);
semantics.dispose();
}

Expand Down
Loading