Skip to content

fix(docs): make the TreeView Custom onAction example selectable and non-disruptive - #2520

Open
mateoviilla1 wants to merge 1 commit into
developfrom
fix/2519-custom-onaction-example
Open

fix(docs): make the TreeView Custom onAction example selectable and non-disruptive#2520
mateoviilla1 wants to merge 1 commit into
developfrom
fix/2519-custom-onaction-example

Conversation

@mateoviilla1

@mateoviilla1 mateoviilla1 commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes the Custom onAction TreeView example, which had two problems reported
in an accessibility pass (#2519). Both were in the example itself — no component
change.

The two issues

Additional checkboxes could not be selected. The example rendered checkboxes
but ran in selectionMode="single", so selecting a second item silently cleared
the first. With a checkbox affordance that reads as "nothing happened". It now
uses selectionMode="multiple", which matches what the checkboxes imply.

Activating an item opened an unannounced dialog. The handler called
window.alert. A modal dialog on a checkbox toggle is an unannounced context
change, which is disorienting for keyboard and screen reader users. The handler
now writes into a role="status" region, so the action is announced without
stealing focus.

const [lastAction, setLastAction] = useState(null);

<TreeView selectionMode="multiple" onAction={setLastAction} items={items} />
<p role="status">
  {lastAction ? `Last action: item ${lastAction}` : 'No action yet.'}
</p>

alert() is used in other docs examples (e.g. ActionMenu), and that is fine
there — the affordance is a menu item, where activating is expected to do
something. On a checkbox it is not.

Notes

Testing

  • Docs build (NODE_ENV=production webpack --bail) passes.
  • Verified locally: checkboxes now toggle independently, and the status line
    updates without a dialog.

QA notes: on TreeView → Custom onAction, confirm several checkboxes can be
checked at once and that activating an item updates the status line instead of
opening a pop-up.

Ref #2519

…on-disruptive

The example rendered checkboxes but ran in `selectionMode="single"`, so
selecting a second item silently cleared the first — it read as "no further
checkboxes can be selected". Checkboxes imply independent selection, so the
example now uses `selectionMode="multiple"` to match its own affordance.

Activating an item also fired a `window.alert`. A modal dialog on a checkbox
toggle is an unannounced context change, which is disorienting for keyboard and
screen reader users. The handler now writes to a `role="status"` region instead,
so the action is announced without stealing focus.
Copilot AI lite review requested due to automatic review settings September 1, 2026 21:17
@mateoviilla1
mateoviilla1 requested a review from a team as a code owner September 1, 2026 21:17

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

Updates the TreeView documentation’s Custom onAction example to align behavior with its checkbox UI and to avoid disruptive modal dialogs during interaction, addressing the a11y issues reported in #2519 without changing the TreeView component itself.

Changes:

  • Import useState in the MDX module so the live example can track action state.
  • Update the “Custom onAction” example to use selectionMode="multiple" so multiple checkboxes can be selected.
  • Replace window.alert with a role="status" region that announces the last activated item without stealing focus.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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.

2 participants