- 
                Notifications
    
You must be signed in to change notification settings  - Fork 1.3k
 
feat: add support for tree sections #9013
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
473d209
              e896397
              c3385c1
              fb17656
              a1c8b17
              89df42f
              8491826
              6f78fe7
              43f2895
              99d4169
              049f2a5
              fce9dce
              f138f6a
              900d69e
              ae36ec5
              cff1b4c
              e6752ca
              fb703b2
              98289ce
              ed55388
              3facc4a
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -11,7 +11,8 @@ | |
| */ | ||
| 
     | 
||
| import {chain, getScrollParent, mergeProps, scrollIntoViewport, useSlotId, useSyntheticLinkProps} from '@react-aria/utils'; | ||
| import {DOMAttributes, FocusableElement, Key, RefObject, Node as RSNode} from '@react-types/shared'; | ||
| import {Collection, DOMAttributes, FocusableElement, Key, RefObject, Node as RSNode} from '@react-types/shared'; | ||
| import {CollectionNode} from '@react-aria/collections'; | ||
| import {focusSafely, getFocusableTreeWalker} from '@react-aria/focus'; | ||
| import {getRowId, listMap} from './utils'; | ||
| import {HTMLAttributes, KeyboardEvent as ReactKeyboardEvent, useRef} from 'react'; | ||
| 
          
            
          
           | 
    @@ -100,11 +101,11 @@ export function useGridListItem<T>(props: AriaGridListItemOptions, state: ListSt | |
| 
     | 
||
| let isExpanded = hasChildRows ? state.expandedKeys.has(node.key) : undefined; | ||
| let setSize = 1; | ||
| if (node.level > 0 && node?.parentKey != null) { | ||
| if (node.level >= 0 && node?.parentKey != null) { | ||
| let parent = state.collection.getItem(node.parentKey); | ||
| if (parent) { | ||
| // siblings must exist because our original node exists | ||
| let siblings = state.collection.getChildren?.(parent.key)!; | ||
| let siblings = getDirectChildren(parent as CollectionNode<T>, state.collection as Collection<CollectionNode<T>>); | ||
| setSize = [...siblings].filter(row => row.type === 'item').length; | ||
| } | ||
| } else { | ||
| 
          
            
          
           | 
    @@ -324,3 +325,13 @@ function last(walker: TreeWalker) { | |
| } while (last); | ||
| return next; | ||
| } | ||
| 
     | 
||
| function getDirectChildren<T>(parent: CollectionNode<T>, collection: Collection<CollectionNode<T>>) { | ||
| let node = parent?.firstChildKey != null ? collection.getItem(parent.firstChildKey) : null; | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this only works with new collections (that's why it required a type cast above)? Maybe ok because we currently only implement Tree in RAC, not directly via hooks, but if someone did that this wouldn't work. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh true. i guess i could maybe do some type guarding and have some different logic if it's Node and not a CollectionNode? kinda unfortunate that we can't use getChildren here anymore tho  | 
||
| let siblings: CollectionNode<T>[] = []; | ||
| while (node) { | ||
| siblings.push(node); | ||
| node = node.nextKey != null ? collection.getItem(node.nextKey) : null; | ||
| } | ||
| return siblings; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we used to use the
getChildrenmethod fromTreeCollectionbut now that we've changed it to get ALL the descendants of a parent node instead of its immediate descendants, we can't use that anymore. i decided to make a new function calledgetDirectChildrenwhich is essentially the same code as whatgetChildrenwas before