@@ -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,45 @@ 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 /> ,
100
+ // Virtuoso components must not be inlined: https://github.com/petyosi/react-virtuoso/issues/566
101
+ < VirtuosoComponentContext . Provider
102
+ value = { {
103
+ isVirtuosoFocused,
104
+ showNoResults : ! loading && ! groups . ids . length ,
104
105
} }
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
- />
106
+ >
107
+ < GroupedVirtuoso
108
+ ref = { ref }
109
+ onFocus = { ( ) => setIsVirtuosoFocused ( true ) }
110
+ onBlur = { ( ) => setIsVirtuosoFocused ( false ) }
111
+ components = { {
112
+ EmptyPlaceholder,
113
+ ...components ,
114
+ } }
115
+ scrollerRef = { scrollerRef }
116
+ rangeChanged = { setRange }
117
+ groupCounts = { groups ?. counts }
118
+ groupContent = { ( index ) => (
119
+ < GroupContainer role = { 'group' } >
120
+ < MuiBox sx = { { display : 'flex' } } >
121
+ { renderJumpUp ( index ) }
122
+ { renderJumpDown ( index ) }
123
+ </ MuiBox >
124
+ { renderGroupName ?.( groups . keys [ index ] ) || (
125
+ < MuiBox sx = { { flex : 1 } } />
126
+ ) }
127
+ </ GroupContainer >
128
+ ) }
129
+ itemContent = { ( index ) =>
130
+ renderItemContent ( groups . ids [ index ] , {
131
+ index,
132
+ selected : index === selectedIndex ,
133
+ focused : index === focusedIndex ,
134
+ } )
135
+ }
136
+ { ...props }
137
+ />
138
+ </ VirtuosoComponentContext . Provider >
128
139
) }
129
140
</ LoadingMask >
130
141
) ;
0 commit comments