Skip to content

MudMenu: Fix PositionAtCursor#10122

Merged
ScarletKuro merged 24 commits intoMudBlazor:devfrom
versile2:fix/mudmenupopoverposition
Oct 30, 2024
Merged

MudMenu: Fix PositionAtCursor#10122
ScarletKuro merged 24 commits intoMudBlazor:devfrom
versile2:fix/mudmenupopoverposition

Conversation

@versile2
Copy link
Contributor

@versile2 versile2 commented Oct 28, 2024

Description

Mudmenu as a Context Menu and in some cases when using PositionAtCursor was not properly setting the position due to the args events relating to the container it's in not necessarily where the popover needed to nest. Our javascript would then jumble that up more and make it near impossible to have consistent behavior. These changes standardize anytime the exact position is known such as args.PageX and args.PageY to not allow javascript to determine position (except flipping behavior). This is accomplished by a class mud-popover-position-override

Additionally added a DataGrid Context Menu example in the Docs section and a MudTable (I don't recommend this, too laggy) and DataGrid example in the UnitTests.Viewer section.

Resolves #3060
Resolves #3854
Resolves #10073
Resolves: #8124

How Has This Been Tested?

Tons of visual tests in first comment

Type 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)
  • Documentation (fix or improvement to the website or code docs)

Checklist

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

@github-actions github-actions bot added bug Unexpected behavior or functionality not working as intended docs Updates/improvements to project documentation that do not affect core library logic enhancement Adds a new feature or enhances existing functionality (not fixing a defect) in the main library PR: needs review labels Oct 28, 2024
@versile2
Copy link
Contributor Author

versile2 commented Oct 28, 2024

Before:
PreFix

After:
PostFix

@codecov
Copy link

codecov bot commented Oct 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.23%. Comparing base (5f4d7c6) to head (a24111b).
Report is 85 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev   #10122      +/-   ##
==========================================
+ Coverage   91.18%   91.23%   +0.05%     
==========================================
  Files         411      411              
  Lines       12480    12484       +4     
  Branches     2431     2431              
==========================================
+ Hits        11380    11390      +10     
+ Misses        556      552       -4     
+ Partials      544      542       -2     

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

@versile2
Copy link
Contributor Author

I don't know how to make codecov happy.

@ScarletKuro ScarletKuro changed the title Fix and Enhance MudMenu for Context Menu MudMenu: Fix and Enhance for Context Menu Oct 29, 2024
@ScarletKuro ScarletKuro self-requested a review October 29, 2024 20:41
@ScarletKuro ScarletKuro self-assigned this Oct 29, 2024
@ScarletKuro
Copy link
Member

This also fixes: #8124

@ScarletKuro
Copy link
Member

ScarletKuro commented Oct 30, 2024

I fixed all the problems etc.
The style check you possible could grab from the popover if you want. But as you can see the codecov doesn't complain anymore.

But I think using the DataGrid in the OpenMenuAsync_Should_Set_FixedPosition() aka DataGridContextMenuTest is too heavy.
I would rather just use the code for testing from the #8124

upd: anyway, going bed now, its very late and I'm doing more and more typos in the text.

P.S. I also noticed it's writing in AnchorOrigin, but considering it's old code and was there before, I'm not going to bother for now. This is task for later.

@ScarletKuro ScarletKuro removed the docs Updates/improvements to project documentation that do not affect core library logic label Oct 30, 2024
@versile2
Copy link
Contributor Author

The context menu example is broken, the menu is being rendered to the page:

image

When you click it the wasm app crashes.

@ScarletKuro
In WASM any line that does this or similar causes the app to crash (is not particular to the context menu) and they all work in Server Mode.
await httpClient.GetFromJsonAsync<List>("webapi/periodictable")

@ScarletKuro
Copy link
Member

The context menu example is broken, the menu is being rendered to the page:
image
When you click it the wasm app crashes.

@ScarletKuro In WASM any line that does this or similar causes the app to crash (is not particular to the context menu) and they all work in Server Mode. await httpClient.GetFromJsonAsync("webapi/periodictable")

Are we talking about MudBlazor.Docs.Wasm? That's expected since it's doing API call, but there is no server running with the controlled, so just ignore it.

@meenzen
Copy link
Contributor

meenzen commented Nov 27, 2024

That invisible menu shouldn't be rendered in the first place

@versile2
Copy link
Contributor Author

That invisible menu shouldn't be rendered in the first place

If I understand what you are saying, all the popovers work that way, inspect a page with a mudselect, mudautocomplete, tooltip, etc find the popover provider element and every popover will be listed there just not visible. The visible ones will have a data-ticks attribute > 0

@ScarletKuro
Copy link
Member

ScarletKuro commented Nov 27, 2024

That invisible menu shouldn't be rendered in the first place

