Skip to content

Commit 6947923

Browse files
committed
- Fixed vikramlearning#849 by providing an option to suppress the default "offcanvas" class following BS docs for responsive offcanvas.
- Includes recommended workaround for dismiss button where the default class is ommitted for this scenario per twbs/bootstrap#36962 - Added example to demos for this scenario. Tested using Demo.WebASsembly project.
1 parent 8c01a53 commit 6947923

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

BlazorBootstrap.Demo.RCL/Components/Pages/Offcanvas/OffcanvasDocumentation.razor

+4
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@
5858
<div class="mb-3">Blazor Bootstrap offcanvas component exposes a few events for hooking into offcanvas functionality.</div>
5959
<Demo Type="typeof(Offcanvas_Demo_06_Events)" Tabs="true" />
6060

61+
<SectionHeading Size="HeadingSize.H2" Text="Responsive" PageUrl="@pageUrl" HashTagName="responsive" />
62+
<div class="mb-3">Blazor Bootstrap offcanvas component can implement responsiveness to show its content inline on larger devices and revert to default hidden behavior on smaller devices. This example switches between the two responsive views at the lg breakpoint.</div>
63+
<Demo Type="typeof(Offcanvas_Demo_07_Responsive)" Tabs="true" />
64+
6165
@code {
6266
private string pageUrl = "/offcanvas";
6367
private string title = "Blazor Offcanvas Component";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
@* Per bootstrap documentation, disable the default "offcanvas" class and replace with responsive offcanvas-lg class.
2+
This will make the offcanvas appear as a modal on small devices and on larger devices show the content inline.
3+
*@
4+
<Offcanvas @ref="offcanvas" Title="Responsive Offcanvas" Class="offcanvas-lg" EnableDefaultClass="false">
5+
<BodyTemplate>...</BodyTemplate>
6+
</Offcanvas>
7+
8+
@* Only show the button when the offcanvas is hidden belkow its breakpoint. *@
9+
<Button Class="d-lg-none" Color="ButtonColor.Primary" @onclick="() => OnShowOffcanvasClick()">Show offcanvas</Button>
10+
11+
@code {
12+
private Offcanvas offcanvas = default!;
13+
private Placement placement;
14+
15+
private async Task OnShowOffcanvasClick()
16+
{
17+
await offcanvas.ShowAsync();
18+
}
19+
}

blazorbootstrap/Components/Offcanvas/Offcanvas.razor

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
@if (ShowCloseButton)
1818
{
19-
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
19+
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" data-bs-target="#@Id" aria-label="Close"></button>
2020
}
2121
</div>
2222
}

blazorbootstrap/Components/Offcanvas/Offcanvas.razor.cs

+10-1
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,19 @@ private async Task ShowAsync(string? title, Type? type, Dictionary<string, objec
101101

102102
protected override string? ClassNames =>
103103
BuildClassNames(Class,
104-
(BootstrapClass.Offcanvas, true),
104+
(BootstrapClass.Offcanvas, EnableDefaultClass),
105105
(Placement.ToOffcanvasPlacementClass(), true),
106106
(Size.ToOffcanvasSizeClass(), true));
107107

108+
/// <summary>
109+
/// When set to false, suppresses the rendering of the default "offcanvas" class, which must be ommitted in some scenarios such as a responsive offcanvas.
110+
/// </summary>
111+
/// <remarks>
112+
/// Defaults to true.
113+
/// </remarks>
114+
[Parameter]
115+
public bool EnableDefaultClass { get; set; } = true;
116+
108117
/// <summary>
109118
/// Gets or sets the body CSS class.
110119
/// </summary>

0 commit comments

Comments
 (0)