Skip to content

Commit

Permalink
Prevent menu open on right click by bubbling layer events
Browse files Browse the repository at this point in the history
  • Loading branch information
AtishayMsft committed Dec 25, 2024
1 parent b672101 commit 998286e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ export const DeclarativeChart: React.FunctionComponent<DeclarativeChartProps> =
{...transformPlotlyJsonToDonutProps(plotlySchema, colorMap, isDarkTheme)}
legendProps={{ ...legendProps, canSelectMultipleLegends: true, selectedLegends: activeLegends}}
componentRef={chartRef}
// Bubble event to prevent right click to open menu on the callout
calloutProps={{layerProps: {eventBubblingEnabled: true}}}
/>
);
case 'bar':
Expand All @@ -154,6 +156,7 @@ export const DeclarativeChart: React.FunctionComponent<DeclarativeChartProps> =
{...transformPlotlyJsonToHorizontalBarWithAxisProps(plotlySchema, colorMap, isDarkTheme)}
legendProps={legendProps}
componentRef={chartRef}
calloutProps={{layerProps: {eventBubblingEnabled: true}}}
/>
);
} else {
Expand All @@ -163,6 +166,7 @@ export const DeclarativeChart: React.FunctionComponent<DeclarativeChartProps> =
{...transformPlotlyJsonToGVBCProps(plotlySchema, colorMap, isDarkTheme)}
legendProps={legendProps}
componentRef={chartRef}
calloutProps={{layerProps: {eventBubblingEnabled: true}}}
/>
);
}
Expand All @@ -171,6 +175,7 @@ export const DeclarativeChart: React.FunctionComponent<DeclarativeChartProps> =
{...transformPlotlyJsonToVSBCProps(plotlySchema, colorMap, isDarkTheme)}
legendProps={legendProps}
componentRef={chartRef}
calloutProps={{layerProps: {eventBubblingEnabled: true}}}
/>
);
}
Expand All @@ -183,6 +188,7 @@ export const DeclarativeChart: React.FunctionComponent<DeclarativeChartProps> =
{...transformPlotlyJsonToScatterChartProps({ data, layout }, true, colorMap, isDarkTheme)}
legendProps={legendProps}
componentRef={chartRef}
calloutProps={{layerProps: {eventBubblingEnabled: true}}}
/>
);
}
Expand All @@ -191,6 +197,7 @@ export const DeclarativeChart: React.FunctionComponent<DeclarativeChartProps> =
{...transformPlotlyJsonToScatterChartProps({ data, layout }, false, colorMap, isDarkTheme)}
legendProps={{ ...legendProps, canSelectMultipleLegends: true, selectedLegends: activeLegends}}
componentRef={chartRef}
calloutProps={{layerProps: {eventBubblingEnabled: true}}}
/>
);
}
Expand All @@ -199,6 +206,7 @@ export const DeclarativeChart: React.FunctionComponent<DeclarativeChartProps> =
{...transformPlotlyJsonToVSBCProps(plotlySchema, colorMap, isDarkTheme)}
legendProps={legendProps}
componentRef={chartRef}
calloutProps={{layerProps: {eventBubblingEnabled: true}}}
/>
);
case 'heatmap':
Expand All @@ -207,13 +215,15 @@ export const DeclarativeChart: React.FunctionComponent<DeclarativeChartProps> =
{...transformPlotlyJsonToHeatmapProps(plotlySchema)}
legendProps={legendProps}
componentRef={chartRef}
calloutProps={{layerProps: {eventBubblingEnabled: true}}}
/>
);
case 'sankey':
return (
<SankeyChart
{...transformPlotlyJsonToSankeyProps(plotlySchema, colorMap, isDarkTheme)}
componentRef={chartRef}
calloutProps={{layerProps: {eventBubblingEnabled: true}}}
/>
);
case 'indicator':
Expand All @@ -223,6 +233,7 @@ export const DeclarativeChart: React.FunctionComponent<DeclarativeChartProps> =
{...transformPlotlyJsonToGaugeProps(plotlySchema, colorMap, isDarkTheme)}
legendProps={legendProps}
componentRef={chartRef}
calloutProps={{layerProps: {eventBubblingEnabled: true}}}
/>
);
}
Expand All @@ -233,6 +244,7 @@ export const DeclarativeChart: React.FunctionComponent<DeclarativeChartProps> =
{...transformPlotlyJsonToVBCProps(plotlySchema, colorMap, isDarkTheme)}
legendProps={legendProps}
componentRef={chartRef}
calloutProps={{layerProps: {eventBubblingEnabled: true}}}
/>
);
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,7 @@ export class SankeyChartBase extends React.Component<ISankeyChartProps, ISankeyC
onDismiss: this._onCloseCallout,
className: classNames.calloutContentRoot,
preventDismissOnLostFocus: true,
...this.props.calloutProps!,
};
return (
<div
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { IStyle, ITheme } from '@fluentui/react/lib/Styling';
import { IRefObject, IStyleFunctionOrObject } from '@fluentui/react/lib/Utilities';
import { ICalloutProps } from '@fluentui/react/lib/Callout';
import { IChart, IChartProps } from '../../types/IDataPoint';

export type { IChartProps, IDataPoint, ISankeyChartData } from '../../types/IDataPoint';
Expand Down Expand Up @@ -90,6 +91,11 @@ export interface ISankeyChartProps {
* the public methods and properties of the component.
*/
componentRef?: IRefObject<IChart>;

/**
* props for the callout in the chart
*/
calloutProps?: Partial<ICalloutProps>;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ export class DeclarativeChartBasicExample extends React.Component<{}, IDeclarati
this._lastKnownValidLegends = selectedLegends;
}

componentDidMount() {
document.addEventListener('contextmenu', (e) => {
e.preventDefault();
});
};

public render(): JSX.Element {
return <div>{this._createDeclarativeChart()}</div>;
}
Expand Down

0 comments on commit 998286e

Please sign in to comment.