@@ -20,8 +20,9 @@ import {
20
20
import { text } from '../../../shared/text' ;
21
21
import { OpossumColors } from '../../shared-styles' ;
22
22
import { useVirtuosoRefs } from '../../util/use-virtuoso-refs' ;
23
+ import { EmptyPlaceholder } from '../EmptyPlaceholder/EmptyPlaceholder' ;
23
24
import { LoadingMask } from '../LoadingMask/LoadingMask' ;
24
- import { NoResults } from '../NoResults/NoResults ' ;
25
+ import { VirtuosoComponentContext } from '../VirtuosoComponentContext/VirtuosoComponentContext ' ;
25
26
import { GroupContainer , StyledLinearProgress } from './GroupedList.style' ;
26
27
27
28
export interface GroupedListItemContentProps {
@@ -53,6 +54,7 @@ export function GroupedList({
53
54
selectedId,
54
55
sx,
55
56
testId,
57
+ components,
56
58
...props
57
59
} : GroupedListProps & Omit < GroupedVirtuosoProps < string , unknown > , 'selected' > ) {
58
60
const [ { startIndex, endIndex } , setRange ] = useState < {
@@ -80,6 +82,7 @@ export function GroupedList({
80
82
focusedIndex,
81
83
setIsVirtuosoFocused,
82
84
selectedIndex,
85
+ isVirtuosoFocused,
83
86
} = useVirtuosoRefs < GroupedVirtuosoHandle > ( {
84
87
data : groups ?. ids ,
85
88
selectedId,
@@ -94,37 +97,42 @@ export function GroupedList({
94
97
>
95
98
{ loading && < StyledLinearProgress data-testid = { 'loading' } /> }
96
99
{ groups && (
97
- < GroupedVirtuoso
98
- ref = { ref }
99
- onFocus = { ( ) => setIsVirtuosoFocused ( true ) }
100
- onBlur = { ( ) => setIsVirtuosoFocused ( false ) }
101
- components = { {
102
- EmptyPlaceholder :
103
- loading || groups . ids . length ? undefined : ( ) => < NoResults /> ,
104
- } }
105
- scrollerRef = { scrollerRef }
106
- rangeChanged = { setRange }
107
- groupCounts = { groups ?. counts }
108
- groupContent = { ( index ) => (
109
- < GroupContainer role = { 'group' } >
110
- < MuiBox sx = { { display : 'flex' } } >
111
- { renderJumpUp ( index ) }
112
- { renderJumpDown ( index ) }
113
- </ MuiBox >
114
- { renderGroupName ?.( groups . keys [ index ] ) || (
115
- < MuiBox sx = { { flex : 1 } } />
116
- ) }
117
- </ GroupContainer >
118
- ) }
119
- itemContent = { ( index ) =>
120
- renderItemContent ( groups . ids [ index ] , {
121
- index,
122
- selected : index === selectedIndex ,
123
- focused : index === focusedIndex ,
124
- } )
125
- }
126
- { ...props }
127
- />
100
+ // Virtuoso components must not be inlined: https://github.com/petyosi/react-virtuoso/issues/566
101
+ < VirtuosoComponentContext . Provider
102
+ value = { { isVirtuosoFocused, loading } }
103
+ >
104
+ < GroupedVirtuoso
105
+ ref = { ref }
106
+ onFocus = { ( ) => setIsVirtuosoFocused ( true ) }
107
+ onBlur = { ( ) => setIsVirtuosoFocused ( false ) }
108
+ components = { {
109
+ EmptyPlaceholder,
110
+ ...components ,
111
+ } }
112
+ scrollerRef = { scrollerRef }
113
+ rangeChanged = { setRange }
114
+ groupCounts = { groups ?. counts }
115
+ groupContent = { ( index ) => (
116
+ < GroupContainer role = { 'group' } >
117
+ < MuiBox sx = { { display : 'flex' } } >
118
+ { renderJumpUp ( index ) }
119
+ { renderJumpDown ( index ) }
120
+ </ MuiBox >
121
+ { renderGroupName ?.( groups . keys [ index ] ) || (
122
+ < MuiBox sx = { { flex : 1 } } />
123
+ ) }
124
+ </ GroupContainer >
125
+ ) }
126
+ itemContent = { ( index ) =>
127
+ renderItemContent ( groups . ids [ index ] , {
128
+ index,
129
+ selected : index === selectedIndex ,
130
+ focused : index === focusedIndex ,
131
+ } )
132
+ }
133
+ { ...props }
134
+ />
135
+ </ VirtuosoComponentContext . Provider >
128
136
) }
129
137
</ LoadingMask >
130
138
) ;
0 commit comments