Skip to content

Implement contextMenuHidden property for TextInput fabric architecture #14804

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,22 @@ const examples: Array<RNTesterModuleExample> = [
);
},
},
{
title: 'ContextMenuHidden set to True',
render: function (): React.Node {
return (
<View>
<Text>ContextMenuHidden (Right-click to test)</Text>
<ExampleTextInput
style={styles.singleLine}
contextMenuHidden={true}
placeholder="contextMenuHidden={true}"
testID="textinput-contextmenuhidden"
/>
</View>
);
},
},
{
title: 'Cursorcolor set to Green',
render: function (): React.Node {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,23 @@ describe('TextInput Tests', () => {
const dump = await dumpVisualTree('textinput-carethidden');
expect(dump).toMatchSnapshot();
});
test('TextInputs can have contextMenuHidden', async () => {
const component = await app.findElementByTestID('textinput-contextmenuhidden');
await component.waitForDisplayed({timeout: 5000});
await app.waitUntil(
async () => {
await component.setValue('Hello World');
return (await component.getText()) === 'Hello World';
},
{
interval: 1500,
timeout: 5000,
timeoutMsg: `Unable to enter correct text.`,
},
);
const dump = await dumpVisualTree('textinput-contextmenuhidden');
expect(dump).toMatchSnapshot();
});
test('Text have cursorColor', async () => {
const component = await app.findElementByTestID('textinput-cursorColor');
await component.waitForDisplayed({timeout: 5000});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,10 @@ void WindowsTextInputComponentView::OnPointerReleased(
msg = WM_MBUTTONUP;
break;
case winrt::Microsoft::ReactNative::Composition::Input::PointerUpdateKind::RightButtonReleased:
msg = WM_RBUTTONUP;
// Don't send right button up to RichEdit if context menu is hidden
if (!windowsTextInputProps().contextMenuHidden) {
msg = WM_RBUTTONUP;
}
break;
case winrt::Microsoft::ReactNative::Composition::Input::PointerUpdateKind::XButton1Released:
msg = WM_XBUTTONUP;
Expand Down Expand Up @@ -797,6 +800,23 @@ void WindowsTextInputComponentView::OnKeyDown(
const winrt::Microsoft::ReactNative::Composition::Input::KeyRoutedEventArgs &args) noexcept {
// Do not forward tab keys into the TextInput, since we want that to do the tab loop instead. This aligns with WinUI
// behavior We do forward Ctrl+Tab to the textinput.

// Check for context menu keyboard shortcuts when contextMenuHidden is true
if (windowsTextInputProps().contextMenuHidden) {
// Block Menu key (VK_APPS)
if (args.Key() == winrt::Windows::System::VirtualKey::Application) {
args.Handled(true);
return;
}
// Block Shift+F10
if (args.Key() == winrt::Windows::System::VirtualKey::F10 &&
(args.KeyboardSource().GetKeyState(winrt::Windows::System::VirtualKey::Shift) &
winrt::Microsoft::UI::Input::VirtualKeyStates::Down) == winrt::Microsoft::UI::Input::VirtualKeyStates::Down) {
args.Handled(true);
return;
}
}

if (args.Key() != winrt::Windows::System::VirtualKey::Tab ||
(args.KeyboardSource().GetKeyState(winrt::Windows::System::VirtualKey::Control) &
winrt::Microsoft::UI::Input::VirtualKeyStates::Down) == winrt::Microsoft::UI::Input::VirtualKeyStates::Down) {
Expand Down