UNPKG

azure-devops-ui

Version:

React components for building web UI in Azure DevOps

36 lines (35 loc) 1.62 kB
import "../../CommonImports"; import "../../Core/core.css"; import "./Menu.css"; import "./MenuButton.css"; var ContextMenuBehavior = /** @class */ (function () { function ContextMenuBehavior(contextMenuHandler, allowDefaultMenuOnAnchor) { var _this = this; if (allowDefaultMenuOnAnchor === void 0) { allowDefaultMenuOnAnchor = false; } this.initialize = function (props, component, eventDispatch) { _this.eventDispatch = eventDispatch; _this.eventDispatch.addEventListener("contextmenu", _this.onContextMenu); }; this.onContextMenu = function (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) { var target = event.nativeEvent.target; if (target && target.nodeName === "A") { return; } } } _this.contextMenuHandler(event); }; this.contextMenuHandler = contextMenuHandler; this.allowDefaultMenuOnAnchor = allowDefaultMenuOnAnchor; } ContextMenuBehavior.prototype.componentWillUnmount = function () { var _a; (_a = this.eventDispatch) === null || _a === void 0 ? void 0 : _a.removeEventListener("contextmenu", this.onContextMenu); }; return ContextMenuBehavior; }()); export { ContextMenuBehavior };