Make EmojiPicker an unmanaged Context Menu as it is too complex to be managed

pull/21833/head
Michael Telatynski 2019-12-19 07:23:05 +00:00
parent f30e919f9e
commit a1df87a375
2 changed files with 13 additions and 9 deletions

View File

@ -71,12 +71,12 @@ export class ContextMenu extends React.Component {
// on resize callback // on resize callback
windowResize: PropTypes.func, windowResize: PropTypes.func,
catchTab: PropTypes.bool, // whether to close the ContextMenu on TAB (default=true) managed: PropTypes.bool, // whether this context menu should be focus managed. If false it must handle itself
}; };
static defaultProps = { static defaultProps = {
hasBackground: true, hasBackground: true,
catchTab: true, managed: true,
}; };
constructor() { constructor() {
@ -186,15 +186,19 @@ export class ContextMenu extends React.Component {
}; };
_onKeyDown = (ev) => { _onKeyDown = (ev) => {
if (!this.props.managed) {
if (ev.key === Key.ESCAPE) {
this.props.onFinished();
ev.stopPropagation();
ev.preventDefault();
}
return;
}
let handled = true; let handled = true;
switch (ev.key) { switch (ev.key) {
case Key.TAB: case Key.TAB:
if (!this.props.catchTab) {
handled = false;
break;
}
// fallthrough
case Key.ESCAPE: case Key.ESCAPE:
this.props.onFinished(); this.props.onFinished();
break; break;
@ -321,7 +325,7 @@ export class ContextMenu extends React.Component {
return ( return (
<div className="mx_ContextualMenu_wrapper" style={{...position, ...wrapperStyle}} onKeyDown={this._onKeyDown}> <div className="mx_ContextualMenu_wrapper" style={{...position, ...wrapperStyle}} onKeyDown={this._onKeyDown}>
<div className={menuClasses} style={menuStyle} ref={this.collectContextMenuRect} role="menu"> <div className={menuClasses} style={menuStyle} ref={this.collectContextMenuRect} role={this.props.managed ? "menu" : undefined}>
{ chevron } { chevron }
{ props.children } { props.children }
</div> </div>

View File

@ -88,7 +88,7 @@ const ReactButton = ({mxEvent, reactions, onFocusChange}) => {
if (menuDisplayed) { if (menuDisplayed) {
const buttonRect = button.current.getBoundingClientRect(); const buttonRect = button.current.getBoundingClientRect();
const ReactionPicker = sdk.getComponent('emojipicker.ReactionPicker'); const ReactionPicker = sdk.getComponent('emojipicker.ReactionPicker');
contextMenu = <ContextMenu {...aboveLeftOf(buttonRect)} onFinished={closeMenu} catchTab={false}> contextMenu = <ContextMenu {...aboveLeftOf(buttonRect)} onFinished={closeMenu} managed={false}>
<ReactionPicker mxEvent={mxEvent} reactions={reactions} onFinished={closeMenu} /> <ReactionPicker mxEvent={mxEvent} reactions={reactions} onFinished={closeMenu} />
</ContextMenu>; </ContextMenu>;
} }