Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding contextmenu to the list of event the callout dismisses on #25051

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Making contextual menu dismiss on right click",
"packageName": "@fluentui/react",
"email": "[email protected]",
"dependentChangeType": "patch"
}
21 changes: 21 additions & 0 deletions packages/react/src/components/Callout/Callout.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,27 @@ describe('Callout', () => {
expect(onDismiss).not.toHaveBeenCalled();
});

it('Callout dismisses on right-click', () => {
jest.useFakeTimers();
const onDismiss = jest.fn();

const { getByText } = render(
<div>
<button>button</button>
<Callout target="#target" onDismiss={onDismiss}>
<div>Content</div>
</Callout>
</div>,
);

act(() => {
jest.runAllTimers();
getByText('button').dispatchEvent(new MouseEvent('contextmenu'));
});

expect(onDismiss).toHaveBeenCalled();
});

it('will correctly return focus to element that spawned it', () => {
jest.useFakeTimers();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ function useDismissHandlers(
on(targetWindow, 'resize', dismissOnResize, true),
on(targetWindow.document.documentElement, 'focus', dismissOnLostFocus, true),
on(targetWindow.document.documentElement, 'click', dismissOnLostFocus, true),
on(targetWindow.document.documentElement, 'contextmenu', dismissOnLostFocus, true),
on(targetWindow, 'blur', dismissOnTargetWindowBlur, true),
];

Expand Down