SlideMenu displays submenus with slide animation.
import { SlideMenuModule } from 'primeng/slidemenu';
SlideMenu requires a collection of menuitems as its model along with viewportHeight and menuWidth.
<p-slideMenu [model]="items" [viewportHeight]="250" [menuWidth]="175"></p-slideMenu>
Popup mode is enabled by adding popup property and calling toggle method with an event of the target.
<button type="button" pButton icon="pi pi-bars" label="Show" (click)="menu.toggle($event)"></button>
<p-slideMenu #menu [model]="items" [popup]="true" [viewportHeight]="250" [menuWidth]="175"></p-slideMenu>
Following is the list of structural style classes, for theming classes visit theming page.
Name | Element |
---|---|
p-slidemenu | Container element. |
p-slidemenu-wrapper | Wrapper of content. |
p-slidemenu-content | Content element. |
p-slidemenu-backward | Element to navigate to previous menu on click. |
p-menu-list | List element. |
p-menuitem | Menuitem element. |
p-menuitem-text | Label of a menuitem. |
p-menuitem-icon | Icon of a menuitem. |
p-submenu-icon | Arrow icon of a submenu. |
SlideMenu component uses the menubar role with aria-orientation set to "vertical" and the value to describe the menu can either be provided with aria-labelledby or aria-label props. Each list item has a presentation role whereas anchor elements have a menuitem role with aria-label referring to the label of the item and aria-disabled defined if the item is disabled. A submenu within a SlideMenu uses the menu role with an aria-labelledby defined as the id of the submenu root menuitem label. In addition, menuitems that open a submenu have aria-expanded and aria-controls to define the relation between the item and the submenu.
In popup mode, the component implicitly manages the aria-expanded, aria-haspopup and aria-controls attributes of the target element to define the relation between the target and the popup.
Key | Function |
---|---|
tab | Add focus to the first item if focus moves in to the menu. If the focus is already within the menu, focus moves to the next focusable item in the page tab sequence. |
shift + tab | Add focus to the last item if focus moves in to the menu. If the focus is already within the menu, focus moves to the previous focusable item in the page tab sequence. |
enter | If menuitem has a submenu, toggles the visibility of the submenu otherwise activates the menuitem and closes all open overlays. |
space | If menuitem has a submenu, toggles the visibility of the submenu otherwise activates the menuitem and closes all open overlays. |
escape | If focus is inside a popup submenu, closes the submenu and moves focus to the root item of the closed submenu. |
down arrow | Moves focus to the next menuitem within the submenu. |
up arrow | Moves focus to the previous menuitem within the submenu. |
right arrow | Opens a submenu if there is one available and moves focus to the first item. |
left arrow | Closes a submenu and moves focus to the root item of the closed submenu. |
home | Moves focus to the first menuitem within the submenu. |
end | Moves focus to the last menuitem within the submenu. |
API defines helper props, events and others for the PrimeNG Slide Menu module.
Name | Type | Default | Description |
---|---|---|---|
model | array | null | An array of menuitems. |
popup | boolean | false | Defines if menu would displayed as a popup. |
style | string | null | Inline style of the component. |
styleClass | string | null | Style class of the component. |
easing | string | ease-out | Easing animation to use for sliding. |
effectDuration | any | 250 | Duration of the sliding animation in milliseconds. |
backLabel | string | Back | Label of element to navigate back. |
menuWidth | number | 180 | Width of the submenus. |
viewportHeight | number | 175 | Height of the scrollable area, a scrollbar appears if a menu height is longer than this value. |
appendTo | any | null | Target element to attach the overlay, valid values are "body" or a local ng-template variable of another element (note: use binding with brackets for template variables, e.g. [appendTo]="mydiv" for a div element having #mydiv as variable name). |
baseZIndex | number | 0 | Base zIndex value to use in layering. |
autoZIndex | boolean | true | Whether to automatically manage layering. |
showTransitionOptions | string | .12s cubic-bezier(0, 0, 0.2, 1) | Transition options of the show animation. |
hideTransitionOptions | string | .1s linear | Transition options of the hide animation. |
Name | Parameters | Description |
---|---|---|
toggle | event: browser event | Toggles the visibility of the popup menu. |
show | event: browser event | Displays the popup menu. |
hide | - | Hides the popup menu. |
Name | Parameters |
---|---|
submenuicon | - |
backicon | - |
MenuItem provides the following properties. Note that not all of them may be utilized by the slidemenu component.
Name | Type | Default | Description |
---|---|---|---|
id | string | null | Identifier of the element. |
label | string | null | Text of the item. |
icon | string | null | Icon of the item. |
iconStyle | object | null | Inline style of the item's icon. |
command | function | null | Callback to execute when item is clicked. |
url | string | null | External link to navigate when item is clicked. |
routerLink | array | null | RouterLink definition for internal navigation. |
routerLinkActiveOptions | object | null | Configuration for active router link. |
queryParams | object | null | Query parameters for internal navigation via routerLink. |
fragment | string | null | Sets the hash fragment for the URL. |
queryParamsHandling | QueryParamsHandling | null | How to handle query parameters in the router link for the next navigation. One of: merge : Merge new with current parameters. preserve : Preserve current parameters.k. |
preserveFragment | boolean | false | When true, preserves the URL fragment for the next navigation. |
skipLocationChange | boolean | null | When true, navigates without pushing a new state into history. |
replaceUrl | boolean | null | When true, navigates while replacing the current state in history. |
state | object | null | Developer-defined state that can be passed to any navigation. |
items | array | null | An array of children menuitems. |
expanded | boolean | false | Visibility of submenu. |
disabled | boolean | false | When set as true, disables the menuitem. |
visible | boolean | true | Whether the dom element of menuitem is created or not. |
target | string | null | Specifies where to open the linked document. |
escape | boolean | true | Whether to escape the label or not. Set to false to display html content. |
separator | boolean | false | Defines the item as a separator. |
style | object | null | Inline style of the menuitem. |
styleClass | string | null | Style class of the menuitem. |
badge | string | null | Value of the badge. |
badgeStyleClass | string | null | Style class of the badge. |
title | string | null | Tooltip text of the item. |
automationId | any | null | Value of HTML data-* attribute. |
tabindex | string | 0 | Specifies tab order of the item. |
tooltipOptions | TooltipOptions | - | Options of the item's tooltip. |