Offcanvas Start
Offcanvas Content
Blazorise Offcanvas component allows to build hidden sidebars into your project for navigation, shopping carts.
Offcanvas is a sidebar component that can be toggled to appear from the start, end, top, or bottom edge of the viewport.
<Offcanvas>
the main container
<OffcanvasHeader>
, a main offcanvas title.
<OffcanvasBody>
, a main content of the offcanvas.
<OffcanvasFooter>
, a main offcanvas footer.
<Offcanvas @ref="offcanvasRef" ShowBackdrop Placement="Placement.Start"> <OffcanvasHeader> Offcanvas Start <CloseButton Clicked="" /> </OffcanvasHeader> <OffcanvasBody> Offcanvas Content </OffcanvasBody> </Offcanvas> <Button Color="Color.Primary" Clicked="">Show Offcanvas Start</Button>
@code { private Offcanvas offcanvasRef; private Task ShowOffcanvas() { return offcanvasRef.Show(); } private Task HideOffcanvas() { return offcanvasRef.Hide(); } }
<Offcanvas @ref="offcanvasRef" ShowBackdrop Placement="Placement.Top"> <OffcanvasHeader> Offcanvas Top <CloseButton Clicked="" /> </OffcanvasHeader> <OffcanvasBody> Offcanvas Content </OffcanvasBody> </Offcanvas> <Button Color="Color.Primary" Clicked="">Show Offcanvas Top</Button>
@code { private Offcanvas offcanvasRef; private Task ShowOffcanvas() { return offcanvasRef.Show(); } private Task HideOffcanvas() { return offcanvasRef.Hide(); } }
<Offcanvas @ref="offcanvasRef" ShowBackdrop Placement="Placement.Bottom"> <OffcanvasHeader> Offcanvas Bottom <CloseButton Clicked="" /> </OffcanvasHeader> <OffcanvasBody> Offcanvas Content </OffcanvasBody> </Offcanvas> <Button Color="Color.Primary" Clicked="">Show Offcanvas Bottom</Button>
@code { private Offcanvas offcanvasRef; private Task ShowOffcanvas() { return offcanvasRef.Show(); } private Task HideOffcanvas() { return offcanvasRef.Hide(); } }
<Offcanvas @ref="offcanvasRef" ShowBackdrop Placement="Placement.End"> <OffcanvasHeader> Offcanvas End <CloseButton Clicked="" /> </OffcanvasHeader> <OffcanvasBody> Offcanvas Content </OffcanvasBody> </Offcanvas> <Button Color="Color.Primary" Clicked="">Show Offcanvas End</Button>
@code { private Offcanvas offcanvasRef; private Task ShowOffcanvas() { return offcanvasRef.Show(); } private Task HideOffcanvas() { return offcanvasRef.Hide(); } }
Closing
event.
<Offcanvas @ref="offcanvasRef" ShowBackdrop Closing=""> <OffcanvasHeader> Offcanvas Start <CloseButton Clicked="" /> </OffcanvasHeader> <OffcanvasBody> <Div Padding="Padding.Is3"> Offcanvas Content </Div> <Div Padding="Padding.Is3"> <Button Color="Color.Secondary" Clicked="">This will close the offcanvas</Button> <Button Color="Color.Primary" Clicked="">This will not</Button> </Div> </OffcanvasBody> </Offcanvas> <Button Color="Color.Primary" Clicked="">Show Offcanvas Start</Button>
@code { private Offcanvas offcanvasRef; private bool cancelClose; private Task ShowOffcanvas() { return offcanvasRef.Show(); } private Task HideOffcanvas() { cancelClose = false; return offcanvasRef.Hide(); } private Task TryHideOffcanvas() { cancelClose = true; return offcanvasRef.Hide(); } private Task OnOffcanvasClosing( OffcanvasClosingEventArgs e ) { // just set Cancel to prevent offcanvas from closing e.Cancel = cancelClose || e.CloseReason != CloseReason.UserClosing; return Task.CompletedTask; } }
OffcanvasFooter
component.
<Offcanvas @ref="offcanvasRef" ShowBackdrop> <OffcanvasHeader> Offcanvas Start <CloseButton Clicked="" /> </OffcanvasHeader> <OffcanvasBody> Offcanvas Content </OffcanvasBody> <OffcanvasFooter> <Button Color="Color.Primary" Clicked="">Close Offcanvas</Button> </OffcanvasFooter> </Offcanvas> <Button Color="Color.Primary" Clicked="">Show Offcanvas</Button>
@code { private Offcanvas offcanvasRef; private Task ShowOffcanvas() { return offcanvasRef.Show(); } private Task HideOffcanvas() { return offcanvasRef.Hide(); } }
Name | Description | Type | Default |
---|---|---|---|
Visible |
Determines whether the Offcanvas is visible or hidden. | bool |
false |
VisibleChanged |
Occurs when the Visible property value changes. | EventCallback<bool> |
|
Animated |
Determines whether the Offcanvas has animation. | bool |
true |
AnimationDuration |
The duration of the Offcanvas animation in milliseconds. | int |
300 |
ShowBackdrop |
Determines whether to show the backdrop behind the Offcanvas. | bool |
true |
Placement |
The placement of the Offcanvas (Start, End, Top, Bottom). | Placement |
Placement.Start |
Name | Description | Type | Default |
---|---|---|---|
Class |
The custom CSS class for the OffcanvasHeader. | string |
Name | Description | Type | Default |
---|---|---|---|
Class |
The custom CSS class for the OffcanvasBody. | string |
Name | Description | Type | Default |
---|---|---|---|
Class |
The custom CSS class for the OffcanvasFooter. | string |