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

Menu: Improve touch support & Merge OnTouch,OnAction into OnClick #8492

Merged
merged 6 commits into from
Apr 2, 2024

Conversation

danielchalmers
Copy link
Contributor

@danielchalmers danielchalmers commented Mar 26, 2024

Description

Changes for v7:

  • Remove OnTouch and OnAction in favor of OnClick like all other controls
  • Fix touch events falling through
  • Add Activate override for TouchEventArgs
  • Properly handle the context menu as a right click on touch so it doesn't trigger the default action
  • Remove obsolete members

Impact:

Everything should work the same or better.
If there's any regressions in behavior they'll be fixed.

Migration Guide - MudMenu

OnTouch and OnAction have been removed to simplify the API. OnClick handles all use cases for both mouse and touch.

How Has This Been Tested?

unit

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Touch events don't fall through.

Before:

Video3.mp4

After:

Video2.mp4

Checklist:

  • The PR is submitted to the correct branch (dev).
  • My code follows the code style of this project.
  • I've added relevant tests.

Breaking change for v7.

- Remove OnTouch and OnAction in favor of OnClick like all other controls
- Fix touch events falling through
- Add Activate override for TouchEventArgs
- Replace one use of async void
- Properly handle the context menu as a right click on touch so it doesn't trigger the default action
- Remove obsolete members

- Closes MudBlazor#8331
- Resolves MudBlazor#4527
- Resolves MudBlazor#4549
- Resolves MudBlazor#5170
- Resolves MudBlazor#5768
- Resolves MudBlazor#7784
@github-actions github-actions bot added breaking change bug Something does not work as intended/expected enhancement New feature or request PR: needs review labels Mar 26, 2024
@danielchalmers
Copy link
Contributor Author

Took care of a few issues with the menu while simplifying the handlers to match the rest of the components.

@mckaragoz @henon @ScarletKuro

Copy link

codecov bot commented Mar 26, 2024

Codecov Report

Attention: Patch coverage is 71.42857% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 89.34%. Comparing base (27e54b3) to head (e5b2f2e).
Report is 19 commits behind head on dev.

Files Patch % Lines
src/MudBlazor/Components/Menu/MudMenu.razor.cs 71.42% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #8492      +/-   ##
==========================================
+ Coverage   89.01%   89.34%   +0.33%     
==========================================
  Files         411      410       -1     
  Lines       12175    11892     -283     
  Branches     2431     2355      -76     
==========================================
- Hits        10837    10625     -212     
+ Misses        803      748      -55     
+ Partials      535      519      -16     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ScarletKuro
Copy link
Member

Will this problem not come back since we removed semaphore? #7651
If I remember correctly the problem only existed on specific platforms.

@@ -6,11 +6,12 @@
<div @attributes="UserAttributes" Class="@Classname" Style="@Style"
@onmouseenter="@MouseEnter"
@onmouseleave="@MouseLeave"
@oncontextmenu="@(ActivationEvent==MouseEvent.RightClick ? ToggleMenu : null)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we missing spaces before and after ==

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a straight copy paste. I didn't want to do clean up and pollute the review

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you tell me some components I could do them in bulk separately?

@danielchalmers
Copy link
Contributor Author

Will this problem not come back since we removed semaphore? #7651 If I remember correctly the problem only existed on specific platforms.

Isn't that only relevant due to the OnClick/OnTouch split?

@ScarletKuro
Copy link
Member

Isn't that only relevant due to the OnClick/OnTouch split?

I'm actually not sure, as I understand the problem was when you click multiple times?

Maybe @dennisrahmen knows wmore

@dennisrahmen
Copy link
Contributor

dennisrahmen commented Mar 26, 2024

@ScarletKuro the Problem was with OnAction.

If I remember correctly OnAction should be called if it is a Touch or a Click.

So that you don't have to add both OnTouch and OnClick when you want it to work on Desktop and Mobile.

But that at least for me never worked on Blazor WASM. I am still adding both to my menus.

@danielchalmers
Copy link
Contributor Author

as I understand the problem was when you click multiple times?

Like this?

video2.mp4

@danielchalmers
Copy link
Contributor Author

danielchalmers commented Mar 26, 2024

@ScarletKuro the Problem was with OnAction.

