Skip to content

Commit 9bde5a6

Browse files
author
Sravan S
authored
fix: menu position in tight screens (#450)
* condition where some menus get clipped in left side: * usually user profile in channel moderation * context menu of last item in channel gets clipped under fixes 1. & 3. from: https://sendbird.atlassian.net/browse/SBISSUE-10883
1 parent b356b94 commit 9bde5a6

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/ui/ContextMenu/MenuItems.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ interface MenuItemsState {
1717
handleClickOutside: (e: MouseEvent) => void;
1818
}
1919

20+
// padding to handle height of last item in message-list
21+
const HEIGHT_PADDING = 60;
22+
2023
export default class MenuItems extends React.Component<MenuItemsProps, MenuItemsState> {
2124
constructor(props: MenuItemsProps) {
2225
super(props);
@@ -70,7 +73,7 @@ export default class MenuItems extends React.Component<MenuItemsProps, MenuItems
7073
if (!this.menuRef.current) return menuStyle;
7174
const { innerWidth, innerHeight } = window;
7275
const rect = this.menuRef.current.getBoundingClientRect();
73-
if (y + rect.height > innerHeight) {
76+
if (y + rect.height + HEIGHT_PADDING > innerHeight) {
7477
menuStyle.top -= rect.height;
7578
}
7679
if (x + rect.width > innerWidth && !openLeft) {
@@ -79,16 +82,19 @@ export default class MenuItems extends React.Component<MenuItemsProps, MenuItems
7982
if (menuStyle.top < 0) {
8083
menuStyle.top = rect.height < innerHeight ? (innerHeight - rect.height) / 2 : 0;
8184
}
82-
if (menuStyle.left < 0) {
83-
menuStyle.left = rect.width < innerWidth ? (innerWidth - rect.width) / 2 : 0;
84-
}
8585
menuStyle.top += 32;
8686
if (openLeft) {
8787
const padding = Number.isNaN(rect.width - 30)
8888
? 108 // default
8989
: rect.width - 30;
9090
menuStyle.left -= padding;
9191
}
92+
// warning: this section has to be executed after the openLeft is calculated
93+
// menu is outside viewport
94+
if (menuStyle.left < 0) {
95+
menuStyle.left = rect.width < innerWidth ? (innerWidth - rect.width) / 2 : 0;
96+
}
97+
9298
this.setState({ menuStyle })
9399
return menuStyle;
94100
}

0 commit comments

Comments
 (0)