Avoid errant scroll on context menu hide

This commit is contained in:
trevor-signal 2025-02-19 12:22:48 -05:00 committed by GitHub
commit 1d44c70393
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 33 additions and 4 deletions

View file

@ -5,6 +5,7 @@ import React, { type RefObject } from 'react';
import { ContextMenu, MenuItem } from 'react-contextmenu';
import ReactDOM from 'react-dom';
import type { LocalizerType } from '../../types/I18N';
import type { InteractionModeType } from '../../state/ducks/conversations';
export type ContextMenuTriggerType = {
handleContextClick: (
@ -16,7 +17,7 @@ type MessageContextProps = {
i18n: LocalizerType;
triggerId: string;
shouldShowAdditional: boolean;
interactionMode: InteractionModeType;
onDownload: (() => void) | undefined;
onEdit: (() => void) | undefined;
onReplyToMessage: (() => void) | undefined;
@ -33,6 +34,7 @@ export const MessageContextMenu = ({
i18n,
triggerId,
shouldShowAdditional,
interactionMode,
onDownload,
onEdit,
onReplyToMessage,
@ -46,7 +48,14 @@ export const MessageContextMenu = ({
onDeleteMessage,
}: MessageContextProps): JSX.Element => {
const menu = (
<ContextMenu id={triggerId}>
// We avoid restoring focus on this context menu because it is not intended for
// keyboard use and restoring focus to the message could cause an unwanted scroll
<ContextMenu
id={triggerId}
// In keyboard mode, we do want to restore focus to the message; the message is very
// likely already scrolled into view in this case.
avoidFocusRestoreOnBlur={interactionMode !== 'keyboard'}
>
{shouldShowAdditional && (
<>
{onDownload && (