Skip to content

Fix chart LabelView/TickLabelView a11y peer-subtree leaks (#162) - #644

Merged
Alexandre Zollinger Chohfi (azchohfi) merged 4 commits into
mainfrom
azchohfi-fix-chart-labelview-a11y-peers
Jun 26, 2026
Merged

Alexandre Zollinger Chohfi (azchohfi) merged 4 commits into
mainfrom
azchohfi-fix-chart-labelview-a11y-peers

Conversation

@azchohfi

@azchohfi Alexandre Zollinger Chohfi (azchohfi) commented Jun 23, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #162.

Problem

PieChartElement<T>.LabelView(Func<T,PieSliceLayout,Element>) and ChartElement<T>.{X,Y}TickLabelView(Func<double,Element>) let callers replace the built-in TextBlock at a slice centroid / axis tick with any Reactor Element (including a custom Component). The stopgap wrapped the returned element with .AccessibilityView(Raw) + IsHitTestVisible=false on the outer wrapper only. Raw on the outer wrapper does not reliably remove inner peers from assistive tech / focus traversal, causing:

  1. Double-announcement — the chart's own ChartPointDescriptor names the slice (e.g. "Slice 5: 12 units"); a user LabelView containing the same string produces a second peer that announces it again.
  2. Focusable children — interactive sub-elements (e.g. a Button) in the user's Element keep their peers; IsHitTestVisible=false blocks pointer hits but not keyboard/focus traversal of inner peers.
  3. DataLabel not auto-fed — when a caller uses LabelView and skips the string LabelAccessor/DataLabel, the slice's accessible name falls back to "Slice {i+1}" even though the visual shows a meaningful label.

Fix

1. Force-Raw the whole realized subtree + remove inner focus

New helper src/Reactor/Charting/Accessibility/ChartLabelA11y.cs:

  • HideSubtreeOnMount(fe) sets IsHitTestVisible=false on the outer wrapper, then walks the realized visual tree (immediately and again on Loaded, to cover templated-control inner peers that only realize after load).
  • HideSubtree(root) recurses via VisualTreeHelper, setting AutomationProperties.AccessibilityView = Raw on every descendant FrameworkElement (removes inner peers from the UIA Content/Control views) and IsTabStop = false on every descendant Control (removes inner focusable children from the keyboard tab order).
  • Uses only the public VisualTreeHelper / AutomationProperties API — no reflection — so it stays AOT/trim-safe (the core lib treats AOT/trim warnings as errors).

2. Opt-in interactive: true escape hatch

LabelView, XTickLabelView, YTickLabelView (and D3Charts.D3Axes) gain an optional interactive param. When true, the chart does not force-Raw the subtree or remove focus — the caller takes responsibility for the element's accessibility. Default (false) = fully hidden from UIA/focus; the chart's own descriptor is the single source of truth.

3. accessibleName projection

LabelView/XTickLabelView/YTickLabelView gain an optional name projection. For pie slices it threads into the ChartPointDescriptor (LabelAccessor?.Invoke(d) ?? _labelName?.Invoke(d) ?? "Slice {i+1}"), so the accessible name matches the visible label instead of falling back to "Slice N" when a LabelView is supplied without a DataLabel/LabelAccessor. For ticks it applies AutomationName.

API additions are optional params (source-compatible — existing single-arg call sites compile unchanged). reactor.api.txt regenerated (both copies).

Tests

  • 6 unit tests (tests/Reactor.Tests/ChartsBuilderTests.cs): overload storage, name-projection threading into the descriptor, "Slice N" fallback, LabelAccessor precedence.
  • 3 selftest fixtures (tests/Reactor.AppTests.Host/SelfTest/Fixtures/ChartAccessibilityFixtures.cs) that build a real PieChart / Chart with a composite-Component LabelView containing a focusable Button + a TextBlock, realize the peer tree, and walk the realized FrameworkElement subtree asserting: (a) every inner descendant is AccessibilityView.Raw and (b) every inner Control is not a tab stop for the default non-interactive case; (c) with interactive:true the inner peers/tab-stops are intact; (d) the slice's accessible name equals the name projection (not "Slice N") when supplied without a DataLabel.
  • Negative-test verified: temporarily reverting the pie fix to pre-fix behavior makes the subtree-Raw / not-tab-stop assertions fail (4 failures), proving the assertions are real.

Peer-tree assertions are automated at the realized-FE level via the selftest tier; descriptor/name threading is verified both at the builder seam (unit) and via a realized ChartAutomationPeer (selftest).

Build clean (core lib + tests, ARM64), all unit + ChartA11y selftests green.

Coordination note (charting a11y is churning)

Per issue #162, charting a11y is actively churning (#628/#629 A11Y_CHART_011, #633 active-background scope, #498 charting↔scanner decoupling). This PR keeps changes scoped to the LabelView/TickLabelView peer-subtree + accessibleName paths. The only shared a11y touch is threading _labelName into the existing pie ChartPointDescriptor construction in Charts.cs (one line, additive fallback) — flagging for merge ordering with any concurrent descriptor/scanner work.

Co-authored-by: Copilot [email protected]


Review triage (pr-review follow-up)

Applied the coordinator-triaged pr-review findings on top of the original fix:

  • H1 (high) — pool contamination, fixed systemically. The subtree-hide sets IsTabStop=false/IsHitTestVisible=false on poolable inner controls. ElementPool.CleanElement now ClearValues UIElement.IsHitTestVisibleProperty and (guarded) Control.IsTabStopProperty next to the existing AccessibilityView reset, so a hidden inner control can't return to the pool non-tabbable / non-hit-testable and poison the next unrelated renter. New selftest ChartA11y_LabelViewPoolReset rents → sets both false + Raw → returns → re-rents the same instance and asserts all three reset.
  • H2 (high) — interactive toggle is now update-aware. The hide is a mount-time side effect, so flipping interactive in place couldn't undo it. Pie-label and axis-tick elements are now keyed by the interactive flag (__pielabel{i}_{0|1}, __xtick{i}_{0|1}, __ytick{i}_{0|1}), so toggling forces a remount that re-runs (or skips) the hide. New selftest ChartA11y_LabelViewInteractiveToggle toggles at runtime and asserts peers/tab-stops hide → un-hide → re-hide. (Relies on the H1 pool reset for the recycled control to come back clean.)
  • M2 (medium) — tick name coverage. New selftest ChartA11y_TickLabelViewNameProjection exercises both XTickLabelView/YTickLabelView name projections and asserts the value reaches AutomationName on the realized tick element.
  • M3 (medium) — docs. Updated the charting.md.dt template signature table + a11y wording (subtree-Raw + interactive opt-in + name projection) and both chart skill copies (skills/charts.md, plugins/reactor/skills/reactor-charts/SKILL.md); recompiled charting.md.
  • L2 (low) — consistency. Reordered D3Axes params (name before interactive) to match the fluent builders.
  • L1 (low) — docs. XML-doc note clarifying the pie name feeds the slice descriptor (always) while the tick name only sets AutomationName (intentional asymmetry).
  • M1 (medium) — accepted as-is. Kept the clean optional-param signatures rather than adding forwarder overloads. The additions are source-compatible (existing call sites compile unchanged) but technically binary-incompatible; acceptable for this pre-1.0, fast-moving framework.

Merge-ordering: the only shared-a11y touch remains the additive _labelName fallback in the pie ChartPointDescriptor — keep an eye on concurrent #633 descriptor work.

All ChartA11y selftests (incl. 3 new), ElementPoolOptionalReset selftests, and PoolResetSetConsistencyTests + ChartsBuilderTests + ApiIndexGeneratorTests unit tests green; core lib + host build clean (ARM64); both reactor.api.txt copies identical and current.


Re-review follow-up (2nd pr-review pass)

Implemented the 4 findings from the second pr-review run (0 critical, 0 high, 2 medium, 2 low):

  • M1 (correctness) — re-assert the subtree hide on in-place update. The non-interactive label/tick hide ran only at mount/Loaded, so a later in-place data/content update that realized new focusable descendants leaked them back into UIA / the tab order. Added an internal OnUpdateAction modifier hook (the update-time counterpart to OnMountAction) fired from Reconciler.ApplyModifiers when oldM is not null — i.e. on every in-place update, after child reconciliation — plus an internal OnUpdateAdd extension. The 3 non-interactive chart sites now wire .OnUpdateAdd(HideSubtreeOnUpdate) to re-walk and re-Raw/untab the subtree. Internal-only ⇒ no public API change. New selftest ChartA11y_LabelViewUpdateRehide grows a label from VStack(TextBlock) to VStack(TextBlock, Button) on a state toggle (stable key ⇒ in-place update) and asserts the update-realized buttons are Raw + not tab stops. Verified red-on-revert (buttons still mount but leak when the hook is disabled).
  • M2 (alternative-solution + test-coverage) — track IsTabStop in the pool-reset convention. The new Control.IsTabStop pool reset was invisible to PoolResetSetAnalyzer/PoolResetSetConsistencyTests. Added IsTabStop to TrappedProperties (it has an .IsTabStop modifier) and widened the consistency-test ClearValue regex to owner-qualified (FrameworkElement|UIElement|Control).XProperty on any receiver, so it now sees both the UIElement.IsHitTestVisible and Control.IsTabStop resets (the allow-list deliberately keeps AutomationProperties.* / FlexPanel.* attached-property clears excluded). IsHitTestVisible has no modifier → documented in IntentionallyExcluded. The table-driven analyzer test auto-covers IsTabStop.
  • L1 (correctness) — sentinel-based deferred-hide guard. Replaced the one-shot Loaded arm's IsHitTestVisible identity guard (which mis-fired on a recycled element that merely carried IsHitTestVisible=false) with a private attached PendingDeferredHide sentinel set in HideSubtreeOnMount and cleared on unmount via .OnUnmountAdd(ClearPendingHide) (Charting-side, to avoid a Core→Charting layering dependency). ApplyDeferredHide now hides only when the sentinel is present and consumes it. Reworked ChartA11y_LabelViewDeferredHideStaleGuard to cover no-sentinel-skips / sentinel-applies / cleared-skips. Verified red-on-revert (old guard fails 6/7 cases).
  • L2 (test-coverage) — Y-tick + tick interactive-toggle. New ChartA11y_TickLabelViewInteractiveToggle exercises the previously-uncovered Y-tick hide branch and the tick remount-by-interactive key for both axes (hide → expose → hide).

Shared-a11y note (merge ordering): unchanged from above — the only shared touch remains the additive _labelName fallback in the pie ChartPointDescriptor; watch vs concurrent #633 descriptor work. No public surface change; both reactor.api.txt copies unchanged (verified by ApiIndexGeneratorTests). Full unit suite (9523), PoolResetSet (28), and all ChartA11y selftests green; core lib + host build clean (ARM64, 0 warnings).

Custom PieChart LabelView and {X,Y}TickLabelView extension points wrapped
caller-supplied Elements with AccessibilityView.Raw on only the outer
wrapper, which does not reliably hide inner composite peers from assistive
tech or keyboard focus. This caused double-announcement, focusable-child
leaks, and a poor 'Slice N' accessible-name fallback.

- Add ChartLabelA11y.HideSubtreeOnMount: recursively force AccessibilityView.Raw
  on every descendant FrameworkElement and clear IsTabStop on every descendant
  Control (public VisualTreeHelper/AutomationProperties API only, AOT-safe).
  Re-walks on Loaded to cover templated-control inner peers.
- Add opt-in 'interactive: true' overload to LabelView/XTickLabelView/
  YTickLabelView (and D3Axes) that leaves caller peers intact; caller owns a11y.
- Add 'name' accessible-name projection: threads into the pie slice
  ChartPointDescriptor (replacing 'Slice N' fallback) and applies AutomationName
  to interactive ticks.
- Regenerate reactor.api.txt (both copies) for the new optional params.
- Add 6 unit tests + 3 selftest fixtures (peer-tree Raw/IsTabStop assertions,
  interactive opt-in, name projection); negative-test verified pre-fix failures.

Co-authored-by: Copilot <[email protected]>
…me test, docs

H1: reset IsHitTestVisible + IsTabStop in ElementPool.CleanElement so a control
hidden inside a custom chart label can't return to the pool non-tabbable /
non-hit-testable and poison the next renter.

H2: key pie-label and axis-tick elements by the interactive flag so toggling it
at runtime forces a remount (the subtree-hide is a mount-time side effect that an
in-place update cannot undo). Adds a runtime-toggle selftest.

M2: add a selftest asserting the X/Y tick name projection reaches AutomationName.

M3: update charting.md.dt template + both chart skill copies for the new
optional-param signatures and corrected a11y wording (subtree-Raw + interactive
opt-in + name projection); recompiled charting.md.

L2: reorder D3Axes params (name before interactive) to match the fluent builders.

L1: XML-doc note clarifying the pie name feeds the slice descriptor (always)
while the tick name only sets AutomationName.

New selftests: ChartA11y_LabelViewPoolReset, ChartA11y_LabelViewInteractiveToggle,
ChartA11y_TickLabelViewNameProjection.

Co-authored-by: Copilot <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes chart a11y issues when callers provide custom LabelView / {X,Y}TickLabelView elements by hiding the entire realized subtree (not just the wrapper) from UIA/focus by default, adding an interactive: true escape hatch, and allowing an optional name projection to keep the chart’s accessible names meaningful.

Changes:

  • Added ChartLabelA11y helper to force AccessibilityView.Raw across realized descendants and clear IsTabStop for non-interactive label/tick subtrees.
  • Extended chart label/tick APIs with optional name and interactive parameters, and keyed label/tick elements by the interactive flag to force remount on toggles.
  • Added unit + selftests, updated fixture registry, and refreshed docs/skill/API reference outputs.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/Reactor.Tests/ChartsBuilderTests.cs Unit tests for new overload storage and name-projection precedence/fallback.
tests/Reactor.AppTests.Host/SelfTest/SelfTestFixtureRegistry.cs Registers new ChartA11y selftests in both required locations.
tests/Reactor.AppTests.Host/SelfTest/Fixtures/ChartAccessibilityFixtures.cs Selftests validating subtree Raw/tab-stop behavior, interactive toggling, and name projection.
src/Reactor/Core/ElementPool.cs Resets IsHitTestVisible and IsTabStop to avoid pool contamination from subtree hiding.
src/Reactor/Charting/D3Charts.cs Adds tick name/interactive options, subtree hiding, and interactive-keyed remount behavior in D3Axes.
src/Reactor/Charting/Charts.cs Threads tick options into D3Axes; adds pie name/interactive options and descriptor fallback.
src/Reactor/Charting/Accessibility/ChartLabelA11y.cs New helper implementing subtree hide + focus removal (immediate + Loaded pass).
skills/reactor.api.txt Regenerated API reference reflecting new method signatures.
skills/charts.md Updates charting skill guidance for new defaults/parameters.
plugins/reactor/skills/reactor-dsl/references/reactor.api.txt Regenerated plugin API reference reflecting new signatures.
plugins/reactor/skills/reactor-charts/SKILL.md Updates packaged chart skill guidance for new defaults/parameters.
docs/guide/charting.md User guide updates documenting name and interactive behavior.
docs/_pipeline/templates/charting.md.dt Template updates (source-of-truth) for regenerated charting guide section.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…review)

