@@ -18,7 +18,7 @@ import { PlacementType } from '@ui5/webcomponents-react/lib/PlacementType';
18
18
import { Popover } from '@ui5/webcomponents-react/lib/Popover' ;
19
19
import { PopoverHorizontalAlign } from '@ui5/webcomponents-react/lib/PopoverHorizontalAlign' ;
20
20
import { StandardListItem } from '@ui5/webcomponents-react/lib/StandardListItem' ;
21
- import React , { CSSProperties , forwardRef , RefObject , useCallback } from 'react' ;
21
+ import React , { CSSProperties , RefObject , useCallback , useEffect , useRef } from 'react' ;
22
22
import { createPortal } from 'react-dom' ;
23
23
import { Ui5PopoverDomRef } from '../../../interfaces/Ui5PopoverDomRef' ;
24
24
import { stopPropagation } from '../../../internal/stopPropagation' ;
@@ -28,16 +28,21 @@ export interface ColumnHeaderModalProperties {
28
28
column : ColumnType ;
29
29
onSort ?: ( e : CustomEvent < { column : unknown ; sortDirection : string } > ) => void ;
30
30
onGroupBy ?: ( e : CustomEvent < { column : unknown ; isGrouped : boolean } > ) => void ;
31
+ open : boolean ;
32
+ setPopoverOpen : ( open : boolean ) => void ;
33
+ targetRef : RefObject < any > ;
31
34
}
32
35
33
36
const staticStyle = { fontWeight : 'normal' } ;
34
37
35
- export const ColumnHeaderModal = forwardRef ( ( props : ColumnHeaderModalProperties , ref : RefObject < Ui5PopoverDomRef > ) => {
36
- const { column, onSort, onGroupBy } = props ;
38
+ export const ColumnHeaderModal = ( props : ColumnHeaderModalProperties ) => {
39
+ const { column, onSort, onGroupBy, open , setPopoverOpen , targetRef } = props ;
37
40
const showFilter = column . canFilter ;
38
41
const showGroup = column . canGroupBy ;
39
42
const showSort = column . canSort ;
40
43
44
+ const ref = useRef < Ui5PopoverDomRef > ( null ) ;
45
+
41
46
const { Filter } = column ;
42
47
43
48
const [ clearSortingText , sortAscendingText , sortDescendingText , groupText , ungroupText ] = useI18nText (
@@ -110,14 +115,34 @@ export const ColumnHeaderModal = forwardRef((props: ColumnHeaderModalProperties,
110
115
const isSortedAscending = column . isSorted && column . isSortedDesc === false ;
111
116
const isSortedDescending = column . isSorted && column . isSortedDesc === true ;
112
117
118
+ useEffect ( ( ) => {
119
+ const popoverInstance = ref . current ;
120
+ if ( open ) {
121
+ popoverInstance ?. openBy ( targetRef . current ) ;
122
+ }
123
+ return ( ) => {
124
+ popoverInstance ?. close ( ) ;
125
+ } ;
126
+ } , [ open , targetRef . current , ref . current ] ) ;
127
+
128
+ const onAfterClose = useCallback (
129
+ ( e ) => {
130
+ stopPropagation ( e ) ;
131
+ ref ?. current ?. close ( ) ;
132
+ setPopoverOpen ( false ) ;
133
+ } ,
134
+ [ setPopoverOpen ]
135
+ ) ;
136
+
137
+ if ( ! open ) return null ;
113
138
return createPortal (
114
139
< Popover
115
140
noArrow
116
141
horizontalAlign = { PopoverHorizontalAlign . Left }
117
142
placementType = { PlacementType . Bottom }
118
143
ref = { ref }
119
144
style = { staticStyle as CSSProperties }
120
- onAfterClose = { stopPropagation }
145
+ onAfterClose = { onAfterClose }
121
146
>
122
147
< List onItemClick = { handleSort } >
123
148
{ isSortedAscending && (
@@ -162,5 +187,5 @@ export const ColumnHeaderModal = forwardRef((props: ColumnHeaderModalProperties,
162
187
</ Popover > ,
163
188
document . body
164
189
) ;
165
- } ) ;
190
+ } ;
166
191
ColumnHeaderModal . displayName = 'ColumnHeaderModal' ;
0 commit comments