If I understand what you are saying, all the popovers work that way, inspect a page with a mudselect, mudautocomplete, tooltip, etc find the popover provider element and every popover will be listed there just not visible. The visible ones will have a data-ticks attribute > 0

Are we talking about the Popover Provider? Unfortunately, on this screen, I can't tell if it is coming from the provider or not. If it is, then that’s expected and unrelated to this PR, it will list all popovers inside it as invisible with empty content. When Open=true, they become visible with their content.

<div class="mud-popover-provider">
@foreach (var handler in PopoverService.ActivePopovers)
{
<MudRender @ref="handler.ElementReference" @key="handler.Id">
<div id="@($"popovercontent-{handler.Id}")" data-ticks="@(handler.ActivationDate?.Ticks ?? 0)" @attributes="@handler.UserAttributes" class="@handler.Class" style="@handler.Style">
@if (handler.ShowContent)
{
@handler.Fragment
}
</div>
</MudRender>
}
</div>

(heh, just noticed that the formatting in the file is not correct)

This was architected this way long before I joined the team, I only boosted the performance, but the principal is still the same.

@versile2
Copy link
Contributor Author

looks like what's mentioned isn't from the provider after further research but also it's required. Popover needs a parent to place itself. There's nearly nothing in it, the actual menu is with the provider.

<div id="_contextMenu" class="mud-menu"><!--!--><!--!--><button type="button" class="mud-button-root mud-button mud-button-text mud-button-text-default mud-button-text-size-medium mud-ripple" _bl_649=""><span class="mud-button-label"></span></button><!--!--><div id="popover-d0144102-d780-4ada-9c36-f1aeeba99cee" class="mud-popover-cascading-value"></div><!--!-->

    <!--!--><div class="mud-overlay" style=""></div></div>

@henon
Copy link
Contributor

henon commented Nov 28, 2024

So to summarize the invisible element needs to be there, but clicking it shouldn't cause a crash, I guess.

@meenzen
Copy link
Contributor

meenzen commented Nov 28, 2024

The invisible element must not:

  • be visible (so users or screen readers don't get confused)
  • be clickable (so the crash condition is impossible to produce)
  • take up any space (so it doesn't break the layout)

Currently the menu renders as an empty button. IMHO this button element should not be rendered at all.

@ScarletKuro
Copy link
Member

ScarletKuro commented Nov 28, 2024

I was able to reproduce the issue with this example:
https://github.com/MudBlazor/MudBlazor/blob/43fbb956b46650885a4b25230fece4a1c81ed253/src/MudBlazor.UnitTests.Viewer/TestComponents/DataGrid/DataGridContextMenuTest.razor

There is indeed a hidden clickable element that crashes both server-side and wasm.
The stack trace:

blazor.web.js:1 
 crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: Object reference not set to an instance of an object.
System.NullReferenceException: Object reference not set to an instance of an object.
   at MudBlazorWebAppAuto.Client.Pages.Counter.<BuildRenderTree>b__0_14(RenderTreeBuilder __builder3)
   at Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddContent(Int32 sequence, RenderFragment fragment)
   at MudBlazor.MudMenuItem.<BuildRenderTree>b__53_0(RenderTreeBuilder __builder2)
   at Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddContent(Int32 sequence, RenderFragment fragment)
   at MudBlazor.MudListItem`1[[System.Object, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].<BuildRenderTree>b__141_3(RenderTreeBuilder __builder3) in C:\Users\KuroPC\source\repos\MudBlazor\src\MudBlazor\Components\List\MudListItem.razor:line 51
   at Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddContent(Int32 sequence, RenderFragment fragment)
   at MudBlazor.MudText.<BuildRenderTree>b__37_0(RenderTreeBuilder __builder2)
   at Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddContent(Int32 sequence, RenderFragment fragment)
   at MudBlazor.MudElement.BuildRenderTree(RenderTreeBuilder builder) in C:\Users\KuroPC\source\repos\MudBlazor\src\MudBlazor\Components\Element\MudElement.cs:line 99
   at Microsoft.AspNetCore.Components.ComponentBase.<.ctor>b__7_0(RenderTreeBuilder builder)
   at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment, Exception& renderFragmentException)

When clicking on it, the popover opens BUT this PR is not the cause of the issue. Setting PositionAtCursor to false or completely reverting this commit does not fix it. Therefore, I am removing the regression label from this PR.
I don't see anything in the example that would cause this hidden thing to showup, so I think we should look the problem somewhere else than look it in the example?

@ScarletKuro ScarletKuro removed the regression Previously worked and now doesn't label Nov 28, 2024
@ScarletKuro
Copy link
Member

@ScarletKuro
Copy link
Member

Null exception is fixed in #10352

LLauter pushed a commit to cannellamedia/MudBlazor that referenced this pull request Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Unexpected behavior or functionality not working as intended enhancement Adds a new feature or enhances existing functionality (not fixing a defect) in the main library

Projects

None yet

4 participants