Handling MudBlazor Popover dismissal

Just trying not to forget this...

Anywhere in the component, create a MudOverlay as shown below.  When the visibility of the overlay changes, the FiltersOverlayVisibileChanged gets called.

<MudOverlay @ref="@filtersOverlay"
            AutoClose="true"
            Visible="@filtersVisible"
            VisibleChanged="@FiltersOverlayVisibileChanged"/>
The invisible overlay that hears the click away from the popover.

Then in the C# code, add the following values.  The ToggleFiltersVisible is the method that shows/hides the overlay and the popover:

    MudOverlay? filtersOverlay;
    bool filtersVisible = false;
    void ToggleFiltersVisible() => filtersVisible = !filtersVisible;

And this method which handles what to do when the visibility changes.  Note that it sets the filtersVisible value which is bound to the visibility of the popover.  This links the visibility of the overlay and the popover:

public async Task<bool> VisibilityChangeHandler()
{
  filtersVisible = (filtersOverlay?.Visible ?? false);
  logger.LogInformation("Filters overlay visibility changed to {Visible}", filtersVisible);
  if (!filtersVisible && (_originalViewModel != AccountPickerState.AccountFiltersViewModel))
  {
    logger.LogInformation("Overlay closing and original view model does not match current state - restoring original values");
    await _mediator.Send(new AccountPickerState.UpdateFilters { FiltersViewModel = _originalViewModel });
    await _mediator.Send(new AccountPickerState.RefreshAccountSelectors());
   }
   else
   {
     logger.LogInformation("Original view model matches current state - nothing to do.");
   }
     return filtersVisible;
  }

And this to let the overlay do something when the visibility changes. You can see this method references the VisibilityChangeHandler above:

EventCallback<bool> FiltersOverlayVisibileChanged =>
   EventCallback.Factory.Create<bool>(this, async () => await VisibilityChangeHandler());

This is passed into the overlay so it can perform the method above when the visibility changes.