UNPKG

azure-devops-ui

Version:

React components for building web UI in Azure DevOps

32 lines (31 loc) 1.35 kB
import "../../CommonImports"; import "../../Core/core.css"; import "./Menu.css"; import "./MenuButton.css"; export class ContextMenuBehavior { constructor(contextMenuHandler, allowDefaultMenuOnAnchor = false) { this.initialize = (props, component, eventDispatch) => { this.eventDispatch = eventDispatch; this.eventDispatch.addEventListener("contextmenu", this.onContextMenu); }; this.onContextMenu = (event) => { if (this.allowDefaultMenuOnAnchor) { // We don't want to show the custom contextual menu and prevent default // if user clicked mouse and the target element is an anchor tag. if (event.nativeEvent instanceof MouseEvent) { const target = event.nativeEvent.target; if (target && target.nodeName === "A") { return; } } } this.contextMenuHandler(event); }; this.contextMenuHandler = contextMenuHandler; this.allowDefaultMenuOnAnchor = allowDefaultMenuOnAnchor; } componentWillUnmount() { var _a; (_a = this.eventDispatch) === null || _a === void 0 ? void 0 : _a.removeEventListener("contextmenu", this.onContextMenu); } }