user-event icon indicating copy to clipboard operation
user-event copied to clipboard

Simulate MacOS X' Ctrl + Click as a contextmenu

Open julienw opened this issue 3 years ago • 1 comments

Problem description

On MacOS X, it's possible to trigger a contextmenu event with ctrl + click. This gives a contextmenu event with { button: 0, buttons: 1 } (as opposed to { button: 2, buttons: 2 } for a normal right click). It would be good to be able to trigger this somehow, and I haven't found that the user-event library can do it at the moment.

Suggested solution

This would be my prefered solution:

const user = userEvent.setup({ environment: 'macosx' });
await user.keyboard("{Shift>}");
await user.click(target);

Additional context

No response

julienw avatar Apr 12 '22 14:04 julienw

We currently implement a combinationBehavior on keydown that only implements "select all" for Ctrl+A. This also behaves differently on Mac. See https://github.com/testing-library/user-event/issues/778#issuecomment-966393903

I think we should not hard-code but implement those combinations as plugins to the event/behavior and then let the user supply the plugin per setup().

import userEvent, { InputScheme } from `@testing-library/user-event`

// Could also extend it and supply your own
const user = userEvent.setup({inputScheme: InputScheme.MacOSX})

ph-fritsche avatar Apr 13 '22 07:04 ph-fritsche