Repository navigation
fix(TreeList): respect consumer onKeyDown preventDefault cancellation - #5606
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR Modified ComponentsTreeList (@astryxdesign/core) · View in Storybook
Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Visual Regression12 added · 0 removed. View the report A repository maintainer can accept these exact frames: Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
cixzhang
left a comment
There was a problem hiding this comment.
Thanks for fixing the cancellation order. One compatibility issue remains: a builder's onKeyDown now receives the inner <ul> as event.currentTarget, although TreeListProps and the ref promise the root <div> (TreeList.tsx:356). Chromium and a focused test confirm event.currentTarget !== ref.current. Please preserve the root handler contract while letting consumers cancel built-in tree navigation, and assert both cancellation and currentTarget === ref.current. If you'd rather talk it through with someone, we're in Discord.
[Reviewed by Robohands]
… currentTarget === ref.current
cixzhang
left a comment
There was a problem hiding this comment.
Thanks, the root currentTarget contract is fixed, but moving TreeList’s internal keyboard handler to the root also captures keys from the public header slot. In Chromium at this head, focusing a header button and pressing ArrowDown moves focus to the first tree item; the pre-PR base leaves focus on the button. Please keep internal tree navigation scoped to events originating inside ul[role="tree"] while preserving the root consumer handler and its preventDefault() cancellation. If you’d rather talk it through with someone, we’re in Discord.
[Reviewed by Robohands]
…nating inside ul role=tree
cixzhang
left a comment
There was a problem hiding this comment.
Thanks, this now preserves the root handler contract, consumer cancellation, and header keyboard behavior. Please update the stale <ul>/composeEventHandlers changeset wording before merge.
[Reviewed by Robohands]
…onKeyDown handling
|
done, updated the changeset as requested! |
cixzhang
left a comment
There was a problem hiding this comment.
Thanks, canceled keys now keep focus in place while preserving the root currentTarget, normal tree navigation, and header behavior. The changeset matches the implementation.
[Reviewed by Robohands]
|
/accept-visual 33753971655/1 All 12 exact-head TreeList baseline frames render the intended unchanged hierarchy across the six light/dark themes; the PR changes keyboard event handling, not appearance. |
|
Visual acceptance refused: the pull request is not open against |
…#5606) * fix(TreeList): respect consumer onKeyDown preventDefault cancellation * docs(changeset): add author tag @Geervan to TreeList changeset * fix(TreeList): bind onKeyDown to root div and assert cancellation and currentTarget === ref.current * fix(TreeList): scope internal tree navigation to keydown events originating inside ul role=tree * docs(changeset): update TreeList changeset to reflect root container onKeyDown handling
Resolved conflicts:
- packages/core/src/TreeList/TreeList.test.tsx: both sides appended tests at
the end of the top-level describe('TreeList'). Kept both: this branch's
describe('renderExpandIcon') block (with its closing brace), followed by
upstream's three consumer onKeyDown tests (meta#5606).
TreeList.tsx, TreeListItem.tsx, TreeListTypes.ts and TreeList.doc.mjs
auto-merged; the merged diff against upstream/main is only this PR's delta.



Fixes #5584
A builder using
TreeList's acceptedonKeyDownprop to intercept or reserve specific keys (such asArrowDown,ArrowUp, orEnter) could not cancel the built-in WAI-ARIA tree keyboard navigation.Calling
event.preventDefault()inonKeyDownexecuted and type-checked without warning, but focus and rovingtabindexmoved to the adjacent tree item anyway. This broke the standard React component event contract and prevented applications from implementing custom keyboard shortcuts or drag-and-drop reordering without triggering unwanted list navigation.Root Cause
In
TreeList.tsx,...restPropsplaced consumer attributes (includingonKeyDown) onto the outer<div class="astryx-tree-list">wrapper, while internal APG keyboard navigation (handleKeyDownfromuseTreeFocus) was attached to the inner<ul role="tree">.Because DOM keyboard events originate on
<li role="treeitem">elements inside the<ul>, event bubbling delivered the event to<ul role="tree">first.useTreeFocusupdatedtabindexand called.focus()on the target item before the event bubbled up to the outer<div>. By the time the consumer'sonKeyDownexecutedevent.preventDefault(), focus had already jumped.Solution
onKeyDown: DestructuredonKeyDownfromTreeListPropsand composed it directly on<ul role="tree">usingcomposeEventHandlers(onKeyDownProp, handleKeyDown).composeEventHandlersinvokes the consumer'sonKeyDownfirst. Ifevent.preventDefault()is called,composeEventHandlershalts execution beforehandleKeyDownruns, keeping focus and rovingtabindexlocked on the active item.onKeyDownProp as unknown as React.KeyboardEventHandler<HTMLUListElement>) to resolve TypeScript element type mismatches betweenHTMLDivElementprops andHTMLUListElementlisteners.Verification
TreeList.test.tsxverifying:event.preventDefault()blocks built-in navigation and preserves active item focus/tabindex.onKeyDownhandlers still fire alongside built-in keyboard navigation.83/83tests passing).Changeset
Added patch changeset
.changeset/treelist-onkeydown-cancellation.mdfor@astryxdesign/core.