Skip to content

Click and DoubleClick should directly use MouseEventArgs #617

@linkdotnet

Description

@linkdotnet

Current Situation

The current state offers multiple overloads with a dozen of properties which are mapped one to one to the MouseEventArgs:

Click(this IElement element, long detail = 1, double screenX = default, double screenY = default, double clientX = default, double clientY = default, long button = default, long buttons = default, bool ctrlKey = default, bool shiftKey = default, bool altKey = default, bool metaKey = default, string? type = default)

The motivation behind is to have a "valid" argument passed down which behaves like Blazor would in a "real" scenario (detail = 1 for example for Click and detail = 2 for DoubleClick).

Proposed Solution

bUnit already offers an overload which takes the MouseEventArgs. This decouples bUnit from the supported .NET versions. For example in .net5 OffsetX and OffsetY was introduced. In .net6 PageX and PageY was introduced. Thus this "simple" version just works.

Furthermore the suggestion would be to delete Click and DoubleClick with all it's overloads and just offer 2 versions:

public void Click(this IElement element, MouseEventArgs mouseEventArgs); // Already exists

public void Click(this IElement element) => Click(element, new MouseEventArgs { detail = 1}); // New one to be in line with Blazor

In any way a small migration guide should be added to the docs.

Advantages:

  • If Microsoft extends that class we don't have to do anything (you could also argue that is a bad thing)
  • In my opinion more readable than n parameters. Also documentation for free from Microsoft
  • Also more cohesive as a lot of the default parameters are often times not used
  • ClickAsync which is also public does use the MouseEventArgs. That seems a bit in-cohesive as well. Normal expectation is that the sync and async version have the same parameter (except maybe CancellationToken or similar stuff)
  • The enhancement would come for free ;)

Disadvantages:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions