@@ -20,7 +20,7 @@ import {DisabledBehavior, DragPreviewRenderer, Expandable, forwardRefType, Hover
20
20
import { DragAndDropContext , DropIndicatorContext , useDndPersistedKeys , useRenderDropIndicator } from './DragAndDrop' ;
21
21
import { DragAndDropHooks } from './useDragAndDrop' ;
22
22
import { DraggableCollectionState , DroppableCollectionState , Collection as ICollection , Node , SelectionBehavior , TreeState , useTreeState } from 'react-stately' ;
23
- import { filterDOMProps , inertValue , LoadMoreSentinelProps , UNSTABLE_useLoadMoreSentinel , useObjectRef } from '@react-aria/utils' ;
23
+ import { filterDOMProps , useObjectRef } from '@react-aria/utils' ;
24
24
import React , { createContext , ForwardedRef , forwardRef , JSX , ReactNode , useContext , useEffect , useMemo , useRef , useState } from 'react' ;
25
25
import { TreeDropTargetDelegate } from './TreeDropTargetDelegate' ;
26
26
import { useControlledState } from '@react-stately/utils' ;
@@ -196,7 +196,7 @@ function TreeInner<T extends object>({props, collection, treeRef: ref}: TreeInne
196
196
let hasDropHooks = ! ! dragAndDropHooks ?. useDroppableCollectionState ;
197
197
let dragHooksProvided = useRef ( hasDragHooks ) ;
198
198
let dropHooksProvided = useRef ( hasDropHooks ) ;
199
-
199
+
200
200
useEffect ( ( ) => {
201
201
if ( dragHooksProvided . current !== hasDragHooks ) {
202
202
console . warn ( 'Drag hooks were provided during one render, but not another. This should be avoided as it may produce unexpected behavior.' ) ;
@@ -701,87 +701,51 @@ export const TreeItem = /*#__PURE__*/ createBranchComponent('item', <T extends o
701
701
) ;
702
702
} ) ;
703
703
704
- export interface UNSTABLE_TreeLoadingSentinelRenderProps extends Pick < TreeItemRenderProps , 'isFocused' | 'isFocusVisible' > {
704
+ export interface UNSTABLE_TreeLoadingIndicatorRenderProps {
705
705
/**
706
706
* What level the tree item has within the tree.
707
707
* @selector [data-level]
708
708
*/
709
709
level : number
710
710
}
711
711
712
- export interface TreeLoadingSentinelProps extends Omit < LoadMoreSentinelProps , 'collection' > , RenderProps < UNSTABLE_TreeLoadingSentinelRenderProps > {
713
- /**
714
- * The load more spinner to render when loading additional items.
715
- */
716
- children ?: ReactNode | ( ( values : UNSTABLE_TreeLoadingSentinelRenderProps & { defaultChildren : ReactNode | undefined } ) => ReactNode ) ,
717
- /**
718
- * Whether or not the loading spinner should be rendered or not.
719
- */
720
- isLoading ?: boolean
721
- }
712
+ export interface TreeLoaderProps extends RenderProps < UNSTABLE_TreeLoadingIndicatorRenderProps > , StyleRenderProps < UNSTABLE_TreeLoadingIndicatorRenderProps > { }
722
713
723
- export const UNSTABLE_TreeLoadingSentinel = createLeafComponent ( 'loader' , function TreeLoadingSentinel < T extends object > ( props : TreeLoadingSentinelProps , ref : ForwardedRef < HTMLDivElement > , item : Node < T > ) {
714
+ export const UNSTABLE_TreeLoadingIndicator = createLeafComponent ( 'loader' , function TreeLoader < T extends object > ( props : TreeLoaderProps , ref : ForwardedRef < HTMLDivElement > , item : Node < T > ) {
724
715
let state = useContext ( TreeStateContext ) ! ;
725
- let { isLoading, onLoadMore, scrollOffset, ...otherProps } = props ;
726
- let sentinelRef = useRef ( null ) ;
727
- let memoedLoadMoreProps = useMemo ( ( ) => ( {
728
- onLoadMore,
729
- // TODO: this collection will update anytime a row is expanded/collapsed becaused the flattenedRows will change.
730
- // This means onLoadMore will trigger but that might be ok cause the user should have logic to handle multiple loadMore calls
731
- collection : state ?. collection ,
732
- sentinelRef,
733
- scrollOffset
734
- } ) , [ onLoadMore , scrollOffset , state ?. collection ] ) ;
735
- UNSTABLE_useLoadMoreSentinel ( memoedLoadMoreProps , sentinelRef ) ;
736
-
737
- ref = useObjectRef < HTMLDivElement > ( ref ) ;
738
- let { rowProps, gridCellProps, ...states } = useTreeItem ( { node : item } , state , ref ) ;
716
+ // This loader row is is non-interactable, but we want the same aria props calculated as a typical row
717
+ // @ts -ignore
718
+ let { rowProps} = useTreeItem ( { node : item } , state , ref ) ;
739
719
let level = rowProps [ 'aria-level' ] || 1 ;
740
720
741
721
let ariaProps = {
742
- role : 'row' ,
743
722
'aria-level' : rowProps [ 'aria-level' ] ,
744
723
'aria-posinset' : rowProps [ 'aria-posinset' ] ,
745
- 'aria-setsize' : rowProps [ 'aria-setsize' ] ,
746
- tabIndex : rowProps . tabIndex
724
+ 'aria-setsize' : rowProps [ 'aria-setsize' ]
747
725
} ;
748
726
749
- let { isFocusVisible, focusProps} = useFocusRing ( ) ;
750
-
751
727
let renderProps = useRenderProps ( {
752
- ...otherProps ,
728
+ ...props ,
753
729
id : undefined ,
754
730
children : item . rendered ,
755
731
defaultClassName : 'react-aria-TreeLoader' ,
756
732
values : {
757
- level,
758
- isFocused : states . isFocused ,
759
- isFocusVisible
733
+ level
760
734
}
761
735
} ) ;
762
736
763
737
return (
764
738
< >
765
- { /* Alway render the sentinel. For now onus is on the user for styling when using flex + gap (this would introduce a gap even though it doesn't take room) */ }
766
- { /* @ts -ignore - compatibility with React < 19 */ }
767
- < div style = { { position : 'relative' , width : 0 , height : 0 } } inert = { inertValue ( true ) } >
768
- < div data-testid = "loadMoreSentinel" ref = { sentinelRef } style = { { position : 'absolute' , height : 1 , width : 1 } } />
769
- </ div >
770
- { isLoading && renderProps . children && (
771
- < div
772
- ref = { ref }
773
- { ...mergeProps ( filterDOMProps ( props as any ) , ariaProps , focusProps ) }
774
- { ...renderProps }
775
- data-key = { rowProps [ 'data-key' ] }
776
- data-collection = { rowProps [ 'data-collection' ] }
777
- data-focused = { states . isFocused || undefined }
778
- data-focus-visible = { isFocusVisible || undefined }
779
- data-level = { level } >
780
- < div { ...gridCellProps } >
781
- { renderProps . children }
782
- </ div >
739
+ < div
740
+ role = "row"
741
+ ref = { ref }
742
+ { ...mergeProps ( filterDOMProps ( props as any ) , ariaProps ) }
743
+ { ...renderProps }
744
+ data-level = { level } >
745
+ < div role = "gridcell" aria-colindex = { 1 } >
746
+ { renderProps . children }
783
747
</ div >
784
- ) }
748
+ </ div >
785
749
</ >
786
750
) ;
787
751
} ) ;
@@ -834,10 +798,9 @@ function flattenTree<T>(collection: TreeCollection<T>, opts: TreeGridCollectionO
834
798
keyMap . set ( node . key , node as CollectionNode < T > ) ;
835
799
}
836
800
837
- // Grab the modified node from the key map so our flattened list and modified key map point to the same nodes
838
- let modifiedNode = keyMap . get ( node . key ) || node ;
839
- if ( modifiedNode . level === 0 || ( modifiedNode . parentKey != null && expandedKeys . has ( modifiedNode . parentKey ) && flattenedRows . find ( row => row . key === modifiedNode . parentKey ) ) ) {
840
- flattenedRows . push ( modifiedNode ) ;
801
+ if ( node . level === 0 || ( parentKey != null && expandedKeys . has ( parentKey ) && flattenedRows . find ( row => row . key === parentKey ) ) ) {
802
+ // Grab the modified node from the key map so our flattened list and modified key map point to the same nodes
803
+ flattenedRows . push ( keyMap . get ( node . key ) || node ) ;
841
804
}
842
805
} else if ( node . type !== null ) {
843
806
keyMap . set ( node . key , node as CollectionNode < T > ) ;
@@ -951,5 +914,3 @@ function RootDropIndicator() {
951
914
</ div >
952
915
) ;
953
916
}
954
-
955
-
0 commit comments