If I remember correctly OnAction should be called if it is a Touch or a Click.

So that you don't have to add both OnTouch and OnClick when you want it to work on Desktop and Mobile.

But that at least for me never worked on Blazor WASM. I am still adding both to my menus.

@dennisrahmen I think we can make OnClick functionally the same as OnAction and thus remove OnTouch and OnAction

Maybe you could try this PR out if you get some free time because it seems to work well for me

@ScarletKuro
Copy link
Member

ScarletKuro commented Mar 26, 2024

I found the original discussion #6954
I guess the problem was that on android when using OnClick and OnTouch together it would fire twice. I guess it should be fine now.
If this OnClick now works on Windows, Android and iOS in MAUI for MudMenuItem, we should be fine.
Sorry, just trying to be really cautious with this,

@danielchalmers
Copy link
Contributor Author

Sorry, just trying to be really cautious with this,

Oh I think that's exactly the right approach

I couldn't personally find any problems but always happy to test new scenarios

@dennisrahmen
Copy link
Contributor

@danielchalmers I will try it out this evening when I get home in my WASM App.

I can also try in MAUI for Android.

@mikes-gh
Copy link
Contributor

@danielchalmers If this all works would you mind looking at the coverage. We probably need an additional couple of tests in this area

@danielchalmers
Copy link
Contributor Author

@danielchalmers I will try it out this evening when I get home in my WASM App.

I can also try in MAUI for Android.

@dennisrahmen Thank you, that would be amazing

@danielchalmers If this all works would you mind looking at the coverage. We probably need an additional couple of tests in this area

@mikes-gh Sure, what kind of tests were you thinking?

@mikes-gh
Copy link
Contributor

@mikes-gh Sure, what kind of tests were you thinking?

Use codecov to view the untested lines. Some of them may not be your changes but it would be good to get the patch coverage up

@danielchalmers
Copy link
Contributor Author

should be looking good @mikes-gh

@mikes-gh
Copy link
Contributor

should be looking good @mikes-gh

Thanks @danielchalmers I know it seems pedantic but there's a reason BL0005 exists. Component parameters should pass through all the normal Component lifecycles for a true test.

@danielchalmers
Copy link
Contributor Author

@mikes-gh I don't think it's pedantic. I was just lazy and copy pasted from another test. Thanks for pointing it out 👌

@mikes-gh
Copy link
Contributor

It seems we still have a coverage deficiency though in line 293 ToggleMenu?

@danielchalmers
Copy link
Contributor Author

It seems we still have a coverage deficiency though in line 293 ToggleMenu?

Was the other method even covered? It's just a new overload and is covered by MenuTests.ToggleEventArgs() kind of.

How do you test IActivator? I couldn't see it in another tests but I probably just missed it.

@danielchalmers danielchalmers added the API change API that needs approval label Mar 27, 2024
@ScarletKuro
Copy link
Member

How do you test IActivator? I couldn't see it in another tests but I probably just missed it.

Depends on what you want to do.
For example if you want to override the IActivatable then its how it can be done https://try.mudblazor.com/snippet/wYQSanFmRxwqjzLD

@danielchalmers
Copy link
Contributor Author

@ScarletKuro just to satisfy code coverage

@mikes-gh
Copy link
Contributor

We should probably wait for @dennisrahmen #8492 (comment) before merging.

@dennisrahmen
Copy link
Contributor

@mikes-gh @danielchalmers for reference this was the problem I had when using 'OnAction', the first two menu items have 'OnClick' and 'OnTouch' the last one has just 'OnAction'.

current.mp4

I wanted to try it in the app you see above as it also has a MAUI version, but with the other breaking changes I would need more time to get it running.
In the meantime, if you think that is sufficient, I created a new Blazor WASM app and tested it there:

pullrequest.mp4

Now oddly enough, using the current MudBlazor Nuget on the app I created for the pull request the menu item does not work at all weather in desktop or mobile.

@dennisrahmen
Copy link
Contributor

I could get my app updated by mid next week and test it again, If you guys are willing to wait.
Not sure about you timeline for v7.

@danielchalmers
Copy link
Contributor Author

@dennisrahmen Thanks, this is all really helpful. Can you post the code for your second example?

