MudMenuItem: Add OnAction for either click or touch but invoked only once#7651
MudMenuItem: Add OnAction for either click or touch but invoked only once#7651henon merged 7 commits intoMudBlazor:devfrom
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## dev #7651 +/- ##
==========================================
- Coverage 90.57% 86.19% -4.39%
==========================================
Files 427 427
Lines 15223 15259 +36
Branches 0 3326 +3326
==========================================
- Hits 13788 13152 -636
+ Misses 1435 1424 -11
- Partials 0 683 +683
☔ View full report in Codecov by Sentry. |
src/MudBlazor.UnitTests.Viewer/TestComponents/Menu/MenuItemActionTest.razor
Show resolved
Hide resolved
On what platforms did you test it? Browser(wasm, bss), android(maui), windows(maui)? |
|
browser (wasm) on Windows and Android |
- _lastActionHandled from protected to private.
|
The page https://mudblazor.com/api/menuitem exists, but I didn't find it in the documentation. Is this intentional? |
It's under menu https://mudblazor.com/components/menu because |
|
Before merging, we would need someone to test this on iOS, sadly I don't have Iphone either. Also regarding this
If you want to do that, I would consider using the |
| /// </remarks> | ||
| [Parameter] | ||
| [Category(CategoryTypes.Menu.Behavior)] | ||
| public TimeSpan SilenceTime { get; set; } = TimeSpan.FromMilliseconds(100); |
There was a problem hiding this comment.
-
I think we should call this
DebounceIntervalto be consistent with other components. Also the termdebounceis fitting here, see: https://www.freecodecamp.org/news/javascript-debounce-example/#:~:text=What%20is%20debounce%3F,your%20%E2%80%9Cclick%E2%80%9D%20multiple%20times. -
Actually this is something you usually want to change for every menu in the application if you want to change it. I suspect this will never ever have to be changed anyway.
@ScarletKuro What would you say about not making it a [Parameter] and instead public static TimeSpan DebounceInterval { get; set; } = TimeSpan.FromMilliseconds(100); ?
There was a problem hiding this comment.
I think it makes sense, because if it is necessary to change this value for one component, it will probably be necessary to change it for all of the items. Can I change it to static?
There was a problem hiding this comment.
Yes, make it static and remove the attributes, which are then no longer needed.
There was a problem hiding this comment.
@henon wouldn't it make sense to add it to the MudGlobal instead?
There was a problem hiding this comment.
You are right, I have already forgotten about that. MenuItemDebounceInterval ?
There was a problem hiding this comment.
So, I put it as static property in static class MudGlobal with name MenuItemDebounceInterval?
|
IOS is untested at this moment, nobody in the team is IPhone user. We'll just have to risk it. |
|
Thanks @GRMagic ! |
…once (MudBlazor#7651) * MudMenuItem Href, OnClick, OnTouch, OnAction * MudGlobal.MenuItemDebounceInterval
|
@GRMagic thanks for this improvement, I just tested it. It seems to not be working correctly on mobile. So there is something happening there, since it is working fine in Desktop mode as well as with 'OnClick' and 'OnTouch' |
|
Did you remove onclick and ontouch, leaving only onaction? |
|
@GRMagic yes, I only have You can check it here: https://try.mudblazor.com/snippet/QEwxvlGVwWrSSpbr |
|
Maybe something specific to WASM? As I use it and tryMudBlazor also uses WASM. |
|
I am also using wasm. I tested your code on my development branch and it worked. |
|
In master the code also works, but in try mudblazor it didn't work. |
|
Upgraded a wasm project to mudblazor version 6.11.1, and tested your code on it, it worked. |
|
I am using 6.11.1 in my App. |
|
In most of the time it is preferable to use async Task instead of async void. Try change it too. |
|
I just pulled the code in the TryMud together from two examples to make it simpler: This is my code inside a DataGrid column: And the code behind: |
Description
OnAction will only be invoked once, when the user clicks or touch the menu item.
If OnClick is set, OnAction is not called on user clicks.
If OnTouch is set, OnAction is not called on user touch.
Thus maintaining backwards compatibility.
Example:
<MudMenuItem OnAction="MyAction">My Item</MudMenuItem>How Has This Been Tested?
Tests in MenuItemActionTest.cs
I don't have an Apple, could someone test it for me?
Types of changes
Checklist:
dev).See
Discussion: #6954