1
- ` <mat-sidenav> ` is a panel that can be placed next to or above some primary content. A sidenav is
2
- typically used for navigation, but can contain any content.
1
+ Angular Material provides two sets of components designed to add collapsible side content (often
2
+ navigation, though it can be any content) alongside some primary content. These are the sidenav and
3
+ drawer components.
3
4
4
- <!-- example(sidenav-overview) -->
5
+ The sidenav components are designed to add side content to a fullscreen app. To set up a sidenav we
6
+ use three components: ` <mat-sidenav-container> ` which acts as a structural container for our content
7
+ and sidenav, ` <mat-sidenav-content> ` which represents the main content, and ` <mat-sidenav> ` which
8
+ represents the added side content.
9
+
10
+ <!-- TODO(mmalerba): sidenav example -->
11
+
12
+ There are also drawer components, ` <mat-drawer-container> ` , ` <mat-drawer-content> ` , and
13
+ ` <mat-drawer> ` , which are analogous to their sidenav equivalents. Rather than adding side content
14
+ to the app as a whole, these are designed to add side content to a small section of your app. They
15
+ support almost all of the same features, but do not support fixed positioning.
16
+
17
+ <!-- TODO(mmalerba): drawer example -->
18
+
19
+ ### Specifying the main and side content
20
+
21
+ Both the main and side content should be placed inside of the ` <mat-sidenav-container> ` , content
22
+ that you don't want to be affected by the sidenav, such as a header or footer, can be placed outside
23
+ of the container.
24
+
25
+ The side content should be wrapped in a ` <mat-sidenav> ` element. The ` position ` property can be used
26
+ to specify which end of the main content to place the side content on. ` position ` can be either
27
+ ` start ` or ` end ` which places the side content on the left or right respectively in left-to-right
28
+ languages. If the ` position ` is not set, the ` start ` end will be assumed. A
29
+ ` <mat-sidenav-container> ` can have up to two ` <mat-sidenav> ` elements total, but only one for any
30
+ given side.
31
+
32
+ The main content should be wrapped in a ` <mat-sidenav-content> ` . If no ` <mat-sidenav-content> ` is
33
+ specified for a ` <mat-sidenav-container> ` , one will be created implicitly and all of the content
34
+ inside the ` <mat-sidenav-container> ` other than the ` <mat-sidenav> ` elements will be placed inside
35
+ of it.
36
+
37
+ The following are examples of valid sidenav layouts:
5
38
6
- The sidenav and its associated content live inside of an ` <mat-sidenav-container> ` :
7
39
``` html
8
40
<mat-sidenav-container >
9
- <mat-sidenav >
10
- <!-- sidenav content -->
11
- </mat-sidenav >
41
+ <mat-sidenav >Start</mat-sidenav >
42
+ <mat-sidenav-content >Main</mat-sidenav-content >
43
+ </mat-sidenav-container >
44
+ ```
12
45
13
- <!-- primary content -->
46
+ ``` html
47
+ <mat-sidenav-container >
48
+ <mat-sidenav >Start</mat-sidenav >
49
+ <mat-sidenav position =" end" >End</mat-sidenav >
50
+ <section >Main</section >
14
51
</mat-sidenav-container >
15
52
```
16
53
17
- A sidenav container may contain one or two ` <mat-sidenav> ` elements. When there are two
18
- ` <mat-sidenav> ` elements, each must be placed on a different side of the container.
19
- See the section on positioning below.
54
+ ``` html
55
+ <mat-sidenav-container ></ mat-sidenav- container>
56
+ ```
20
57
21
- ### Sidenav mode
22
- The sidenav can render in one of three different ways based on the ` mode ` property.
58
+ Anf these are examples of invalid sidenav layouts:
59
+
60
+ ``` html
61
+ <mat-sidenav-container >
62
+ <mat-sidenav >Start</mat-sidenav >
63
+ <mat-sidenav position =" start" >Start 2</mat-sidenav >
64
+ </mat-sidenav-container >
65
+ ```
66
+
67
+ ``` html
68
+ <mat-sidenav-container >
69
+ <mat-sidenav-content >Main</mat-sidenav-content >
70
+ <mat-sidenav-content >Main 2</mat-sidenav-content >
71
+ </mat-sidenav-container >
72
+ ```
73
+
74
+ ``` html
75
+ <mat-sidenav-container ></mat-sidenav-container >
76
+ <mat-sidenav ></mat-sidenav >
77
+ ```
23
78
24
- | Mode | Description |
25
- | ------| -------------------------------------------------------------------------------------------|
26
- | over | Sidenav floats _ over_ the primary content, which is covered by a backdrop |
27
- | push | Sidenav _ pushes_ the primary content out of its way, also covering it with a backdrop |
28
- | side | Sidenav appears _ side-by-side_ with the primary content |
79
+ These same rules all apply to the drawer components as well.
29
80
30
- Using the ` side ` mode on mobile devices can affect the performance and is also not recommended by the
31
- [ Material Design specification] ( https://material.io/guidelines/patterns/navigation-drawer.html#navigation-drawer-behavior ) .
81
+ ### Opening and closing a sidenav
32
82
33
- ### Positioning the sidenav
34
- The ` position ` property determines whether the sidenav appears at the ` "start" ` or ` "end" ` of the
35
- container. This is affected by the current text direction ("ltr" or "rtl"). By default, the sidenav
36
- appears at the start of the container.
83
+ A ` <mat-sidenav> ` can be opened or closed using the ` open() ` , ` close() ` and ` toggle() ` methods. Each
84
+ of these methods returns a ` Promise<boolean> ` that will be resolved with ` true ` when the sidenav
85
+ finishes opening or ` false ` when it finishes closing.
37
86
87
+ The opened state can also be set via a property binding in the template using the ` opened ` property.
88
+ The property supports 2-way binding.
38
89
39
- ### Sizing the sidenav
40
- The ` <mat-sidenav> ` will, by default, fit the size of its content. The width can be explicitly set
41
- via CSS:
90
+ ` <mat-sidenav> ` also supports output properties for just open and just close events, The ` (opened) `
91
+ and ` (closed) ` properties respectively.
92
+
93
+ <!-- TODO(mmalerba): open/close example -->
94
+
95
+ All of these properties and methods work on ` <mat-drawer> ` as well.
96
+
97
+ ### Changing the sidenav's behavior
98
+
99
+ The ` <mat-sidenav> ` can render in one of three different ways based on the ` mode ` property.
100
+
101
+ | Mode | Description |
102
+ | --------| -----------------------------------------------------------------------------------------|
103
+ | ` over ` | Sidenav floats _ over_ the primary content, which is covered by a backdrop |
104
+ | ` push ` | Sidenav _ pushes_ the primary content out of its way, also covering it with a backdrop |
105
+ | ` side ` | Sidenav appears _ side-by-side_ with the main content, shrinking the main content's width to make space for the sidenav. |
106
+
107
+ If no ` mode ` is specified, ` over ` is used by default.
108
+
109
+ <!-- TODO(mmalerba): modes example -->
110
+
111
+ ` <mat-drawer> ` also supports all of these same modes.
112
+
113
+ ### Disabling automatic close
114
+
115
+ Clicking on the backdrop or pressing the <kbd >Esc</kbd > key will normally close an open sidenav.
116
+ However, this automatic closing behavior can be disabled by setting the ` disableClose ` property on
117
+ the ` <mat-sidenav> ` or ` <mat-drawer> ` that you want to disable the behavior for.
118
+
119
+ Custom handling for <kbd >Esc</kbd > can be done by adding a keydown listener to the ` <mat-sidenav> ` .
120
+ Custom handling for backdrop clicks can be done via the ` (backdropClick) ` output property on
121
+ ` <mat-sidenav-container> ` .
122
+
123
+ <!-- TODO(mmalerba): autoclose example -->
124
+
125
+ ### Setting the sidenav's size
126
+
127
+ The ` <mat-sidenav> ` and ` <mat-drawer> ` will, by default, fit the size of its content. The width can
128
+ be explicitly set via CSS:
42
129
43
130
``` css
44
131
mat-sidenav {
@@ -48,37 +135,28 @@ mat-sidenav {
48
135
49
136
Try to avoid percent based width as ` resize ` events are not (yet) supported.
50
137
51
- For a fullscreen sidenav, the recommended approach is set up the DOM such that the
52
- ` <mat-sidenav-container> ` can naturally take up the full space:
138
+ ### Fixed position sidenavs
53
139
54
- ``` html
55
- <app >
56
- <mat-sidenav-container >
57
- <mat-sidenav mode =" side" opened =" true" >Drawer content</mat-sidenav >
58
- <div class =" my-content" >Main content</div >
59
- </mat-sidenav-container >
60
- </app >
61
- ```
62
- ``` css
63
- html , body , material-app , mat-sidenav-container , .my-content {
64
- margin : 0 ;
65
- width : 100% ;
66
- height : 100% ;
67
- }
68
- ```
140
+ For ` <mat-sidenav> ` only (not ` <mat-drawer> ` ) fixed positioning is supported. It can be enabled by
141
+ setting the ` fixedInViewport ` property. Additionally, top and bottom space can be set via the
142
+ ` fixedTopGap ` and ` fixedBottomGap ` . These properties accept a pixel value amount of space to add at
143
+ the top or bottom.
69
144
70
- ### FABs inside sidenav
71
- For a sidenav with a FAB (Floating Action Button) or other floating element, the recommended approach is to place the FAB
72
- outside of the scrollable region and absolutely position it.
145
+ <!-- TODO(mmalerba): fixed example -->
73
146
147
+ ### Common layout patterns
74
148
75
- ### Disabling closing of sidenav
76
- By default, sidenav can be closed either by clicking on the backdrop or by pressing <kbd >ESCAPE</kbd >.
77
- The ` disableClose ` attribute can be set on ` mat-sidenav ` to disable automatic closing when the backdrop
78
- is clicked or <kbd >ESCAPE</kbd > is pressed. To add custom logic on backdrop click, add a ` (backdropClick) ` listener to
79
- ` mat-sidenav-container ` . For custom <kbd >ESCAPE</kbd > logic, a standard ` (keydown) ` listener will suffice.
80
- ``` html
81
- <mat-sidenav-container (backdropClick) =" customBackdropClickHandler()" >
82
- <mat-sidenav disableClose (keydown) =" customKeydownHandler($event)" ></mat-sidenav >
83
- </mat-sidenav-container >
84
- ```
149
+ <!-- TODO(mmalerba): fill out -->
150
+
151
+ #### Full-height sidenav
152
+ #### Sidenav under toolbar
153
+ #### Mobile sidenav
154
+ #### Responsive sidenav
155
+
156
+ ### Accessibility
157
+
158
+ <!-- TODO(mmalerba): fill out -->
159
+
160
+ ### Troubleshooting
161
+
162
+ <!-- TODO(mmalerba): fill out -->
0 commit comments