Skip to content

Closing a control's context flyout (e.g. TextBox right-click menu) permanently removes it from the macOS accessibility treeΒ #25228

Open

Description

@MartinZikmund

Current behavior πŸ›

On Skia Desktop/macOS, opening and closing a control's default context flyout (TextCommandBarFlyout, e.g. right-click on a TextBox) permanently removes the control's own accessibility element β€” and its entire internal accessibility subtree β€” from the native accessibility tree exposed to VoiceOver/AX clients. The control is still visible and fully usable, but to any AX client it has vanished: accessibilityChildren no longer contains it, and nothing later rebuilds the tree, so it stays broken for the rest of the window's lifetime.

A verbose native trace of the macOS accessibility bridge (UNO_A11Y_VERBOSE=1, Debug build) shows the exact sequence for a single TextBox with AcceptsReturn="True":

added element handle=4362385560 role=textarea label=lorem parent=4362385480   // the TextBox's own AX element
added element handle=5552949632 ... parent=4362385560                        // + 13 more legitimate descendants (its internal ScrollViewer/scrollbars)
...
added element handle=5767317152 role=dialog label=Popup parent=4362369456    // the ContextFlyout's own Popup/dialog wrapper
added element handle=5767319664 role=region ... parent=5767317152
added element handle=5767644432 ... parent=5767319664
added element handle=5767699808 ... parent=5767690120                        // <-- parent handle 5767690120 was NEVER added to the context
...                                                                           // (dozens more descendants of 5767699808)
removed element handle=5767317152 (and 2 descendants)                        // Popup wrapper removed correctly on close
removed element handle=4362385560 (and 14 descendants)                       // <-- the TextBox's own AX element is removed!

handle=5767690120 is used as a parentHandle at uno_accessibility_add_element but never appears as an added element anywhere before it β€” the lookup for it fails. After that point the TextBox (and the rest of the real content) is gone from accessibilityChildren.

Expected behavior 🎯

Opening and closing a context menu/flyout must not affect the accessibility exposure of the control it was opened on (or of any other unrelated content). This matches WinUI, where a TextCommandBarFlyout opening/closing on a TextBox has no effect on the TextBox's own UIA/AX representation (verified by source inspection of FlyoutBase_partial.cpp's light-dismiss/close teardown, which only tears down the flyout's own presenter β€” not the placement target).

How to reproduce it (as minimally and precisely as possible) πŸ”¬

Minimal runtime-test repro (Skia Desktop/macOS), using the native accessibilityChildren Objective-C selector in-process so it isn't affected by AX-client sandboxing:

var textBox = new TextBox { Text = "lorem\nipsum", AcceptsReturn = true };
window.Content = textBox;
window.Activate();
// ... wait for load/idle ...

// First AX client query builds the native tree (objc_msgSend(windowHandle, "accessibilityChildren")).
// FindByRole(windowHandle, "AXTextArea") now finds the TextBox - OK.

var flyout = textBox.ContextFlyout;   // default TextCommandBarFlyout
flyout.ShowAt(textBox);
// ... wait for idle ...
flyout.Hide();
// ... wait for idle ...

// FindByRole(windowHandle, "AXTextArea") now returns null: the TextBox is gone.

This fails on the very first attempt, every time (verified with UITEST_RUNTIME_TESTS_ITERATIONS=10, UITEST_RUNTIME_TESTS_ATTEMPTS=1: "Failed on iteration 1 of 10").

Manual repro in the SamplesApp: open sample TextBox/TextBox_IsReadOnly_AcceptsReturn, right-click the TextBox to open its context menu, dismiss it (Esc or click elsewhere), then inspect the window's AX tree (e.g. via Accessibility Inspector or AXUIElementCopyAttributeValue on kAXChildrenAttribute/kAXWindowsAttribute) β€” the TextBox and the rest of the page content are gone; only the title bar remains. The same thing happens after the SamplesApp's reload (↻) replaces the current sample's content.

Workaround πŸ› οΈ

None found. The window must be closed and reopened to restore accessibility (a fresh window gets a fresh tree).

Affected platforms πŸ“±πŸ’»πŸ–₯️

  • Desktop (macOS)

Renderer 🎨

  • Skia

Uno.Sdk version (and other relevant versions) πŸ“¦