HideSubtreeOnMount attaches a one-shot Loaded handler for the deferred subtree
hide. If the label element is unmounted and returned to the pool before it ever
loads, that handler survives into a later reuse of the recycled FrameworkElement.
When the FE is re-rented for an interactive (or unrelated) element, the stale
handler would wrongly force AccessibilityView.Raw / IsTabStop=false on the new
subtree.

Extract the deferred arm into ChartLabelA11y.ApplyDeferredHide with a guard: only
apply when IsHitTestVisible == false (the state HideSubtreeOnMount established).
The H1 pool reset restores IsHitTestVisible to true on return, so a stale handler
firing on a recycled/interactive FE is correctly skipped; a genuine deferred
non-interactive load still applies.

Adds selftest ChartA11y_LabelViewDeferredHideStaleGuard covering both arms.

Co-authored-by: Copilot <[email protected]>
…entinel guard, tick tests

Implements the 4 findings from the second pr-review pass on PR #644:

M1 (correctness): the non-interactive label/tick subtree hide ran only at mount/Loaded, so an in-place data/content update that realized NEW focusable descendants leaked them back into UIA / the tab order. Add an internal OnUpdateAction modifier hook (the update-time counterpart to OnMountAction) fired from Reconciler.ApplyModifiers when oldM is not null (after child reconciliation), plus an internal OnUpdateAdd extension. The 3 non-interactive chart sites now wire .OnUpdateAdd(HideSubtreeOnUpdate) to re-walk and re-Raw/untab the subtree on every update. Internal-only -> no public api.txt change.

