Skip to content

Keyboard focus does not shift to a newly opened modal page: Pressing enter clicks the button on the page beneath the modal page #22938

@janne-hmp

Description

@janne-hmp

Description

On Windows in .NET MAUI 8.0 and 9.0 Preview 4, the keyboard focus does not shift to the newly opened modal page (opened using Navigation.PushModalAsync), but remains on the main page (first page of the app). You can press enter to click the button on the page beneath the modal page.

Steps to Reproduce

  1. Make the default MAUI app
  2. Create a new MAUI ContentPage named ModalTestPage.
  3. Change ModalTestPage's background color to Beige by adding to the page's XAML: BackgroundColor="Beige" .
  4. Add the following code to the MainPage button:
            var modalPage = new ModalTestPage();
            Navigation.PushModalAsync(modalPage);
  1. (This is from other example of having a problem with maximizing, but I keep it here just in case it is relevant.) Add to the top of MauiProgram.cs the following:

using Microsoft.Maui.LifecycleEvents;

and add to builder the following:

#if WINDOWS
                .ConfigureLifecycleEvents(events =>
                {
                    // Make sure to add "using Microsoft.Maui.LifecycleEvents;" in the top of the file 
                    events.AddWindows(windowsLifecycleBuilder =>
                    {
                        windowsLifecycleBuilder.OnWindowCreated(window =>
                        {
                            window.ExtendsContentIntoTitleBar = false;
                            var handle = WinRT.Interop.WindowNative.GetWindowHandle(window);
                            var id = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(handle);
                            var appWindow = Microsoft.UI.Windowing.AppWindow.GetFromWindowId(id);
                            switch (appWindow.Presenter)
                            {
                                case Microsoft.UI.Windowing.OverlappedPresenter overlappedPresenter:
                                    overlappedPresenter.SetBorderAndTitleBar(false, false);
                                    overlappedPresenter.Maximize();
                                    break;
                            }
                        });
                    });
                })
#endif            
  1. Add a tap recognizer to the label on ModalTestPage:

XAML:

        <Label 
            Text="Welcome to .NET MAUI!"
            VerticalOptions="Center" 
            HorizontalOptions="Center">
            <Label.GestureRecognizers>
                <TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped"></TapGestureRecognizer>
            </Label.GestureRecognizers>
        </Label>

C#: (closes the modal window, so you can check what's going on beneath):

    private void TapGestureRecognizer_Tapped(object sender, TappedEventArgs e)
    {
		Navigation.PopModalAsync();
    }

  1. Build and start the app.
  2. Press the button. A modal page opens. (Note that the modal page (beige) does not cover the whole window, but this is not relevant in this example.)
  3. Press enter key on your keyboard 10 times. This in fact presses the button on MainPage beneath.
  4. Click the "Welcome to .NET MAUI!" label 11 times (11 modal pages have appeared).
  5. The button says it has been clicked 11 times.

Link to public reproduction project repository

Can make one if need be, but this is very easy to replicate.

Version with bug

9.0.0-preview.4.10690

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

Windows 11

Did you find any workaround?

No. All potential workarounds are complicated and imperfect.

Relevant log output

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions