Fix context menu being opened when clicking message action bar buttons (#9200)
This commit is contained in:
parent
e269c6895d
commit
3eecd68175
6 changed files with 155 additions and 59 deletions
|
@ -240,7 +240,7 @@ class EmojiPicker extends React.Component<IProps, IState> {
|
|||
render() {
|
||||
let heightBefore = 0;
|
||||
return (
|
||||
<div className="mx_EmojiPicker">
|
||||
<div className="mx_EmojiPicker" data-testid='mx_EmojiPicker'>
|
||||
<Header categories={this.categories} onAnchorClick={this.scrollToCategory} />
|
||||
<Search query={this.state.filter} onChange={this.onChangeFilter} onEnter={this.onEnterFilter} />
|
||||
<AutoHideScrollbar
|
||||
|
|
|
@ -134,7 +134,6 @@ class ReactionPicker extends React.Component<IProps, IState> {
|
|||
isEmojiDisabled={this.isEmojiDisabled}
|
||||
selectedEmojis={this.state.selectedEmojis}
|
||||
showQuickReactions={true}
|
||||
data-testid='mx_ReactionPicker'
|
||||
/>;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import React, { ReactElement, useContext, useEffect } from 'react';
|
||||
import React, { ReactElement, useCallback, useContext, useEffect } from 'react';
|
||||
import { EventStatus, MatrixEvent, MatrixEventEvent } from 'matrix-js-sdk/src/models/event';
|
||||
import classNames from 'classnames';
|
||||
import { MsgType, RelationType } from 'matrix-js-sdk/src/@types/event';
|
||||
|
@ -88,7 +88,7 @@ const OptionsButton: React.FC<IOptionsButtonProps> = ({
|
|||
onFocusChange(menuDisplayed);
|
||||
}, [onFocusChange, menuDisplayed]);
|
||||
|
||||
const onOptionsClick = (e: React.MouseEvent): void => {
|
||||
const onOptionsClick = useCallback((e: React.MouseEvent): void => {
|
||||
// Don't open the regular browser or our context menu on right-click
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
@ -97,7 +97,7 @@ const OptionsButton: React.FC<IOptionsButtonProps> = ({
|
|||
// the element that is currently focused is skipped. So we want to call onFocus manually to keep the
|
||||
// position in the page even when someone is clicking around.
|
||||
onFocus();
|
||||
};
|
||||
}, [openMenu, onFocus]);
|
||||
|
||||
let contextMenu: ReactElement | null;
|
||||
if (menuDisplayed) {
|
||||
|
@ -121,6 +121,7 @@ const OptionsButton: React.FC<IOptionsButtonProps> = ({
|
|||
className="mx_MessageActionBar_iconButton mx_MessageActionBar_optionsButton"
|
||||
title={_t("Options")}
|
||||
onClick={onOptionsClick}
|
||||
onContextMenu={onOptionsClick}
|
||||
isExpanded={menuDisplayed}
|
||||
inputRef={ref}
|
||||
onFocus={onFocus}
|
||||
|
@ -153,17 +154,24 @@ const ReactButton: React.FC<IReactButtonProps> = ({ mxEvent, reactions, onFocusC
|
|||
</ContextMenu>;
|
||||
}
|
||||
|
||||
const onClick = useCallback((e: React.MouseEvent) => {
|
||||
// Don't open the regular browser or our context menu on right-click
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
openMenu();
|
||||
// when the context menu is opened directly, e.g. via mouse click, the onFocus handler which tracks
|
||||
// the element that is currently focused is skipped. So we want to call onFocus manually to keep the
|
||||
// position in the page even when someone is clicking around.
|
||||
onFocus();
|
||||
}, [openMenu, onFocus]);
|
||||
|
||||
return <React.Fragment>
|
||||
<ContextMenuTooltipButton
|
||||
className="mx_MessageActionBar_iconButton"
|
||||
title={_t("React")}
|
||||
onClick={() => {
|
||||
openMenu();
|
||||
// when the context menu is opened directly, e.g. via mouse click, the onFocus handler which tracks
|
||||
// the element that is currently focused is skipped. So we want to call onFocus manually to keep the
|
||||
// position in the page even when someone is clicking around.
|
||||
onFocus();
|
||||
}}
|
||||
onClick={onClick}
|
||||
onContextMenu={onClick}
|
||||
isExpanded={menuDisplayed}
|
||||
inputRef={ref}
|
||||
onFocus={onFocus}
|
||||
|
@ -193,7 +201,11 @@ const ReplyInThreadButton = ({ mxEvent }: IReplyInThreadButton) => {
|
|||
return null;
|
||||
}
|
||||
|
||||
const onClick = (): void => {
|
||||
const onClick = (e: React.MouseEvent): void => {
|
||||
// Don't open the regular browser or our context menu on right-click
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
if (firstTimeSeeingThreads) {
|
||||
localStorage.setItem("mx_seen_feature_thread", "true");
|
||||
}
|
||||
|
@ -245,6 +257,7 @@ const ReplyInThreadButton = ({ mxEvent }: IReplyInThreadButton) => {
|
|||
: _t("Can't create a thread from an event with an existing relation")}
|
||||
|
||||
onClick={onClick}
|
||||
onContextMenu={onClick}
|
||||
>
|
||||
<ThreadIcon />
|
||||
{ firstTimeSeeingThreads && !threadsEnabled && (
|
||||
|
@ -265,10 +278,19 @@ const FavouriteButton = ({ mxEvent }: IFavouriteButtonProp) => {
|
|||
'mx_MessageActionBar_favouriteButton_fillstar': isFavourite(eventId),
|
||||
});
|
||||
|
||||
const onClick = useCallback((e: React.MouseEvent) => {
|
||||
// Don't open the regular browser or our context menu on right-click
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
toggleFavourite(eventId);
|
||||
}, [toggleFavourite, eventId]);
|
||||
|
||||
return <RovingAccessibleTooltipButton
|
||||
className={classes}
|
||||
title={_t("Favourite")}
|
||||
onClick={() => toggleFavourite(eventId)}
|
||||
onClick={onClick}
|
||||
onContextMenu={onClick}
|
||||
data-testid={eventId}
|
||||
>
|
||||
<StarIcon />
|
||||
|
@ -335,7 +357,11 @@ export default class MessageActionBar extends React.PureComponent<IMessageAction
|
|||
this.props.onFocusChange?.(focused);
|
||||
};
|
||||
|
||||
private onReplyClick = (ev: React.MouseEvent): void => {
|
||||
private onReplyClick = (e: React.MouseEvent): void => {
|
||||
// Don't open the regular browser or our context menu on right-click
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
dis.dispatch({
|
||||
action: 'reply_to_event',
|
||||
event: this.props.mxEvent,
|
||||
|
@ -343,7 +369,11 @@ export default class MessageActionBar extends React.PureComponent<IMessageAction
|
|||
});
|
||||
};
|
||||
|
||||
private onEditClick = (): void => {
|
||||
private onEditClick = (e: React.MouseEvent): void => {
|
||||
// Don't open the regular browser or our context menu on right-click
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
editEvent(this.props.mxEvent, this.context.timelineRenderingType, this.props.getRelationsForEvent);
|
||||
};
|
||||
|
||||
|
@ -406,6 +436,10 @@ export default class MessageActionBar extends React.PureComponent<IMessageAction
|
|||
}
|
||||
|
||||
private onResendClick = (ev: React.MouseEvent): void => {
|
||||
// Don't open the regular browser or our context menu on right-click
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
|
||||
this.runActionOnFailedEv((tarEv) => Resend.resend(tarEv));
|
||||
};
|
||||
|
||||
|
@ -423,6 +457,7 @@ export default class MessageActionBar extends React.PureComponent<IMessageAction
|
|||
className="mx_MessageActionBar_iconButton"
|
||||
title={_t("Edit")}
|
||||
onClick={this.onEditClick}
|
||||
onContextMenu={this.onEditClick}
|
||||
key="edit"
|
||||
>
|
||||
<EditIcon />
|
||||
|
@ -433,6 +468,7 @@ export default class MessageActionBar extends React.PureComponent<IMessageAction
|
|||
className="mx_MessageActionBar_iconButton"
|
||||
title={_t("Delete")}
|
||||
onClick={this.onCancelClick}
|
||||
onContextMenu={this.onCancelClick}
|
||||
key="cancel"
|
||||
>
|
||||
<TrashcanIcon />
|
||||
|
@ -453,6 +489,7 @@ export default class MessageActionBar extends React.PureComponent<IMessageAction
|
|||
className="mx_MessageActionBar_iconButton"
|
||||
title={_t("Retry")}
|
||||
onClick={this.onResendClick}
|
||||
onContextMenu={this.onResendClick}
|
||||
key="resend"
|
||||
>
|
||||
<ResendIcon />
|
||||
|
@ -475,6 +512,7 @@ export default class MessageActionBar extends React.PureComponent<IMessageAction
|
|||
className="mx_MessageActionBar_iconButton"
|
||||
title={_t("Reply")}
|
||||
onClick={this.onReplyClick}
|
||||
onContextMenu={this.onReplyClick}
|
||||
key="reply"
|
||||
>
|
||||
<ReplyIcon />
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue