Nav Drawer
Put your app's navigation in a panel that slides in from the side of the screen, opened from a menu button.
Installation
This also adds Icon, which draws the menu button's icon.
Usage
<ui-nav-drawer-trigger>is a menu button with a hamburger icon. It only emitspressed, so set youropensignal there. Screen readers announce it as "Open navigation menu", or your ownlabel.- The drawer covers 80% of the screen width and the full height, over a dimmed backdrop. A backdrop tap or Android's back button closes it.
- Tapping an item emits its
pressed, then closes the drawer. [active]highlights the item for the current page. When the drawer opens, it scrolls the active item into view.- An item lays out its content in a row. Put an icon and a
<text>in it. - The drawer draws in an
<overlay>, so it covers the whole screen wherever it sits in your template. - When it opens, a screen reader moves into the drawer and stays inside it until it closes.
Layout
The drawer stacks up to three sections, each optional:
<ui-nav-drawer-header>at the top, padded clear of the status bar and notch.<ui-nav-drawer-content>in the middle. It fills the space left over and scrolls when the items don't fit.<ui-nav-drawer-footer>at the bottom, padded clear of the home indicator. Use it for account actions such as Log out.
Navigate with the router
Make each item a routerLink, and let routerLinkActive say which one is active. Import RouterLink and RouterLinkActive from @angular/router:
A tap on the item navigates, and closes the drawer as any item does. routerLinkActive with no classes only tracks the route, for [active], and marks the item selected for screen readers. See Routing and navigation.
A destructive item
variant="destructive" draws an item's content in the theme's destructive color, for an action such as Log out:
- Text styled
text-foregroundturns destructive. Lynx doesn't passcolordown to children, so the item points the--foregroundvariable at--destructiveinstead, and variables do pass down. Text with another color class keeps it. - Icons without a
colorturn destructive. An icon's owncolorwins.
Open from the right
Keep the drawer open
Set autoClose to false on an item that shouldn't close the drawer, such as one that expands a group.
API
UiNavDrawer
UiNavDrawerItem
UiNavDrawerTrigger
All sub-components (UiNavDrawerHeader, UiNavDrawerContent, UiNavDrawerItem, UiNavDrawerFooter, UiNavDrawerTrigger) accept class. Items only work inside a <ui-nav-drawer>, because they close it.
Related
- Routing and navigation: move between pages with the router
- Dialogs and overlays: how overlays work and which one to use
- Safe area: the insets the header and footer pad for
- Tab Bar: bottom tabs, for an app with a handful of top-level screens
- Icon: icons for the items
