Skip to content

Tab focus does not cycle between NativeWebView and the main window properly. #76

Description

@fleeting-zone

Describe the bug

When the last focusable element inside the WebView loses focus, the Tab key no longer cycles focus back to the first element.
The user has to click on the window or the WebView itself to restore the focus chain.

To Reproduce

QQ20260826-020751.mp4
<Window xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
        x:Class="AvaloniaApplication2.MainWindow"
        Title="AvaloniaApplication2">
    <DockPanel Margin="16">
        
        <StackPanel DockPanel.Dock="Top" Spacing="4">
            <CheckBox Name="WebViewFocusableCheckBox" IsChecked="True" Focusable="False">
                Enable WebView Focus
            </CheckBox>
            
            <StackPanel DockPanel.Dock="Top" Orientation="Horizontal" Spacing="4">
                <Button Content="Button 1"></Button>
                <Button Content="Button 2"></Button>
                <Button Content="Button 3"></Button>
            </StackPanel>
        </StackPanel>
        
        <StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" Spacing="4">
            <Button Content="Button 4"></Button>
            <Button Content="Button 5"></Button>
            <Button Content="Button 6"></Button>
        </StackPanel>
        
        <Border BorderThickness="1" BorderBrush="#BBB" Margin="0 4">
            <NativeWebView 
                Name="WebView" 
                Focusable="{Binding IsChecked, ElementName=WebViewFocusableCheckBox}" />
        </Border>
        
    </DockPanel>
</Window>
using System;
using Avalonia.Controls;

namespace AvaloniaApplication2;

public partial class MainWindow : Window
{
    private const string Html = """
                                <html>
                                    <head>
                                        <style>
                                            button {
                                                padding: 8px 16px;
                                                font-size: 14px;
                                                background-color: #fff;
                                                color: #606266;
                                                border: 1px solid #dcdfe6;
                                                border-radius: 4px;
                                                outline: none;
                                            }
                                            button:focus {
                                                outline: 3px solid #409eff;
                                            }
                                        </style>
                                    </head>
                                    <body>
                                        <button>button 7</button>
                                        <button>button 8</button>
                                        <button>button 9</button>
                                    </body>
                                </html>          
                                """;

    public MainWindow()
    {
        InitializeComponent();
        WebView.Source = new Uri($"data:text/html;charset=utf-8,{Uri.EscapeDataString(Html)}");
    }
}

Expected behavior

No response

Avalonia WebView version

12.1.0

Avalonia version

12.1.1

OS

Windows

Additional context

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions