Skip to content

Commit faeb038

Browse files
authored
Merge branch 'main' into fix-fetch-mock-checks
2 parents 0f4bf61 + cc2349c commit faeb038

File tree

6 files changed

+373
-386
lines changed

6 files changed

+373
-386
lines changed

src/components/shared/ContextMenu.tsx

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,52 +4,25 @@
44

55
import { PureComponent } from 'react';
66
import type { ComponentProps } from 'react';
7-
import ReactDOM from 'react-dom';
87
import { ContextMenu as ReactContextMenu } from '@firefox-devtools/react-contextmenu';
98

109
import './ContextMenu.css';
1110

1211
type Props = ComponentProps<typeof ReactContextMenu>;
1312

1413
export class ContextMenu extends PureComponent<Props> {
15-
_contextMenu: any = null;
16-
_takeContextMenuRef = (contextMenu: any) => {
17-
this._contextMenu = contextMenu;
18-
};
19-
20-
_mouseDownHandler(event: Event): void {
14+
_mouseDownHandler = (event: React.MouseEvent<HTMLDivElement>): void => {
2115
// This prevents from stealing the focus from where it was.
2216
event.preventDefault();
23-
}
24-
25-
override componentDidMount() {
26-
if (this._contextMenu) {
27-
// The context menu component does not expose a reference to its internal
28-
// DOM node so using findDOMNode is currently unavoidable.
29-
// eslint-disable-next-line react/no-find-dom-node
30-
const contextMenuNode = ReactDOM.findDOMNode(this._contextMenu);
31-
if (contextMenuNode) {
32-
// There's no need to remove this event listener since the component is
33-
// never unmounted. Duplicate event listeners will also be discarded
34-
// automatically so we don't need to handle that.
35-
contextMenuNode.addEventListener('mousedown', this._mouseDownHandler);
36-
}
37-
}
38-
}
39-
40-
override componentWillUnmount() {
41-
// eslint-disable-next-line react/no-find-dom-node
42-
const contextMenuNode = ReactDOM.findDOMNode(this._contextMenu);
43-
if (contextMenuNode) {
44-
contextMenuNode.removeEventListener('mousedown', this._mouseDownHandler);
45-
}
46-
}
17+
};
4718

4819
override render() {
4920
return (
50-
<ReactContextMenu ref={this._takeContextMenuRef} {...this.props}>
51-
{this.props.children ? this.props.children : <div />}
52-
</ReactContextMenu>
21+
<div onMouseDown={this._mouseDownHandler}>
22+
<ReactContextMenu {...this.props}>
23+
{this.props.children ? this.props.children : <div />}
24+
</ReactContextMenu>
25+
</div>
5326
);
5427
}
5528
}

0 commit comments

Comments
 (0)