Skip to content

feat(ou-tree): keyboard, focus and ARIA: one tab stop, treeview keys, inner focus, searchbox - #1792

Open
HendrikThePendric wants to merge 49 commits into
feat/paged-org-unit-treefrom
feat/ou-tree-keyboard-focus
Open

HendrikThePendric wants to merge 49 commits into
feat/paged-org-unit-treefrom
feat/ou-tree-keyboard-focus

Conversation

@HendrikThePendric

@HendrikThePendric HendrikThePendric commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Implements DHIS2-21263 (client side, batch 5 of OuTree). Base: feat/paged-org-unit-tree, after batch 4 (#1787).


Description

OuTree is operable from the keyboard and correct for assistive technology. Still over the stand-in, still not exported. This resolves the Sonar accessibility findings from batch 4 and keeps the row container clear of the new ones.

Principles

  • The tree is one tab stop. Tab reaches the tree and Tab leaves it, in either direction; everything inside is reached with other keys. This is the W3C tree view pattern, and it keeps a tree of thousands of org units from becoming thousands of tab stops.
  • The container holds focus, the rows are named. DOM focus stays on the container, which names the active row with aria-activedescendant. Rows scroll out of the DOM under virtualisation, so they cannot hold focus themselves; the active row is kept in the rendered range wherever the viewport is, so the name always resolves. The active row shows the focus ring, the container none, and only for keyboard focus: a click focuses the row it lands in without a ring, as a button does.
  • Moving is the arrows, acting is Enter. Up and Down move between rows, Right and Left open, close and step between levels, Enter toggles. Space is reserved for selection (batch 6). No type-ahead: a paged tree does not know the names it has not loaded.
  • A row's actions are its controls, and the keyboard can reach them. The arrow is a button, the eye is a button, a retry is a button; a row takes no click of its own, the container does, focusing the row the click landed in. The label is a plain span until selection gives it something to do. Shift+Enter moves focus into the row's controls, Tab walks them and then leaves the tree as Tab does everywhere, Escape returns to the row; an entered control shows a ring of its own inside the row's. Precedent: the W3C grid and treegrid patterns for widgets inside a cell. Between rows it is always the arrows, whether focus is on the tree or inside a row. A control is an element that calls useOuTreeRowControl (exported) and spreads its props: the built-in ones do, and a custom label's control does the same to be reached the same way; nothing else in a row is one.
  • Everything has a name and a place. The tree is named (ariaLabel, "Organisation units" unless given, or ariaLabelledBy). A node row is named by its label alone, so the arrow's and the eye's names stay out of it; a failed node is described by its retry; skeleton rows are busy and say "Loading". Every row under a parent says its place among the siblings (aria-posinset of aria-setsize), from the slot count in browse mode and the matching children in search mode, -1 until every result arrived. Every row is aria-selected="false" until selection exists.
  • Focus is tree state, inner focus included. The active row, the entered control, whether the tree has focus and the moves live in the tree state, not in the DOM. Controls register with their row as they mount and unregister as they unmount, so the state knows a row's controls without querying and knows when one goes away; DOM focus follows the state through effects. The one exception is Tab past the last control, where the container is focused synchronously so the browser's own Tab leaves the tree.

Keyboard

With the tree focused:

Key Does
Tab, Shift+Tab Leaves the tree. Tab onto the tree lands on the row that was active, or the first visible one.
Down, Up Moves to the next or previous row, scrolling it into view.
Home, End Moves to the first or last row.
Right Opens a closed node; on an open node, moves to its first child.
Left Closes an open node; on a closed node or a leaf, moves to its parent.
Enter Toggles the node, which also retries a failed one. On a placeholder row, acts on its control (the retry).
Shift+Enter Moves focus into the row's first control: the arrow, the eye, a retry, or a custom label's control registered with useOuTreeRowControl. Rows with a control announce it as aria-keyshortcuts.
Space Nothing yet; reserved for selection.

Inside a row's controls, after Shift+Enter:

Key Does
Tab, Shift+Tab Moves to the next or previous control of the row. Past the last, or before the first, leaves the tree, as it does from the tree itself.
Enter, Space Acts on the control, which keeps focus. If the control goes away, like the arrow behind the loader, focus is back on the tree rather than lost to the page.
Escape Returns focus to the tree, on the same row.
Down, Up, Home, End, Right, Left Returns focus to the tree and moves, as above.

In the search input:

Key Does
Down Moves focus to the tree.
Escape Clears the search.

The mouse does not focus a row's controls (a click keeps focus on the tree), and the roots' retry while the roots failed stays in the Tab order, as it is not a tree row.

Implementation notes

  • Focus in the tree state. focusedKey with its last index as the fallback, hasFocus and focusVisible set by the glue (a key makes focus the keyboard's, a pointer makes it the pointer's, which shows no ring), the moves focusNext/focusPrevious/focusFirst/focusLast/focusParent/focusChild returning the new index so the list scrolls to it, and the focused row pinned into the virtualiser's range (rangeExtractor) and scrolled into view when focus arrives on the container. The eye sits in the row of every open node with matching children and is shown in CSS while the row is hovered or focused; row hover is not state. Hooks: useOuTreeNode adds isFocused; new useOuTreeRowFocused, useOuTreeRowElementId, useOuTreeFocusTarget, useOuTreeRegisterFocusTarget; useOuTreeKeyboard in the list.
  • Every row is a treeitem with an element id from the provider's treeId (unique per tree on the page). A node row is named by its label slot (aria-labelledby); a failed node's retry button is named "Could not load children. Retry" and is the row's aria-describedby. The row's controls register through useOuTreeRowControl, which hands back tabIndex=-1, the mouse-down guard and a ref; the registry (tree/row-controls.ts) reads a row's controls in DOM order when a move asks, disabled ones excluded, because controls mount late (the eye on focus, the arrow after the loader). An entered control focuses itself in an effect, and enters itself when focus arrives on it some other way; a key that leaves the row focuses the container at once; the container takes focus back in an effect when the entered control went away, since a removed element drops focus on the page body without a blur. Losing the tree's focus ends inner focus. Past the last control, Tab focuses the container and the browser's Tab goes on from there.
  • Rows carry their place. A node row is kind, id, depth, view and posInSet/setSize; the row component reads the rest through useOuTreeNode, and row reuse compares key, depth, view and place.
  • Search input. role="searchbox" (needs InputField to forward role: one prop added in @dhis2-ui/input, whose clear button also gets its name, "Clear", on the way).
  • Guide lines light up as branches, as in the old tree. Hover an indent segment or an open node's toggle and the whole branch lights up (grey500), click it to close the branch and focus its ancestor; the keyboard gets there with Left repeated. The focused row's parent branch is lit while the tree has focus, so arrowing through a deep branch shows which one you are in. A hover is reported left when its element unmounts under the pointer (useHoverReport), the arrow behind the loader included, so no branch stays lit.

Left for later: selection (next batch; the label becomes a control that selects, and it decides between Space on the row and a checkbox as an inner control).


Known issues

  • eslint's React Compiler warning on useVirtualizer remains, as in batch 3.

Checklist

  • API docs are generated (nothing is exported, so there is nothing to document)
  • Tests were added
  • Storybook demos were added (the key map in the OuTree description)

Screenshots

The Search story over the PAHO stand-in, searching clin: Catamarca focused from the keyboard with its eye; focus moved into the eye with Shift+Enter; End scrolled to the last row; a branch lit from its guide line.

🤖 Generated with Claude Code

HendrikThePendric and others added 14 commits November 17, 2026 18:07
…iew moves

A row key with its last index as the fallback, hasFocus set by the glue,
isFocused for rows, and focusNext/Previous/First/Last/Parent/Child
returning the new index. Every row is indexed by its key now.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
… one

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
… the provider

aria-activedescendant needs element ids unique per tree on the page, and
the search input needs a way to hand focus to the list's container.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…he click

Every row is a treeitem now, skeleton rows busy and labelled, error rows
labelled by their retry, each with an element id for
aria-activedescendant and the focus ring while focused. The row shell
takes the click, so the label and the toggle are plain spans; the eye and
the retry buttons leave the tab order, reached by the row's inner focus.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…s for a row's controls

The container is the tree's one tab stop and names the focused row with
aria-activedescendant; the arrows, Home and End move it, Right and Left
open, close and step between levels, Enter toggles. Shift+Enter moves
DOM focus into the row's first control, Tab cycles the row's controls
and Escape returns to the tree. Moves scroll the row into view.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Input already renders one; InputField did not pass it through, so an
InputField could not be a searchbox.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…and Escape clears

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…ads the rest from the tree

The children status and the result flag came off the store and the
search through the row; the row component already read them through
useOuTreeNode. Row reuse is now key, depth and view.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…e it was focused

Rows inserted above a focused row moved it; when its key then went, the
fallback index pointed at an unrelated row far above.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Only the toggle is skipped for a click that was a button's, so the eye
and the retry keep mouse and keyboard on the same row.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
With no rows, while the roots load or failed or a search has no results,
the tab stop was invisible.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…ght return from a control

Tab cycles only within a row entered from the tree (its controls have
tabIndex -1), so the roots retry, which is in the tab order, is left as
usual. Left and Right pressed inside a control return to the tree and
act. A move key without a focused row starts at the first visible row.
Enter on a row that is not a node clicks its control, the retry.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
… and closes it on click

The old tree's line was the ancestor's toggle, spanning its subtree:
hovering it lit the branch and clicking it collapsed the ancestor. The
flat list draws a segment per row, so a guide is tree state now: the
segment's ancestor and subtree are resolved once per change, each row
reads its lit level, and a click on a lit segment closes the branch and
focuses the ancestor. The focused row's parent branch is lit while the
tree has focus, so the keyboard shows the branch too.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@HendrikThePendric
HendrikThePendric requested a review from a team as a code owner November 18, 2026 08:11
@HendrikThePendric
HendrikThePendric changed the base branch from master to feat/paged-org-unit-tree November 18, 2026 08:12
HendrikThePendric and others added 6 commits November 18, 2026 09:23
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…the label

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
A literal tabIndex is what the activedescendant lint rule reads.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…tion exists

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…ol and the row's

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@dhis2-bot

Copy link
Copy Markdown
Contributor

🚀 Deployed on https://pr-1792--dhis2-ui.netlify.app

@dhis2-bot
dhis2-bot temporarily deployed to netlify November 18, 2026 08:32 Inactive
HendrikThePendric and others added 3 commits November 27, 2026 16:46
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…ntainer takes the click

A row's actions are its controls: the arrow joins the eye and the retries
as a button out of the tab order, named Expand or Collapse. The label is
a plain span until selection gives it something to do, and a click on a
row or its label only focuses the row. The row shell takes no click: the
container does, focusing the tree when focus was elsewhere and the row
the click landed in, by the virtual row's index.

The controls leave DOM focus on the tree: the mouse does not focus them,
and Enter or Space on an entered control acts on it from the tree, so a
control that goes away, like the arrow behind the loader, does not take
focus with it.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@dhis2-bot
dhis2-bot temporarily deployed to netlify November 30, 2026 11:49 Inactive
HendrikThePendric and others added 2 commits November 30, 2026 13:07
…ntrol

The container refocused itself only when DOM focus was outside the tree,
so a click on a control while focus sat in another row's entered control
left the keys acting on that stale control. The container now focuses
itself whenever it is not the active element, after focusing the clicked
row, and the focus handler reads the focused row live (getFocusedIndex
on the actions) rather than from the last render.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…r the pointer

An element removed under the pointer fires no pointerleave, so the arrow
clicked behind the loader left the node's guide lit until the pointer
crossed another guide, and a hovered row or segment scrolled out of the
virtual range left its hover state behind. useHoverReport tracks what is
under the pointer and reports the leave from its cleanup; the toggle and
the row shell, for the row and its segments, use it.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
HendrikThePendric and others added 10 commits November 30, 2026 13:12
…n the tree is focused

aria-activedescendant named a row the virtualiser had dropped once it
scrolled out of the range, so after a wheel scroll Enter and Shift+Enter
found no element and did nothing, assistive technology saw a tree with no
item, and a long jump named the row a frame before it existed. The
virtualiser's rangeExtractor now keeps the focused row in the rendered
range wherever the viewport is, and the pages are requested for the
viewport and its overscan, not for the pinned row. Focus arriving on the
container scrolls the focused row into view, as the aria-activedescendant
practice asks.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The tree view pattern requires a name on the element with role tree, and
the container had none, so a screen reader announced an unnamed tree. The
list and OuTree take ariaLabel, "Organisation units" unless given, or
ariaLabelledBy for a visible element that names the tree.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
… it could not load

A treeitem without a label of its own is named from its content, which
takes in the arrow button's name, so browsers announced rows as
"Collapse Zambia" and, focused in search mode, with the eye's name too.
A failed node was indistinguishable from a closed one: its retry button
was named by the label it wraps. The label slot is now an element,
OuTreeLabelSlot, with no box of its own, and the row's aria-labelledby
names it, with renderLabel content included; the retry button is named
"Could not load children. Retry" and the failed row's aria-describedby
names the button.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…reeRowFocused

The same subscription was written out twice.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The three rows each built the same two closures over the row key for the
shell's guide hover and click. The hook, which already has the key and
the tree, returns them, stable.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…lled

The click focuses a row by its index through focusRow; setFocused by key
stays on the tree state, for tests.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…the pinned focused row

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
… of aria-setsize

Browse mode has the count once a parent's first page arrived, the slots;
search mode counts the matching children, -1 until every result arrived,
as ARIA allows for a set of unknown size. Result placeholders carry no
place. The row carries both numbers, and row reuse compares them.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…then out of the tree

Past the last control, or before the first with Shift, the container is
focused and the browser's Tab goes on from it, out of the tree, as the
controls are not in the tab order. Tab no longer cycles within the row:
leaving the widget is what Tab does on a page, and rows are reached with
the arrow keys.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The clearable input's clear button had no accessible name: an icon only.
It is now labelled "Clear", through the package's locales like the
other icon buttons.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@dhis2-bot
dhis2-bot temporarily deployed to netlify November 30, 2026 15:25 Inactive
HendrikThePendric and others added 2 commits November 30, 2026 16:40
The element every row sits in wraps a row's content as the tree container
wraps the rows: one word for one job, at two levels.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The keyboard hook found a row's controls by what was focusable and told
"entered from the tree" from "in the page's tab order" by the tab index.
Now a control is marked: rowControlProps carries data-ou-tree-control,
tabIndex -1 and the mouse-down guard, the built-in controls spread it,
and a custom label spreads it on a control of its own to be reached the
same way, with Shift+Enter and Tab. The hook finds controls by the
attribute, disabled ones excluded, and nothing unmarked is one.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@dhis2-bot
dhis2-bot temporarily deployed to netlify November 30, 2026 16:13 Inactive
HendrikThePendric and others added 9 commits November 30, 2026 17:22
…config

Generated by yarn setup for the new components/input/i18n/en.pot; CI checks
the committed file against the generated one.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…side the row's

The arrow, the eye and the retry buttons had only the browser's default
focus outline, which read as a second border on the row. Each now has a
focus style separate from its hover: an inset ring in the focus blue.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
… entered one

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…ls is entered

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…nd focuses it in turn

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…wControl

The arrow, the eye and the retry buttons spread the hook's props; the rows
provide their key to it. The roots' retry stays a plain tab stop outside
any row. The keyboard hook finds controls by their tab index until the
tree state hands them over.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…cus follows

Shift+Enter enters the focused row's first control, Tab and Shift+Tab move
along them in DOM order and past the ends leave the tree, Escape leaves
the row, Enter and Space act on the control, which keeps focus. A control
that goes away hands focus back to the container through its
unregistration, as an effect, not a timer. A click inside the entered
control keeps it entered; any other click focuses its row and the tree.
The keyboard hook no longer queries the DOM for controls.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…s it

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…ee ends inner focus

The container took focus from a tabbable retry, or a control, that focus
reached from outside the tree: the recovery effect now acts only when
focus left the container, as it does when the entered control went
away, and a key that leaves the row focuses the container itself. A
control entered when the tree lost focus stayed entered, so Shift+Enter
on return did nothing: losing the tree's focus now ends inner focus, and
focus arriving on a control from outside the keys enters it.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@dhis2-bot
dhis2-bot temporarily deployed to netlify December 1, 2026 09:31 Inactive
HendrikThePendric and others added 2 commits December 1, 2026 11:26
…r focused, not by state

The eye sits in the row of every open node with matching children, marked
data-hover-only, which the row container shows while hovered or focused.
setHovered, isHovered and the row's hover report go; useHoverReport stays
for the guide segments and the toggle.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The controls register with a row since they took useOuTreeRowControl,
so the stories that show them alone give them one. The eye's caption
says the row shows it.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@dhis2-bot
dhis2-bot temporarily deployed to netlify December 1, 2026 10:35 Inactive
…ick shows none

The glue tracks whether focus is the keyboard's (focusVisible in the tree
state): a key makes it so, a pointer down or the click hook's focus makes
it the pointer's, and the ring, the eye on focus and the lit parent branch
follow. Focus arriving by Tab counts as the keyboard's.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@sonarqubecloud

sonarqubecloud Bot commented Dec 2, 2026

Copy link
Copy Markdown

This branch was successfully deployed

1 active deployment
netlify — 99793fc2 Deployed Dec 2, 2026 by dhis2-bot
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