Skip to content

Commit 05610a0

Browse files
authored
fix: popover positioning for chat component (#2774)
moves popovers to be rendered inline and sets a z-index to ensure that popovers are above the messages list
1 parent 10991a5 commit 05610a0

File tree

6 files changed

+46
-22
lines changed

6 files changed

+46
-22
lines changed

.yarn/install-state.gz

0 Bytes
Binary file not shown.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
"watch": "lerna run --parallel --stream --scope '@microsoft/*' --ignore '@microsoft/mgt' --ignore '@microsoft/mgt-spf*' --ignore '@microsoft/mgt-sharepoint-provider' --ignore '@microsoft/mgt-electron-provider' --ignore '@microsoft/mgt-teamsfx-provider' --ignore '@microsoft/mgt-proxy-provider' build:watch ",
4141
"watch:serve": "npm-run-all --parallel watch serve",
4242
"watch:serve:https": "npm-run-all -parallel watch serve:https",
43-
"watch:chat-library": "lerna run build:watch --scope @microsoft/mgt-chat --include-dependents",
44-
"watch:chat-test-app": "lerna run start --scope react-chat",
43+
"watch:chat-library": "lerna run build:watch --scope @microsoft/mgt-chat --include-dependencies",
44+
"watch:chat-test-app": "lerna run start --scope react-chat --include-dependencies",
4545
"watch:chat": "npm-run-all --parallel watch:chat-library watch:chat-test-app",
4646
"watch:components": "lerna run --parallel build:watch --scope @microsoft/mgt-components --include-dependents --include-dependencies",
4747
"watch:react-contoso": "lerna run start --scope react-contoso",

packages/mgt-chat/src/components/Chat/Chat.tsx

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ const useStyles = makeStyles({
3636
chatInput: {
3737
...shorthands.overflow('unset')
3838
},
39+
chatHeader: {
40+
zIndex: 2
41+
},
3942
fullHeight: {
4043
height: '100%'
4144
},
@@ -94,19 +97,21 @@ export const Chat = ({ chatId }: IMgtChatProps) => {
9497
<div className={styles.chat}>
9598
{chatState.userId && chatId && chatState.messages.length > 0 ? (
9699
<>
97-
<ChatHeader
98-
chat={chatState.chat}
99-
currentUserId={chatState.userId}
100-
onRenameChat={chatState.onRenameChat}
101-
/>
102-
{chatState.participants?.length > 0 && chatState.chat?.chatType === 'group' && (
103-
<ManageChatMembers
104-
members={chatState.participants}
105-
removeChatMember={chatState.onRemoveChatMember}
100+
<div className={styles.chatHeader}>
101+
<ChatHeader
102+
chat={chatState.chat}
106103
currentUserId={chatState.userId}
107-
addChatMembers={chatState.onAddChatMembers}
104+
onRenameChat={chatState.onRenameChat}
108105
/>
109-
)}
106+
{chatState.participants?.length > 0 && chatState.chat?.chatType === 'group' && (
107+
<ManageChatMembers
108+
members={chatState.participants}
109+
removeChatMember={chatState.onRemoveChatMember}
110+
currentUserId={chatState.userId}
111+
addChatMembers={chatState.onAddChatMembers}
112+
/>
113+
)}
114+
</div>
110115
<div className={styles.chatMessages}>
111116
<MessageThread
112117
userId={chatState.userId}

packages/mgt-chat/src/components/ChatHeader/ChatHeader.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
makeStyles,
1515
tokens
1616
} from '@fluentui/react-components';
17+
import type { PopoverProps } from '@fluentui/react-components';
1718

1819
interface ChatHeaderProps {
1920
chat?: Chat;
@@ -77,10 +78,19 @@ const GroupChatHeader = ({ chat, currentUserId, onRenameChat }: ChatHeaderProps)
7778
const chatTitle = chat?.topic
7879
? chat.topic
7980
: reduceToFirstNamesList(chat?.members as AadUserConversationMember[], currentUserId);
81+
const trapFocus = true;
82+
const popoverProps: Partial<PopoverProps> = {
83+
trapFocus,
84+
inertTrapFocus: trapFocus,
85+
inline: true,
86+
positioning: 'below-start',
87+
open: isPopoverOpen,
88+
onOpenChange: handleOpenChange
89+
};
8090
return (
8191
<>
8292
{chatTitle}
83-
<Popover trapFocus positioning={'below-start'} open={isPopoverOpen} onOpenChange={handleOpenChange}>
93+
<Popover {...popoverProps}>
8494
<PopoverTrigger>
8595
<Button appearance="transparent" icon={<EditIcon />} aria-label="Name group chat"></Button>
8696
</PopoverTrigger>
@@ -126,7 +136,7 @@ const getOtherParticipantUserId = (chat?: Chat, currentUserId = '') =>
126136
* For group chats with no topic it will show the first names of other participants comma separated.
127137
* For 1:1 chats it will show the first name of the other participant.
128138
*/
129-
const ChatHeader = memo(({ chat, currentUserId, onRenameChat }: ChatHeaderProps) => {
139+
const ChatHeader = ({ chat, currentUserId, onRenameChat }: ChatHeaderProps) => {
130140
const styles = useStyles();
131141
return (
132142
<div className={styles.chatHeader}>
@@ -137,6 +147,6 @@ const ChatHeader = memo(({ chat, currentUserId, onRenameChat }: ChatHeaderProps)
137147
)}
138148
</div>
139149
);
140-
});
150+
};
141151

142-
export default ChatHeader;
152+
export default memo(ChatHeader);

packages/mgt-chat/src/components/ManageChatMembers/ManageChatMembers.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import {
1212
DialogContent,
1313
DialogSurface,
1414
DialogTitle,
15-
DialogTrigger
15+
DialogTrigger,
16+
PopoverProps
1617
} from '@fluentui/react-components';
1718
import {
1819
bundleIcon,
@@ -60,9 +61,17 @@ const ManageChatMembers = ({ currentUserId, members, addChatMembers, removeChatM
6061
}
6162
closeCallout();
6263
}, [removeChatMember, members, currentUserId, closeCallout]);
63-
64+
const trapFocus = true;
65+
const popoverProps: Partial<PopoverProps> = {
66+
trapFocus,
67+
inertTrapFocus: trapFocus,
68+
inline: true,
69+
positioning: 'below-start',
70+
open: isPopoverOpen,
71+
onOpenChange: handleOpenChange
72+
};
6473
return (
65-
<Popover trapFocus positioning={'below-start'} open={isPopoverOpen} onOpenChange={handleOpenChange}>
74+
<Popover {...popoverProps}>
6675
<PopoverTrigger>
6776
<Button className={styles.triggerButton} appearance="transparent" icon={<AddPeople />}>
6877
{members.length}
@@ -97,7 +106,7 @@ const ManageChatMembers = ({ currentUserId, members, addChatMembers, removeChatM
97106
<DialogSurface>
98107
<DialogBody>
99108
<DialogTitle>Leave the conversation?</DialogTitle>
100-
<DialogContent>You'll still have access to the chat history.</DialogContent>
109+
<DialogContent>You&apos;ll still have access to the chat history.</DialogContent>
101110
<DialogActions>
102111
<DialogTrigger disableButtonEnhancement>
103112
<Button appearance="secondary" onClick={closeCallout}>

packages/mgt-chat/src/components/ManageChatMembers/manage-chat-members.styles.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const styles = {
5858
columnGap: '4px'
5959
}),
6060
triggerButton: mergeStyles({
61-
minWidth: 'max-content',
61+
minWidth: 'unset !important',
6262
width: 'max-content'
6363
})
6464
};

0 commit comments

Comments
 (0)