Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 115e17b

Browse files
authored
Fix positioning of the thread context menu (#7918)
1 parent b02d5ec commit 115e17b

File tree

2 files changed

+15
-38
lines changed

2 files changed

+15
-38
lines changed

src/components/structures/ContextMenu.tsx

+10-8
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,11 @@ export default class ContextMenu extends React.PureComponent<IProps, IState> {
260260
const { windowWidth, windowHeight } = UIStore.instance;
261261
if (contextMenuRect) {
262262
if (position.top !== undefined) {
263-
position.top = Math.min(
264-
position.top,
265-
windowHeight - contextMenuRect.height - WINDOW_PADDING,
266-
);
263+
let maxTop = windowHeight - WINDOW_PADDING;
264+
if (!this.props.bottomAligned) {
265+
maxTop -= contextMenuRect.height;
266+
}
267+
position.top = Math.min(position.top, maxTop);
267268
// Adjust the chevron if necessary
268269
if (chevronOffset.top !== undefined) {
269270
chevronOffset.top = props.chevronOffset + props.top - position.top;
@@ -278,10 +279,11 @@ export default class ContextMenu extends React.PureComponent<IProps, IState> {
278279
}
279280
}
280281
if (position.left !== undefined) {
281-
position.left = Math.min(
282-
position.left,
283-
windowWidth - contextMenuRect.width - WINDOW_PADDING,
284-
);
282+
let maxLeft = windowWidth - WINDOW_PADDING;
283+
if (!this.props.rightAligned) {
284+
maxLeft -= contextMenuRect.width;
285+
}
286+
position.left = Math.min(position.left, maxLeft);
285287
if (chevronOffset.left !== undefined) {
286288
chevronOffset.left = props.chevronOffset + props.left - position.left;
287289
}

src/components/views/context_menus/ThreadListContextMenu.tsx

+5-30
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import React, { RefObject, useCallback, useEffect } from "react";
17+
import React, { useCallback, useEffect } from "react";
1818
import { MatrixEvent } from "matrix-js-sdk/src";
1919

2020
import { ButtonEvent } from "../elements/AccessibleButton";
@@ -27,7 +27,6 @@ import { _t } from "../../../languageHandler";
2727
import IconizedContextMenu, { IconizedContextMenuOption, IconizedContextMenuOptionList } from "./IconizedContextMenu";
2828
import { WidgetLayoutStore } from "../../../stores/widgets/WidgetLayoutStore";
2929
import { MatrixClientPeg } from "../../../MatrixClientPeg";
30-
import { useRovingTabIndex } from "../../../accessibility/RovingTabIndex";
3130
import { ViewRoomPayload } from "../../../dispatcher/payloads/ViewRoomPayload";
3231

3332
interface IProps {
@@ -36,13 +35,6 @@ interface IProps {
3635
onMenuToggle?: (open: boolean) => void;
3736
}
3837

39-
interface IExtendedProps extends IProps {
40-
// Props for making the button into a roving one
41-
tabIndex?: number;
42-
inputRef?: RefObject<HTMLElement>;
43-
onFocus?(): void;
44-
}
45-
4638
const contextMenuBelow = (elementRect: DOMRect) => {
4739
// align the context menu's icons with the icon which opened the context menu
4840
const left = elementRect.left + window.pageXOffset + elementRect.width;
@@ -51,27 +43,13 @@ const contextMenuBelow = (elementRect: DOMRect) => {
5143
return { left, top, chevronFace };
5244
};
5345

54-
export const RovingThreadListContextMenu: React.FC<IProps> = (props) => {
55-
const [onFocus, isActive, ref] = useRovingTabIndex();
56-
57-
return <ThreadListContextMenu
58-
{...props}
59-
onFocus={onFocus}
60-
tabIndex={isActive ? 0 : -1}
61-
inputRef={ref}
62-
/>;
63-
};
64-
65-
const ThreadListContextMenu: React.FC<IExtendedProps> = ({
46+
const ThreadListContextMenu: React.FC<IProps> = ({
6647
mxEvent,
6748
permalinkCreator,
6849
onMenuToggle,
69-
onFocus,
70-
inputRef,
7150
...props
7251
}) => {
73-
const [menuDisplayed, _ref, openMenu, closeThreadOptions] = useContextMenu();
74-
const button = inputRef ?? _ref; // prefer the ref we receive via props in case we are being controlled
52+
const [menuDisplayed, button, openMenu, closeThreadOptions] = useContextMenu();
7553

7654
const viewInRoom = useCallback((evt: ButtonEvent): void => {
7755
evt.preventDefault();
@@ -95,11 +73,8 @@ const ThreadListContextMenu: React.FC<IExtendedProps> = ({
9573
}, [mxEvent, closeThreadOptions, permalinkCreator]);
9674

9775
useEffect(() => {
98-
if (onMenuToggle) {
99-
onMenuToggle(menuDisplayed);
100-
}
101-
onFocus?.();
102-
}, [menuDisplayed, onMenuToggle, onFocus]);
76+
onMenuToggle?.(menuDisplayed);
77+
}, [menuDisplayed, onMenuToggle]);
10378

10479
const isMainSplitTimelineShown = !WidgetLayoutStore.instance.hasMaximisedWidget(
10580
MatrixClientPeg.get().getRoom(mxEvent.getRoomId()),

0 commit comments

Comments
 (0)