Skip to content

Responsive Offcanvas requires suppressing class="offcanvas" #849

Open
@SerratedSharp

Description

@SerratedSharp

Propose to add an EnableDefaultClass parameter property that allows the default class to be suppressed as needed.

Describe the bug
Responsive offcanvas offcanvas-lg should not have class="offcanvas" per this example: https://getbootstrap.com/docs/5.3/components/offcanvas/#responsive

To Reproduce
<Offcanvas class="offcanvas-lg"> produces class="offcanvas offcanvas-lg" which breaks the responsiveness(showing content on page above breakpoint) and also makes the offcanvas transparent(when page width is above breakpoint and offcanvas is shown).

Screenshots
How the bug looks when larger than breakpoint and offcanvas shown:
image

Proposed Solution
Verified fix by inheriting from Offcanvas and overriding ClassNames to allow the default class to be disabled:

  [Parameter]
  public bool EnableDefaultClass { get; set; } = true;

  protected override string? ClassNames =>
      BuildClassNames(Class,
          (BootstrapClass.Offcanvas, EnableDefaultClass),
          (Placement.ToOffcanvasPlacementClass(), true),
          (Size.ToOffcanvasSizeClass(), true));

The only remaining problem is this line is hardcoded to expect a class "offcanvas" and so it breaks the dismiss button when class is suppressed. data-bs-dismiss="offcanvas" would need to be adjusted.

@if (ShowCloseButton)
{
    <button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
}

Usage:
<OffcanvasEx @ref="offcanvas" EnableDefaultClass="false" class="offcanvas-lg">

Versions (please complete the following information):

  • .NET Version: [e.g. .NET 6, .NET 7, .NET 8]
  • BlazorBootstrap: 3.0.0 preview.3
  • Blazor WebAssembly
  • Blazor Interactive Render Mode: Auto
  • Blazor Interactivity Location: Not sure

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions