Skip to content

[WASM][A11y] Focusing a TextBox blurs and refocuses it when accessibility is enabled #24866

Open

Description

@MartinZikmund

Current behavior 🐛

On Skia WebAssembly, once accessibility is enabled (the uno-enable-accessibility button, or a screen reader), a programmatic TextBox.Focus(FocusState.Programmatic) focuses the control, blurs it, then focuses it again within the same call:

  • Focused -> Normal -> Focused visual state churn
  • a spurious LostFocus followed by an extra GotFocus
  • the re-focus is applied as FocusState.Keyboard, overriding the state the original Focus() call produced (WinUI coerces Programmatic to Pointer or Keyboard based on the last input device, so the value itself differs by input; what is wrong is that it is re-applied as Keyboard by the bounce)

For an editable ComboBox's EditableText, one Focus() call was observed to raise 3 GotFocus events. Without accessibility enabled there is a single GotFocus and one Normal -> Focused transition.

Expected behavior 🎯

One GotFocus, no LostFocus, and no second focus pass that overrides the FocusState, same as with accessibility off and same as WinUI. Mirroring XAML focus into the semantic DOM must not feed back into XAML focus.

How to reproduce it (as minimally and precisely as possible) 🔬

  1. Use a Skia WebAssembly app (net11.0-browserwasm) on current master.
  2. Put a TextBox on a page and attach handlers:
var textBox = new TextBox { Text = "hello" };
textBox.GotFocus += (_, _) => Debug.WriteLine($"GotFocus({textBox.FocusState})");
textBox.LostFocus += (_, _) => Debug.WriteLine("LostFocus");
content.Children.Add(textBox);
  1. Enable accessibility: click the uno-enable-accessibility button in the page DOM (in the browser console: document.getElementById('uno-enable-accessibility').click()).
  2. Call textBox.Focus(FocusState.Programmatic);.
  3. Observe the log (observed on an instrumented build of an earlier master): GotFocus, LostFocus, GotFocus(Keyboard).

Runtime test used for this (WASM runtime tests, run Given_AccessibleTextBox-style with WasmSemanticDomHelper.EnableAccessibilityThroughDom()):

var textBox = new TextBox { Text = "hello" };
await UITestHelper.Load(textBox);
WasmSemanticDomHelper.EnableAccessibilityThroughDom();
await TestServices.WindowHelper.WaitForIdle();

List<string> log = new();
textBox.GotFocus += (_, _) => log.Add("GotFocus");
textBox.LostFocus += (_, _) => log.Add("LostFocus");

textBox.Focus(FocusState.Programmatic);
await TestServices.WindowHelper.WaitForIdle();
await Task.Delay(500);

CollectionAssert.AreEqual(new[] { "GotFocus" }, log);

Verification note: the stack trace below comes from a temporary diagnostic runtime test on an earlier master (headless Chrome). I could not rebuild the WASM head on current master (the wasm-tools workload is not installed for the .NET 11 SDK on my machine), so on current master I only re-confirmed by code inspection that every link in the chain below is still unchanged at commit 47267e7.

Workaround 🛠️

None in product code. In tests, run focus-sensitive tests before any accessibility-enabling test, or disable accessibility again in cleanup (Accessibility.disableAccessibility() exists since #24636).

Works on UWP/WinUI

Yes. WinUI keeps a single focus state for the control; there is no semantic-DOM mirror.

Renderer 🎨

Skia

Affected platforms 📱💻🖥️

WebAssembly (Skia). Only with accessibility enabled.

Uno.Sdk version (and other relevant versions) 📦

master @ 47267e7 (Uno 7.0 dev), net11.0-browserwasm.

IDE version 🧑‍💻

N/A

Anything else we need to know? 💬

Root cause: two paths into the browser/XAML focus bridge are not covered by the FocusSynchronizer._isSyncing guard.

  1. TextBox.Focus -> FocusManager -> FireAutomationFocusChanged -> WebAssemblyAccessibility.OnAutomationEvent(AutomationFocusChanged) -> NativeMethods.FocusSemanticElement (WebAssemblyAccessibility.cs L2557-L2569). This path does not set _isSyncing; only OnXamlGotFocus does (FocusSynchronizer.cs L127-L186).
  2. The JS focus() on the semantic node (Accessibility.ts L324) makes the browser blur the hidden native <input> that the TextBox just focused. That blur is not a managed-initiated one, so suppressBlurNotification is false and it is reported (BrowserInvisibleTextBoxViewExtension.ts L192) -> OnNativeBlur -> textBox.Unfocus() (BrowserInvisibleTextBoxViewExtension.cs L63-L84). The TextBox goes back to Normal.
  3. The semantic node's own focus event then arrives: WebAssemblyAccessibility.OnFocus -> FocusSynchronizer.OnBrowserFocus -> control.Focus(FocusState.Keyboard) (FocusSynchronizer.cs L208-L226). _isSyncing is false here because step 1 never set it, so XAML focus is re-applied, now as Keyboard.

Possible fix directions: set the sync guard around the OnAutomationEvent -> FocusSemanticElement call (and skip it when the semantic node is already the DOM active element), and/or detach the native input with blur suppression before focusing the semantic node, so the browser-initiated blur is not reported.

No existing issue or open PR (including the WASM a11y remediation work) covers this.

Activity

  1. added
    kind/bug
    platform/wasm 🌐
    triage/untriaged
    area/skia ✏️
    area/a11y
    difficulty/medium 🤔
    area/focus
    on Oct 1, 2026
  2. added
    7.1
    on Oct 14, 2026
  3. removed
    7.1
    on Oct 29, 2026
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

    area/a11yarea/focusarea/skia ✏️difficulty/medium 🤔kind/bugplatform/wasm 🌐triage/untriaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions