diff --git a/lib/widgets/desktop/desktop_navigation.dart b/lib/widgets/desktop/desktop_navigation.dart index d2d4cacf0..e413f1157 100644 --- a/lib/widgets/desktop/desktop_navigation.dart +++ b/lib/widgets/desktop/desktop_navigation.dart @@ -452,19 +452,28 @@ class _NowPlayingTransitionState extends State<_NowPlayingTransition> Visibility( visible: !covered, maintainState: true, - child: IgnorePointer(ignoring: widget.open, child: widget.shell), + // Focus leaves the shell as soon as Now Playing opens, and leaves + // Now Playing as soon as it closes, as without the transition, so + // a field left focused underneath cannot take Space meanwhile. + child: IgnorePointer( + ignoring: widget.open, + child: ExcludeFocus(excluding: widget.open, child: widget.shell), + ), ), if (widget.open || !_controller.isDismissed) IgnorePointer( ignoring: exiting, - child: Transform.translate( - offset: Offset(0, offset), - child: Opacity( - key: const ValueKey('desktop-now-playing-fade'), - opacity: opacity.clamp(0.0, 1.0), - child: KeyedSubtree( - key: const ValueKey('desktop-now-playing'), - child: widget.nowPlaying, + child: ExcludeFocus( + excluding: exiting, + child: Transform.translate( + offset: Offset(0, offset), + child: Opacity( + key: const ValueKey('desktop-now-playing-fade'), + opacity: opacity.clamp(0.0, 1.0), + child: KeyedSubtree( + key: const ValueKey('desktop-now-playing'), + child: widget.nowPlaying, + ), ), ), ), diff --git a/test/desktop_shell_test.dart b/test/desktop_shell_test.dart index 400b77595..75f488ace 100644 --- a/test/desktop_shell_test.dart +++ b/test/desktop_shell_test.dart @@ -417,6 +417,40 @@ void main() { expect(find.text('content'), findsOneWidget); }); + testWidgets('focus leaves the shell as soon as Now Playing opens ' + '($mornye)', (tester) async { + addTearDown(() => desktopNowPlayingOpen.value = false); + await pumpShell( + tester, + mornye: mornye, + width: 1400, + nowPlaying: const ColoredBox(color: Colors.black), + ); + await tester.sendKeyEvent(LogicalKeyboardKey.tab); + await tester.pump(); + final shellFocus = FocusManager.instance.primaryFocus!; + expect( + shellFocus.context!.findAncestorWidgetOfExactType(), + isNotNull, + ); + + desktopNowPlayingOpen.value = true; + await tester.pump(); + await tester.pump(const Duration(milliseconds: 16)); + // Still mid-entrance, with the shell painted underneath. + expect(find.text('content'), findsOneWidget); + expect(shellFocus.hasPrimaryFocus, isFalse); + + await tester.pumpAndSettle(); + desktopNowPlayingOpen.value = false; + await tester.pump(); + // The shell takes focus again while Now Playing leaves. + shellFocus.requestFocus(); + await tester.pump(); + expect(shellFocus.hasPrimaryFocus, isTrue); + await tester.pumpAndSettle(); + }); + testWidgets('the Downloads menu animates only in Material ($mornye)', ( tester, ) async {