@@ -15,6 +15,7 @@ import { RoomListItemMenuView } from "./RoomListItemMenuView";
15
15
import { NotificationDecoration } from "../NotificationDecoration" ;
16
16
import { RoomAvatarView } from "../../avatars/RoomAvatarView" ;
17
17
import { useRovingTabIndex } from "../../../../accessibility/RovingTabIndex" ;
18
+ import { RoomListItemContextMenuView } from "./RoomListItemContextMenuView" ;
18
19
19
20
interface RoomListItemViewProps extends React . HTMLAttributes < HTMLButtonElement > {
20
21
/**
@@ -50,7 +51,19 @@ export const RoomListItemView = memo(function RoomListItemView({
50
51
const isInvitation = vm . notificationState . invited ;
51
52
const isNotificationDecorationVisible = isInvitation || ( ! showHoverDecoration && vm . showNotificationDecoration ) ;
52
53
53
- return (
54
+ const setIsMenuOpenMemoized = useCallback ( ( isOpen : boolean ) => {
55
+ if ( isOpen ) {
56
+ setIsMenuOpen ( isOpen ) ;
57
+ } else {
58
+ // To avoid icon blinking when closing the menu, we delay the state update
59
+ setTimeout ( ( ) => setIsMenuOpen ( isOpen ) , 0 ) ;
60
+ // After closing the menu, we need to set the focus back to the button
61
+ // 10ms because the focus moves to the body and we put back the focus on the button
62
+ setTimeout ( ( ) => buttonRef . current ?. focus ( ) , 10 ) ;
63
+ }
64
+ } , [ ] ) ;
65
+
66
+ const content = (
54
67
< button
55
68
ref = { ref }
56
69
className = { classNames ( "mx_RoomListItemView" , {
@@ -95,20 +108,7 @@ export const RoomListItemView = memo(function RoomListItemView({
95
108
< div className = "mx_RoomListItemView_messagePreview" > { vm . messagePreview } </ div >
96
109
</ div >
97
110
{ showHoverMenu ? (
98
- < RoomListItemMenuView
99
- room = { room }
100
- setMenuOpen = { ( isOpen ) => {
101
- if ( isOpen ) {
102
- setIsMenuOpen ( isOpen ) ;
103
- } else {
104
- // To avoid icon blinking when closing the menu, we delay the state update
105
- setTimeout ( ( ) => setIsMenuOpen ( isOpen ) , 0 ) ;
106
- // After closing the menu, we need to set the focus back to the button
107
- // 10ms because the focus moves to the body and we put back the focus on the button
108
- setTimeout ( ( ) => buttonRef . current ?. focus ( ) , 10 ) ;
109
- }
110
- } }
111
- />
111
+ < RoomListItemMenuView room = { room } setMenuOpen = { setIsMenuOpenMemoized } />
112
112
) : (
113
113
< >
114
114
{ /* aria-hidden because we summarise the unread count/notification status in a11yLabel variable */ }
@@ -125,6 +125,14 @@ export const RoomListItemView = memo(function RoomListItemView({
125
125
</ Flex >
126
126
</ button >
127
127
) ;
128
+
129
+ if ( ! vm . showContextMenu ) return content ;
130
+
131
+ return (
132
+ < RoomListItemContextMenuView room = { room } setMenuOpen = { setIsMenuOpenMemoized } >
133
+ { content }
134
+ </ RoomListItemContextMenuView >
135
+ ) ;
128
136
} ) ;
129
137
130
138
/**
0 commit comments