MudBlazor icon indicating copy to clipboard operation
MudBlazor copied to clipboard

MudTabs: Optionally cancel tab panel activations

Open Flaflo opened this issue 3 years ago • 5 comments

Description

This PR introduces a parameter for MudTabs (Func<int, Task>) that gets invoked as soon as a panel is about to get activated. It is written with async in mind so before the actual activation a developer might decide if activation should be cancelled because of checks done inside that func. (Backend-Call; Check if form filled; etc.)

Example:

<MudTabs OnPanelActivation="panelIndex => Task.FromResult(!CheckFormFilled(panelIndex))">
    @foreach (var tab in _tabs)
    {
        <MudTabPanel @key="tab" Text="@tab">
            <MudText>@tab</MudText>
        </MudTabPanel>
    }
</MudTabs>

How Has This Been Tested?

Tested with an additional unit test.

Types of changes

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

Checklist:

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

Flaflo avatar Jun 13 '22 13:06 Flaflo

Codecov Report

Base: 91.51% // Head: 91.38% // Decreases project coverage by -0.13% :warning:

Coverage data is based on head (733911e) compared to base (6ac4de2). Patch coverage: 100.00% of modified lines in pull request are covered.

:exclamation: Current head 733911e differs from pull request most recent head 57ed9bc. Consider uploading reports for the commit 57ed9bc to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #4738      +/-   ##
==========================================
- Coverage   91.51%   91.38%   -0.13%     
==========================================
  Files         384      365      -19     
  Lines       15078    12539    -2539     
==========================================
- Hits        13798    11459    -2339     
+ Misses       1280     1080     -200     
Impacted Files Coverage Δ
src/MudBlazor/Components/Tabs/MudTabs.razor.cs 97.30% <100.00%> (-0.43%) :arrow_down:
src/MudBlazor/Extensions/TimeSpanExtensions.cs 40.00% <0.00%> (-20.00%) :arrow_down:
src/MudBlazor/Components/DataGrid/HeaderCell.razor 72.22% <0.00%> (-17.44%) :arrow_down:
src/MudBlazor/Components/DataGrid/FooterContext.cs 75.00% <0.00%> (-15.00%) :arrow_down:
src/MudBlazor/Components/DataGrid/HeaderContext.cs 75.00% <0.00%> (-15.00%) :arrow_down:
src/MudBlazor/Components/DataGrid/CellContext.cs 66.66% <0.00%> (-11.91%) :arrow_down:
...azor/Services/ResizeListener/ResizeBasedService.cs 88.23% <0.00%> (-11.77%) :arrow_down:
.../MudBlazor/Components/Input/MudRangeInput.razor.cs 65.71% <0.00%> (-11.43%) :arrow_down:
...lazor/Components/Dialog/MudDialogProvider.razor.cs 86.11% <0.00%> (-8.89%) :arrow_down:
...dBlazor/Components/SwipeArea/MudSwipeArea.razor.cs 76.19% <0.00%> (-8.81%) :arrow_down:
... and 140 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

codecov[bot] avatar Jun 13 '22 13:06 codecov[bot]

Hi @Flaflo, I suggest we make the argument of the func a class. We could use the same func for intercepting tab delete too so for instance a dialog can be popped up "Do you want to close the tab with unsaved changes?". By having a class argument we can extend this even further without adding more parameters.

So how about renaming it OnPreviewInteraction with Type Func<TabInteractionEventArgs> where

public class TabInteractionEventArgs {
  public TabIndex { get; set; }
  public TabInteraction { get; set; }
  public bool Cancel { get; set; }
}

public enum TabInteraction { Click, Delete } // later we can have more if we need more

The name Preview is established in WPF for events that come before something happens and allow to cancel it. Would you agree to these changes?

henon avatar Jul 06 '22 14:07 henon

I totally agree. Sounds awesome!

Flaflo avatar Jul 06 '22 14:07 Flaflo

Activate is probably better than Click

henon avatar Jul 06 '22 15:07 henon

I will start working on this shortly.

Flaflo avatar Sep 06 '22 16:09 Flaflo

Thanks!

henon avatar Feb 16 '23 16:02 henon

@Flaflo Another good PR! I would like a simple example in the docs though.

Yomodo avatar Feb 17 '23 16:02 Yomodo

@Flaflo Another good PR! I would like a simple example in the docs though.

Oh, I think there is documentation for it generated in the API Section

Or do you mean a fully fledged example?

Flaflo avatar Feb 17 '23 17:02 Flaflo

Or do you mean a fully fledged example?

Yes, this. It is listed in the API docs, but a simple example on how to actually apply it would be great I think.

Yomodo avatar Feb 17 '23 18:02 Yomodo