Verified on master @ e98c0dcdc3 (includes #23924), net10.0-desktop, macOS, Xcode 26.5.

IDE version πŸ§‘β€πŸ’»

dotnet CLI

Anything else we need to know? πŸ’¬

Root cause is in the native accessibility bridge:

  • src/Uno.UI.Runtime.MacOS/UnoNativeMac/UnoNativeMac/UNOAccessibility.m, uno_accessibility_add_element (around line 1155): when parentHandle != 0 but the parent lookup (findElement) fails β€” as happens for handle 5767690120 in the trace above, which is never itself added β€” the function falls into the else branch and does context.rootElement = element;, silently promoting the orphaned element to be the new root of the whole accessibility tree, instead of keeping (or at least not losing) the real root. From that point, uno_accessibility_get_root_children (and therefore the window's accessibilityChildren, see UNOWindow.m around line 1670-1679) returns only that orphaned subtree β€” the real content, including the TextBox, becomes unreachable even though its UNOAccessibilityElement objects and parent/child links are still intact in memory.
  • uno_accessibility_remove_element (around line 1209) subsequently nils context.rootElement whenever the removed element happens to be the current root (line ~1244), which is how the tree ends up completely empty (not just missing one subtree) once the orphaned root's own subtree is later torn down.

I have not pinned down which managed call site passes the never-registered parentHandle (5767690120) when the TextCommandBarFlyout/MenuFlyoutPresenter opens β€” most likely something in src/Uno.UI.Runtime.MacOS/Accessibility/MacOSAccessibility.cs (OnChildAdded/AddAccessibilityElement/BuildAccessibilityTreeRecursive) adding a flyout-presenter descendant before its own parent has been registered, during the popup/overlay-layer insertion. That ordering bug is the trigger; the native "silently become root on lookup failure" fallback is what turns it into total tree loss. Either side (fixing the ordering so a parent is always registered first, and/or making the native fallback refuse to overwrite an existing rootElement/attach as a loose child instead) should resolve this.

Confirmed via runtime execution (in-process native accessibilityChildren queries through objc_msgSend, not out-of-process AXUIElement probing, which was unreliable in the sandboxed environment used to investigate this), not just code inspection.

Activity

  1. added
    kind/bug
    platform/macos 🍏
    triage/untriaged
    area/skia ✏️
    area/a11y
    difficulty/challenging 🀯
    on Oct 11, 2026
  2. MartinZikmund commented on Oct 11, 2026

    @MartinZikmund
    MemberAuthor

    A much more common trigger: focusing a non-empty TextBox. No flyout needed.

    Minimal runtime-test repro (Skia Desktop/macOS, master @ 951b7b4):

    var textBox = new TextBox { Text = "Focused late" };
    window.Content = new StackPanel { Children = { new Button { Content = "Other" }, textBox } };
    window.Activate();
    // ... wait for load/idle; first AX client query builds the tree (objc_msgSend(windowHandle, "accessibilityChildren")) ...
    // FindByRole(windowHandle, "AXTextField") finds the TextBox here - OK.
    
    textBox.Focus(FocusState.Programmatic);   // shows the TextBox's DeleteButton
    // ... wait for idle ...
    
    // FindByRole(windowHandle, "AXTextField") now returns null - the TextBox, and the rest of the window's content, is gone.

    This fails on the first attempt every time. The control case (same test, empty TextBox) does not reproduce it, so focus alone isn't the trigger β€” showing the DeleteButton is.

    A UNO_A11Y_VERBOSE=1 Debug-build trace of the focus call shows the exact same native mechanism as described above, just reached through a different managed path:

    UNOAccessibility: focus set to handle=6187890240 label=<private>
    UNOAccessibility: [window 0xa90308780] added element handle=6183223424 role=(null) label=(null) parent=6206570264
    UNOAccessibility: [window 0xa90308780] removed element handle=6187890272 (and 19 descendants)
    UNOAccessibility: [window 0xa90308780] removed element handle=6183223424 (and 0 descendants)
    

    parentHandle 6206570264 for the newly added element was never itself added to this context β€” findElement fails in uno_accessibility_add_element (UNOAccessibility.m#L1155-L1207), so it falls into the else branch and does context.rootElement = element; β€” promoting the orphan to root, exactly as in the flyout case. The real content (19 descendants) is torn down right after, then the orphaned root itself is torn down, and uno_accessibility_remove_element's context.rootElement = nil (UNOAccessibility.m#L1209-L1254) fires for it too, leaving the whole tree empty β€” matching the symptom here.

    So this looks like the same native fallback, reached by a second, much more common managed trigger: focusing any TextBox that has text, at any point after the AX tree exists, permanently kills the window's accessibility β€” no context menu required, just Tab or click into the field. I haven't pinned down the exact call in MacOSAccessibility.cs that adds the DeleteButton (or one of its descendants) with the unregistered parent handle; it's likely the same OnChildAdded/AddAccessibilityElement ordering issue already suspected above, just hit via a Visibility change on an already-templated child instead of a popup/overlay insertion.

  3. added
    7.1
    on Oct 14, 2026
  4. 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/skia ✏️difficulty/challenging 🀯kind/bugplatform/macos 🍏triage/untriaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions