blazor-devexpress-dot-blazor-d2a625d0.md
A side panel that supports minimized layout and expand/collapse operations.
Namespace : DevExpress.Blazor
Assembly : DevExpress.Blazor.v25.2.dll
NuGet Package : DevExpress.Blazor
public class DxDrawer :
DxComponentBase
The DevExpress Drawer for Blazor (<DxDrawer>) allows you to add a side panel to your application. Use this panel to host navigation controls or display additional information about the current view.
Follow the steps below to add the Drawer component to an application:
<DxDrawer>…</DxDrawer> markup to a .razor file.Refer to the following list for the component API reference: DxDrawer Members.
The DxDrawer component consists of a drawer panel and a target content area. The drawer panel can include header, body, and footer. If a header or footer is not specified, the body occupies the free space.
<DxDrawer IsOpen="true" >
<HeaderTemplate>Header Template</HeaderTemplate>
<BodyTemplate>Body Template</BodyTemplate>
<FooterTemplate>Footer Template</FooterTemplate>
<TargetContent>Target Content</TargetContent>
</DxDrawer>
The DxDrawer component allows you to implement different visibility scenarios.
Set the IsOpen property to true to display the drawer permanently.
<DxDrawer IsOpen="true" PanelWidth="20%">
...
</DxDrawer>
<DxButton Click="OnClick" IconCssClass="tb-icon icon-hamburger"
RenderStyleMode="ButtonRenderStyleMode.Outline" />
<DxDrawer @bind-IsOpen="IsOpen" PanelWidth="20%">
...
</DxDrawer>
@code {
bool IsOpen { get; set; } = true;
void OnClick() {
IsOpen = !IsOpen;
}
}
Enable the MiniModeEnabled property to change drawer width instead of closing. Use the MiniPanelWidth property to specify the width of the minimized panel.
Combine DxDrawer and DxLayoutBreakpoint components to adapt page layout to different devices. For instance, you can use the XSmall breakpoint to change drawer settings for small screens.
<DxLayoutBreakpoint DeviceSize="DeviceSize.XSmall" IsActive="isXSmallScreen" IsActiveChanged="IsActiveChanged" />
<DxButton Click="OnClick" IconCssClass="tb-icon icon-hamburger" />
<DxDrawer IsOpen="IsOpen" PanelWidth="180px">
...
</DxDrawer>
@code {
bool isXSmallScreen;
bool? isOpen;
bool IsOpen {
// Hide the Drawer on small screens initially and display it on large screens
get => isOpen ?? !isXSmallScreen;
set => isOpen = value;
}
// Apply Overlap and Shrink modes on small and large screens, respectively
DrawerMode Mode => isXSmallScreen ? DrawerMode.Overlap : DrawerMode.Shrink;
void IsActiveChanged(bool isActive) {
isXSmallScreen = isActive;
isOpen = null;
}
void OnClick() {
IsOpen = !IsOpen;
}
}
The DxDrawer component requires interactive render mode to change its IsOpen state. In static SSR mode, you can use a permanently visible drawer or implement one of the following strategies to dynamically change drawer visibility.
<DxDrawer PanelWidth="240px" IsOpen="@IsOpen">
<BodyTemplate>
<DxMenu Orientation="@Orientation.Vertical">
<Items>
<DxMenuItem Text="Home" NavigateUrl="@GetUrlWithParameter("/")" IconCssClass="icon-home" />
<DxMenuItem Text="Weather" NavigateUrl="@GetUrlWithParameter("weather")" IconCssClass="icon-weather" />
</Items>
</DxMenu>
</BodyTemplate>
<TargetContent>
<div class="top-row">
@* Toggle button that controls drawer visibility *@
<NavLink href="@(new Uri(NavigationManager.Uri).LocalPath + "?IsOpen=" + (!IsOpen).ToString())">
</NavLink>
</div>
@Body
</TargetContent>
</DxDrawer>
@code {
[SupplyParameterFromQuery]
public bool IsOpen { get; set; }
string GetUrlWithParameter(string url) {
// Save drawer visibility state while navigating
return url + "?IsOpen=" + IsOpen.ToString();
}
}
This approach is used within DevExpress Blazor project templates.
Switch drawer visibility (set width to zero) based on toggle element state.
<DxDrawer PanelWidth="240px" IsOpen="@true">
<BodyTemplate>
<DxMenu Orientation="@Orientation.Vertical">
<Items>
<DxMenuItem Text="Home" NavigateUrl="/" IconCssClass="icon-home" />
<DxMenuItem Text="Weather" NavigateUrl="weather" IconCssClass="icon-weather" />
</Items>
</DxMenu>
</BodyTemplate>
<TargetContent>
<div class="top-row">
<input type="checkbox" title="Toggle Drawer" class="navbar-toggler icon-menu" checked />
</div>
@Body
</TargetContent>
</DxDrawer>
.dxbl-drawer:has(.navbar-toggler:not(:checked)) .dxbl-drawer-panel {
width: 0 !important;
}
.navbar-toggler {
appearance: none;
cursor: pointer;
}
View Example: Responsive Drawer in Static SSR Mode
Use the Position property to specify the drawer position relative to the target content.
Run Demo: Drawer Position and Mode
<DxDrawer IsOpen="IsOpen" Position="DrawerPosition.Right" PanelWidth="20%">
<BodyTemplate>
<DxMenu Orientation="Orientation.Vertical">
<Items>
<DxMenuItem Text="Home" IconCssClass="menu-icon-home menu-icon" />
<DxMenuItem Text="Components" IconCssClass="menu-icon-products menu-icon" />
<DxMenuItem Text="Support" IconCssClass="menu-icon-support menu-icon" />
<DxMenuItem Text="Contacts" IconCssClass="menu-icon-contacts menu-icon" />
<DxMenuItem Text="About" IconCssClass="menu-icon-about menu-icon" />
</Items>
</DxMenu>
</BodyTemplate>
<TargetContent>
@* Lorem ipsum dolor sit amet, consectetur adipiscing elit ... *@
</TargetContent>
</DxDrawer>
When the drawer panel opens, it can overlap or shrink target content. Use the Mode property to specify how the panel interacts with the target content area.
Run Demo: Drawer - Position and Mode
<DxDrawer IsOpen="IsOpen" Mode="DrawerMode.Overlap" PanelWidth="20%">
<BodyTemplate>
<DxMenu Orientation="Orientation.Vertical">
<Items>
<DxMenuItem Text="Home" IconCssClass="menu-icon-home menu-icon" />
<DxMenuItem Text="Components" IconCssClass="menu-icon-products menu-icon" />
<DxMenuItem Text="Support" IconCssClass="menu-icon-support menu-icon" />
<DxMenuItem Text="Contacts" IconCssClass="menu-icon-contacts menu-icon" />
<DxMenuItem Text="About" IconCssClass="menu-icon-about menu-icon" />
</Items>
</DxMenu>
</BodyTemplate>
<TargetContent>
@* Lorem ipsum dolor sit amet, consectetur adipiscing elit ... *@
</TargetContent>
</DxDrawer>
The DxDrawer component allows you to customize its appearance with the following properties:
CssClassAssigns a CSS class to the DxDrawer component.ClosedCssClassAssigns a CSS class to the Drawer component when the panel is closed.MiniCssClassAssigns a CSS class to the Drawer component when the panel is minimized.OpenCssClassAssigns a CSS class to the Drawer component when the panel is open.
In overlap mode, the Drawer component is assigned the dialog role and aria-modal attribute. This informs assistive technologies that the component is separate from the rest of the page, and the content outside the Drawer is inactive while it is open.
To ensure a component is fully accessible, it must be labeled correctly. The label depends on your application’s content and cannot be set automatically. Pass the following ARIA attributes to the Drawer’s Attributes property:
<DxDrawer IsOpen="true"
Mode="DrawerMode.Overlap"
aria-label="Navigation">
<BodyTemplate>
@* ... *@
</BodyTemplate>
<TargetContent>
@* ... *@
</TargetContent>
</DxDrawer>
Object ComponentBase DxComponentBase DxDrawer
See Also