Repository navigation
Description
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 -> Focusedvisual state churn- a spurious
LostFocusfollowed by an extraGotFocus - the re-focus is applied as
FocusState.Keyboard, overriding the state the originalFocus()call produced (WinUI coercesProgrammatictoPointerorKeyboardbased on the last input device, so the value itself differs by input; what is wrong is that it is re-applied asKeyboardby 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) 🔬
- Use a Skia WebAssembly app (
net11.0-browserwasm) on currentmaster. - Put a
TextBoxon 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);- Enable accessibility: click the
uno-enable-accessibilitybutton in the page DOM (in the browser console:document.getElementById('uno-enable-accessibility').click()). - Call
textBox.Focus(FocusState.Programmatic);. - 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.
TextBox.Focus->FocusManager->FireAutomationFocusChanged->WebAssemblyAccessibility.OnAutomationEvent(AutomationFocusChanged)->NativeMethods.FocusSemanticElement(WebAssemblyAccessibility.cs L2557-L2569). This path does not set_isSyncing; onlyOnXamlGotFocusdoes (FocusSynchronizer.cs L127-L186).- 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, sosuppressBlurNotificationis false and it is reported (BrowserInvisibleTextBoxViewExtension.ts L192) ->OnNativeBlur->textBox.Unfocus()(BrowserInvisibleTextBoxViewExtension.cs L63-L84). The TextBox goes back toNormal. - The semantic node's own focus event then arrives:
WebAssemblyAccessibility.OnFocus->FocusSynchronizer.OnBrowserFocus->control.Focus(FocusState.Keyboard)(FocusSynchronizer.cs L208-L226)._isSyncingis false here because step 1 never set it, so XAML focus is re-applied, now asKeyboard.
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