microsoft / microsoft/react-native-windows

Cursor/Mouse API

Open
#9,454 11 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Area: Mouse enhancement Needs: PM Design Workstream: Component Parity
Dominant language
C++
Stars
17.3k
Forks
1.2k
Avg merge
1d 13h
Merged PRs (30d)
33

Description

Summary

Hi! I'd love to see a IMouseProps logic very similar to the existing IKeyboardProps or some other way to gain access to a mouse's location.

While this API could differ in many ways, one idea is to add props, like IKeyboardProps such as:

onMouseUp
onMouseDown
onMouseMove
onMouseOver
onMouseOut
onMouseEnter
onMouseLeave

Which maps to a very similar API to the web's API

Motivation

I'm working on a comprehensive UI component library for React Native that supports RNW.

As part of this UI component library, I'd love to have access to a mouse's cursor location in order to do the "Smart Triangle" calculation that's so common for right-clicked menus, such as this:

https://user-images.githubusercontent.com/9100169/152098909-84f302eb-a95f-4ea2-8522-3edbf5f8a504.mp4

Credit: https://height.app/blog/guide-to-build-context-menus

I'm certain there are many other candidates for UI experiences that can only be done with a mouse API of some kind

Basic Example
const App = class App extends React.Component {
  state = {
    screenX,
    screenY
  }

  private _onMouseMove = (event: IMouseEvent) => {
    this.setState({ screenX: event.nativeEvent.screenX, screenY: event.nativeEvent.screenY });
  };

  render() {
    return (
      <View onMouseMove={this._onMouseMove} />
    );
  }
}

export default App;
Open Questions

Is this unique to Windows?

It may not be, since Android and iOS also seem to have cursors in some capacity as well

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the existing IKeyboardProps API and the linked MDN MouseEvent documentation, then compare the Android and iOS pointer references. Done would require an agreed scope for cross-platform mouse location and event props, followed by implementation and tests in the relevant React Native Windows API surfaces.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, react-native
Domain
api, desktop, frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.