210 points · by jameskerr · 4y ago · 53 comments
W3C has some in-depth list of expected keyboard interactions, though I'm not sure how complete they are:
https://w3c.github.io/aria-practices/#TreeView
https://w3c.github.io/aria-practices/examples/treeview/treev...
I ask because I've tried to implement a [TreeGrid](https://w3c.github.io/aria-practices/#treegrid) myself before and... it's a lot of work. I'd love an accessible, keyboard-friendly React tree :).
"React Aria provides accessibility and behavior according to WAI-ARIA Authoring Practices, including full screen reader and keyboard navigation support. All components have been tested across a wide variety of screen readers and devices to ensure the best experience possible for all users."
If that's the standard for open-source projects, it's a wonder any FE components get used
My favorite is the Tree Table
My first thought - how React Arborist is different from Ant Tree? https://ant.design/components/tree/
React Arborist dependencies looks sane https://github.com/brimdata/react-arborist/blob/main/package...
"memoize-one": "^6.0.0", "react-dnd": "^14.0.3", "react-dnd-html5-backend": "^14.0.1", "react-window": "^1.8.6"
However I was never a fan of react-dnd. Extremely hard to reason about react-dnd-html5-backend and spagetti code once you face edge scenarios.
Hard coded css means I need to fork the library
https://github.com/brimdata/react-arborist/blob/main/package...
const style: CSSProperties = {
position: "absolute",
pointerEvents: "none",
top: top - 2 + "px",
left: treeView.indent + left + "px",
right: treeView.indent + "px",
};I agree that the hard-coded DefaultCursor styles need to be configurable. I'll soon update. You'll be able to pass in your own component to render the DropCursor (blue line indicating the new position of the node you're dragging).
Jokes apart, nice library. Will try it out sooner or later. May I suggest to not use children as the prop to Ps the Node component? Maybe a more explicit NodeComponent prop would have been better imho.
This is the approach used by most headless projects such has headless ui or radix.
Hey, since you get to decide the structure yourself, I’m sure you could use that to draw a real tree using SVG.
https://github.com/mozilla/gecko-dev/tree/master/devtools/cl...
It's based on React, but also uses require.js for its dependencies from other parts of Devtools, like TreeView - so it looks tough to separate into an independent component.
I was thinking of making a generic tree manager class to provide basic functions (move, rename, add, delete) for managing the tree data structure in the parent component. Maybe I'll call it "Arborist"!
<Tree children={Node} />