Dock tabs context menu (#1863)

* Adding context menu to dock tabs

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Allowing to open menu by contextmenu event

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Adding DockTab tests with fine-tuning jest config

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Adding disable state to menu items

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Removing empty lines

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Moving jest-canvas-mock to dev dependencies

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev authored and GitHub committed 2020-12-28 15:18:03 +03:00
1 parent a325ffd610
commit 5d746cdff5
11 files changed
+337 -49

No files matched your search

+9 -2
View File
@@ -31,6 +31,7 @@ export interface MenuProps {
closeOnScroll?: boolean; // applicable when usePortal={true}
position?: MenuPosition; // applicable when usePortal={false}
children?: ReactNode;
toggleEvent?: "click" | "contextmenu";
}
interface State {
@@ -44,6 +45,7 @@ const defaultPropsMenu: Partial<MenuProps> = {
closeOnClickItem: true,
closeOnClickOutside: true,
closeOnScroll: false,
toggleEvent: "click"
};
@autobind()
@@ -72,18 +74,19 @@ export class Menu extends React.Component<MenuProps, State> {
this.opener = document.getElementById(this.props.htmlFor); // might not exist in sub-menus
if (this.opener) {
this.opener.addEventListener("click", this.toggle);
this.opener.addEventListener(this.props.toggleEvent, this.toggle);
this.opener.addEventListener("keydown", this.onKeyDown);
}
this.elem.addEventListener("keydown", this.onKeyDown);
window.addEventListener("resize", this.onWindowResize);
window.addEventListener("click", this.onClickOutside, true);
window.addEventListener("scroll", this.onScrollOutside, true);
window.addEventListener("contextmenu", this.onContextMenu, true);
}
componentWillUnmount() {
if (this.opener) {
this.opener.removeEventListener("click", this.toggle);
this.opener.removeEventListener(this.props.toggleEvent, this.toggle);
this.opener.removeEventListener("keydown", this.onKeyDown);
}
this.elem.removeEventListener("keydown", this.onKeyDown);
@@ -198,6 +201,10 @@ export class Menu extends React.Component<MenuProps, State> {
}
}
onContextMenu() {
this.close();
}
onWindowResize() {
if (!this.isOpen) return;
this.refreshPosition();