Add Tree component. (54)
Acceptance criteria:
- Build tests for a tree component that implements the SLDS pattern
- Build the tree component
- Add documentation https://github.com/salesforce-ux/design-system-react-site/issues/33
Future tasks: 4. Add a search / filter #317 5. Add the highlighting component when ready #251
Has anyone talked with Kyle Heldman's team about needing this for Setup?
Kyle's team also needs the component for Installed Packages within Setup. Development for Installed Packages has already started.
@pixelprodotco
SLDS for React tree prop API:
collection: React.PropTypes.oneOfType([
React.PropTypes.array,
React.PropTypes.object
]).isRequired,
autoOpen: React.PropTypes.bool,
autoOpenLimit: React.PropTypes.number,
heading: React.PropTypes.string,
id: React.PropTypes.string,
disabled: React.PropTypes.bool,
folderSelect: React.PropTypes.bool,
multiSelect: React.PropTypes.bool,
onChanged: React.PropTypes.func,
onClosed: React.PropTypes.func,
onOpened: React.PropTypes.func,
open: React.PropTypes.any,
selection: React.PropTypes.any
Selection, multi-select, folderSelect, autoOpen seem like app state engine tasks to me, now that jQuery isn't included. You'd just be manipulating the nodes tree with a new variable. We can enable the onClick for folders if we want to have a folders, but it seems like a better idea to just not have the selection changes in the onClick event.
- Does MVP need loading state for tree #319
- SLDS for React has a loading state (maybe part of
getNodes(node)and a prop like "load") - Do we need direction from SLDS? There is no documentation on website.
Do not implement autoOpen. Make an additional snippet that scans nodes datasource and creates expanded prop to be passed in.
Result of tree discussion @tweettypography / @interactivellama
Do not support: autoOpen autoOpenLimit disabled: do not implement disabled tree or disabled items, needs SLDS CSS folderSelect multiSelect onClosed onOpened
Do support:
- [x] open -> expanded - implement expanded via expanded prop and not node datasource
- [x] selection - - implement selection via selection prop and not node datasource (may later use datasource,
selectedkey - [x] getNodes - w/ Promise
- [x] onClick - would pass back all item keys from
nodesdata + current selection, and handler should handle folder or multiSelect if needed
If crutch is needed for features not supported, it will be provided in sample snippet or in extended component.
- [x] implement child component arrays with
shortidid
Update: getNodes as a promise has been removed.
Current state of Tree: https://github.com/interactivellama/design-system-react/tree/tree-component Not anywhere near a11y functional, nor complete testing, but just raising for transparency.
a11y links for reference:
- http://www.oaa-accessibility.org/examplep/treeview1/
- http://w3c.github.io/aria/practices/aria-practices.html#TreeView
- https://www.w3.org/WAI/GL/wiki/Using_aria-activedescendant_to_allow_changes_in_focus_within_widgets_to_be_communicated_to_Assistive_Technology https://www.marcozehe.de/2012/02/06/if-you-use-the-wai-aria-role-application-please-do-so-wisely/
MobileConnect squad has a need for this control as well. I'd be glad to help with getting this tested.
The need for infinite scroll/lazy load recently surfaced as a need and dependency for Kyle Heldman’s team.
@jamin-hall
How does infinite scroll work in a tree?
Are their 1000 branches and you only want to load 100 and then load the rest 10 at time?
@interactivellama One option: load each top level node up to X amount based on initial render performance (100?). As the node is expanded, render its children (either from existing data or via async call). Infinite scroll would be limited to just the top level nodes at that point.
I'm working on an alternative approach to how the tree is rendering at the moment. The version that existed when slds-for-react had a tree component has performance issues once the node count gets in the hundreds and above (thats including child nodes that may or may not be visible).
I'm in the process of removing promises as an option for the tree nodes and moving forward with a loading prop that will put the tree into a loading UI state until the app provide the new nodes.
Without promises as an option there would be no way to get children (from an async source) on expanding of a node, correct? Would the expectation be that something outside of the tree is building a static data source to pass in? Or am I missing something?
My question is why do we want a promise on the tree and not anywhere else? Do we have precedence for promises with our data props somewhere else?
The original need came from jQuery compatibility and backwards-compatibility with FuelUX, I believe. Neither of those are issues any longer, and it certainly does feel more react-like to simply throw an event and let the application take care of feeding in the new data. I could imagine that for very large, complex trees there might be some benefit to receiving the data back at the node level when it's ready so that you don't have to re-render the entire tree and add it back to the DOM, but I'm not sure that's even a relevant argument and would require some testing.
I'd be curious what solutions all of the other treeviews have come up with: https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=react%20treeview
IMHO, the path forward for infinite scroll is to pass scroll position of the ul element to the app and if it wants to load more nodes it can.
I've added an onScroll event that returns the percentage of the scroll.
Possible loading pattern:
