Skip to content

MudOverlay: Refactor, Deprecate OnClick in favor of new OnClosed, Fix MudMenu interactions#9458

Merged
henon merged 11 commits intoMudBlazor:devfrom
danielchalmers:mud-overlay-changes
Jul 24, 2024
Merged

MudOverlay: Refactor, Deprecate OnClick in favor of new OnClosed, Fix MudMenu interactions#9458
henon merged 11 commits intoMudBlazor:devfrom
danielchalmers:mud-overlay-changes

Conversation

@danielchalmers
Copy link
Member

@danielchalmers danielchalmers commented Jul 20, 2024

Description

Changes:

  • Resolves MudOverlay: Remove OnClick callback #8989
  • Adds Appearance category for background colors
  • Obsoletes OnClick event
  • Adds OnClosed event to pair with AutoClose which can support non-click methods in the future like escape key
  • Removes incorrectly placed preventDefault from mud menu's popover

Other:

  • Improves site docs and code docs
  • Adds many new tests
  • Formats files (+file-scoped namespaces)

How Has This Been Tested?

visually

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)

Menu inside SwipeArea - Fixes #9288

video1.mp4

Menu will close correctly and items can be clicked inside Drop Zone - Fixes #7047

video3.mp4

Menu will not be affected by snackbar - Fixes #9413

video3.mp4

Doesn't regress to menu items triggering things behind - #8790

video2.mp4

Fixes #9479

video3.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.

@danielchalmers

This comment was marked as outdated.

@codecov
Copy link

codecov bot commented Jul 20, 2024

Codecov Report

Attention: Patch coverage is 88.88889% with 3 lines in your changes missing coverage. Please review.

Project coverage is 90.54%. Comparing base (28bc599) to head (2463575).
Report is 379 commits behind head on dev.

Files Patch % Lines
...c/MudBlazor/Components/Overlay/MudOverlay.razor.cs 91.30% 1 Missing and 1 partial ⚠️
...r/Components/Autocomplete/MudAutocomplete.razor.cs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #9458      +/-   ##
==========================================
+ Coverage   89.82%   90.54%   +0.71%     
==========================================
  Files         412      406       -6     
  Lines       11878    12705     +827     
  Branches     2364     2462      +98     
==========================================
+ Hits        10670    11504     +834     
+ Misses        681      641      -40     
- Partials      527      560      +33     

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

@ScarletKuro
Copy link
Member

If you go the mud menu docs page, open the menu, then click somewhere else on the page, this line will execute:

Handlers only fire when the parent modifies the destination parameter.
By the way, originally this was supposed to be removed in v7:

private Task OnVisibleParameterChangedAsync()
{
return VisibleChanged.InvokeAsync(_visibleState.Value);
}

But I forgot. It was added for backward compatibility since I was making it for v6, and in the original code, it was doing this:

public bool Visible
{
get => _visible;
set
{
if (_visible == value)
return;
_visible = value;
VisibleChanged.InvokeAsync(_visible);
}
}

In good code, the VisibleChanged shouldn't be called when the parent modifies the parameter.

I don't think your code is correct. It should be:

if (AutoClose)
{
	await _visibleState.SetValueAsync(false);
	await OnClosed.InvokeAsync();
}
private async Task OnVisibleParameterChangedAsync(ParameterChangedEventArgs<bool> args)
{
	if (!args.Value)
	{
		await OnClosed.InvokeAsync(); // I'm not sure we should call OnClosed when Visible was modified by the parent, but it really depends on what you are trying to achieve.
	}
}

Something along those lines

@danielchalmers
Copy link
Member Author

@ScarletKuro I made changes like that a bit ago, could you check again?

@danielchalmers danielchalmers changed the title Mud overlay changes MudOverlay: Refactor, Deprecate OnClick in favor of new OnClosed, Fix MudMenu interactions Jul 20, 2024
@danielchalmers danielchalmers marked this pull request as ready for review July 20, 2024 19:17
@danielchalmers danielchalmers added 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 API change Modifies the public API surface labels Jul 23, 2024
@ScarletKuro ScarletKuro requested a review from henon July 23, 2024 20:28
Copy link
Member

@ScarletKuro ScarletKuro left a comment

Choose a reason for hiding this comment

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

Seems to work

@henon
Copy link
Contributor

henon commented Jul 24, 2024

A functionality I can see that will be required in the future is the possibility to prevent closing in some cases due to application specific logic. This could be accomplished by a separate OnClosing event that is fired first and the overlay will close only if the Cancel arg of the ClosingEventArgs was not set true by its handler. But this can be in another PR and maybe only if it is really needed.

@henon henon merged commit 3eaaa46 into MudBlazor:dev Jul 24, 2024
@henon
Copy link
Contributor

henon commented Jul 24, 2024

Awesome! Great PR @danielchalmers

@ScarletKuro
Copy link
Member

ScarletKuro commented Jul 25, 2024

A functionality I can see that will be required in the future is the possibility to prevent closing in some cases due to application specific logic. This could be accomplished by a separate OnClosing event that is fired first and the overlay will close only if the Cancel arg of the ClosingEventArgs was not set true by its handler. But this can be in another PR and maybe only if it is really needed.

you mean like with WPF that it has property e.Handled = true in the args (for example KeyPressEventArgs) and it was called then you ignore the default behavior (close)?

@henon
Copy link
Contributor

henon commented Jul 25, 2024

Yes, that is what I mean. Window has also a Closing event that can be cancelled, so when the user clicks the X you can first check if you really want to close the window and abort if you have unsaved changes, etc.

@ScarletKuro
Copy link
Member

Yes, that is what I mean. Window has also a Closing event that can be cancelled, so when the user clicks the X you can first check if you really want to close the window and abort if you have unsaved changes, etc.

Sounds good to me, tho it will be breaking if we add it later, because the signature:

public EventCallback OnClosed { get; set; }

needs to be changed to something like EventCallback<CloseArgs>

@henon
Copy link
Contributor

henon commented Jul 25, 2024

No, you would add a separate event OnClosing that is fired first. OnClosed would be fired after that if the close really happened

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API change Modifies the public API surface 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

3 participants