@dennisrahmen
Copy link
Contributor

dennisrahmen commented Mar 29, 2024

@danielchalmers you can even see it in a tryMud:
Just switch from desktop to mobile in dev tools.
https://try.mudblazor.com/snippet/QEwxvlGVwWrSSpbr

That's the code I used, just removed the touch and action options since your version does not have them anymore.

@danielchalmers
Copy link
Contributor Author

I could get my app updated by mid next week and test it again, If you guys are willing to wait. Not sure about you timeline for v7.

It could get merged before then to avoid conflicts, but development is so heavy right now that having you test it afterwards is still extremely helpful because there won't be a new release by then anyway

@danielchalmers
Copy link
Contributor Author

@danielchalmers you can even see it in a tryMud: Just switch from desktop to mobile in dev tools. https://try.mudblazor.com/snippet/QEwxvlGVwWrSSpbr

That's the code I used, just removed the touch and action options since your version does not have them anymore.

Thanks, I believe that's #5768 and should be fixed by this PR 🤞

@henon
Copy link
Collaborator

henon commented Mar 30, 2024

What's the status?

@dennisrahmen
Copy link
Contributor

dennisrahmen commented Mar 30, 2024

@henon the issue I had with the current implementation should be fixed by this pr since another user reported a similar issue and that was already addressed by @danielchalmers

So as I understand @danielchalmers this pr is ready but I will still report my findings after I updated my app to the newest version in the v7.

@ScarletKuro ScarletKuro requested a review from henon March 30, 2024 17:08
@henon henon merged commit 4d97cb8 into MudBlazor:dev Apr 2, 2024
2 of 3 checks passed
@henon
Copy link
Collaborator

henon commented Apr 2, 2024

Thanks!

@dennisrahmen
Copy link
Contributor

@danielchalmers I finally updated my app to the preview-3 of v7 and could now test the behavior.
Sadly, still does not work for mobile, although I am not really sure what the problem is.

Would think it has something to do with the recognition of the mobile touch in general, as you see in the video in mobile view the sub menu does not even open, I just go straight to the links in the submenus.

MS Edge on the dev site and my app has the same issue as described before, the OnClick is not fired:

Menus.-.MudBlazor.-.Personlich.Microsoft.Edge.2024-05-15.02-14-03.mp4

@dennisrahmen
Copy link
Contributor

Here is my app, working in desktop view but not doing anything when in mobile:

iTS.Dashboard.und.3.weitere.Seiten.-.Personlich.Microsoft.Edge.2024-05-15.02-26-54.mp4

This is the menu code in my DataGrid:

<TemplateColumn Filterable="false" Sortable="false">
    <CellTemplate>
        <MudMenu Dense="true" Icon="@Icons.Material.Filled.MoreVert" Size="Size.Small" Color="Color.Primary">
            <MudMenuItem IconSize="Size.Small" Disabled="@(context.Item.DeviceType is null)" Icon="@Icons.Material.Filled.AppSettingsAlt" OnClick="() => UpdateDeviceConfig(context.Item)">Konfiguration</MudMenuItem>
            <MudMenuItem IconSize="Size.Small" Disabled="@(context.Item.DeviceType is null)" IconColor="Color.Warning" Icon="@Icons.Material.Filled.Edit" OnClick="() => UpdateDevice(context.Item)">Bearbeiten</MudMenuItem>
            <MudDivider Light DividerType="DividerType.Middle" Class="my-1"/>
            <MudMenuItem IconSize="Size.Small" IconColor="Color.Error" Icon="@Icons.Material.Filled.Delete" OnClick="() => RemoveDevice(context.Item)">Löschen</MudMenuItem>
        </MudMenu>
    </CellTemplate>
</TemplateColumn>

@danielchalmers
Copy link
Contributor Author

danielchalmers commented May 15, 2024

@dennisrahmen I believe that's a missing PreventDefault or StopPropagation in the MudListItems that make up the MudMenu content. Could you transfer what you posed to a new issue so I can reference it? Basically "touches pass through menu item" I guess

@AntMaster7
Copy link
Contributor

Thank you for fixing this. I was also affected by this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API change API that needs approval breaking change bug Something does not work as intended/expected enhancement New feature or request
Projects
None yet
6 participants