M2 (alternative/test-coverage): the new Control.IsTabStop pool reset was untracked by the PoolResetSet convention. Add IsTabStop to PoolResetSetAnalyzer.TrappedProperties (it has an .IsTabStop modifier) and widen the consistency-test ClearValue regex to owner-qualified (FrameworkElement|UIElement|Control).XProperty on any receiver so it sees both the UIElement.IsHitTestVisible and Control.IsTabStop resets. IsHitTestVisible has no modifier -> documented in IntentionallyExcluded.

L1 (correctness): replace the deferred-hide IsHitTestVisible identity guard with a private attached sentinel (PendingDeferredHide) set in HideSubtreeOnMount and cleared on unmount (.OnUnmountAdd(ClearPendingHide)); ApplyDeferredHide now hides only when the sentinel is present, so a pre-load unmount can't poison a recycled interactive renter.

L2 (test-coverage): add TickLabelViewInteractiveToggle (X+Y tick hide + interactive remount) and LabelViewUpdateRehide (M1) selftests; rework LabelViewDeferredHideStaleGuard for the sentinel. M1 and L1 both verified red-on-revert.

Shared-a11y note: only additive touch remains the pie ChartPointDescriptor _labelName fallback (from the original fix) -- watch vs concurrent #633 descriptor work. No public API change; both reactor.api.txt copies unchanged (verified by ApiIndexGeneratorTests).

Co-authored-by: Copilot <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 18 out of 18 changed files in this pull request and generated no new comments.

@azchohfi
Alexandre Zollinger Chohfi (azchohfi) merged commit 7c7dc43 into main Jun 26, 2026
18 checks passed
@azchohfi
Alexandre Zollinger Chohfi (azchohfi) deleted the azchohfi-fix-chart-labelview-a11y-peers branch June 26, 2026 05:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Charts: double-announcement risk with custom LabelView / TickLabelView

2 participants