Skip to content

Commit

Permalink
Docs: Programatically removing a Snackbar (MudBlazor#5016)
Browse files Browse the repository at this point in the history
* added documentation for programatically remove snackbar

* updated text and highligthing
  • Loading branch information
sigurdmwahl committed Aug 24, 2022
1 parent 7e6ee9a commit 56202c8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
@@ -0,0 +1,27 @@
@namespace MudBlazor.Docs.Examples

@inject ISnackbar Snackbar

<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="@Show">
Open Snackbar
</MudButton>
<MudButton Variant="Variant.Filled" Color="Color.Error" OnClick="@Hide">
Hide snackbar
</MudButton>

@code {
private Snackbar _snackbar;

void Show()
{
_snackbar = Snackbar.Add("Now click hide snackbar", Severity.Normal, config =>
{
config.VisibleStateDuration = int.MaxValue;
});
}

void Hide() {
if (_snackbar is null) return;
Snackbar.Remove(_snackbar);
}
}
11 changes: 11 additions & 0 deletions src/MudBlazor.Docs/Pages/Components/Snackbar/SnackbarPage.razor
Expand Up @@ -144,5 +144,16 @@
</SectionContent>
</DocsPageSection>

<DocsPageSection>
<SectionHeader Title="Programmatically remove">
<Description>
Using the injected ISnackbar, you can use the <CodeInline>.Remove</CodeInline> method to remove a Snackbar programmatically.
</Description>
</SectionHeader>
<SectionContent Code="SnackbarRemoveExample" ShowCode="false">
<SnackbarRemoveExample />
</SectionContent>
</DocsPageSection>

</DocsPageContent>
</DocsPage>

0 comments on commit 56202c8

Please sign in to comment.