From 43f6f4138acd1c137ca16e00e182559f66be1100 Mon Sep 17 00:00:00 2001 From: Miles Malerba Date: Thu, 12 Oct 2017 15:40:45 -0700 Subject: [PATCH] rewrite sidenav docs --- src/lib/sidenav/README.md | 4 + src/lib/sidenav/sidenav.md | 192 ++++++++++++++++++++++++++----------- 2 files changed, 139 insertions(+), 57 deletions(-) diff --git a/src/lib/sidenav/README.md b/src/lib/sidenav/README.md index 0601c9e29ef3..0acf7332acc8 100644 --- a/src/lib/sidenav/README.md +++ b/src/lib/sidenav/README.md @@ -44,6 +44,10 @@ The sidenav panel. | `close(): Promise` | Close the sidenav. Equivalent to `opened = false`. Returns a promise that will resolve when the animation completes, or be rejected if the animation was cancelled. | | `toggle(): Promise` | Toggle the sidenav. This is equivalent to `opened = !opened`. Returns a promise that will resolve when the animation completes, or be rejected if the animation was cancelled. | + + + + ### Notes The `` will resize based on its content. You can also set its width in CSS, like so: diff --git a/src/lib/sidenav/sidenav.md b/src/lib/sidenav/sidenav.md index 7260c637fd71..84a64ce24f86 100644 --- a/src/lib/sidenav/sidenav.md +++ b/src/lib/sidenav/sidenav.md @@ -1,44 +1,131 @@ -`` is a panel that can be placed next to or above some primary content. A sidenav is -typically used for navigation, but can contain any content. +Angular Material provides two sets of components designed to add collapsible side content (often +navigation, though it can be any content) alongside some primary content. These are the sidenav and +drawer components. - +The sidenav components are designed to add side content to a fullscreen app. To set up a sidenav we +use three components: `` which acts as a structural container for our content +and sidenav, `` which represents the main content, and `` which +represents the added side content. + + + +There are also drawer components, ``, ``, and +``, which are analogous to their sidenav equivalents. Rather than adding side content +to the app as a whole, these are designed to add side content to a small section of your app. They +support almost all of the same features, but do not support fixed positioning. + + + +### Specifying the main and side content + +Both the main and side content should be placed inside of the ``, content +that you don't want to be affected by the sidenav, such as a header or footer, can be placed outside +of the container. + +The side content should be wrapped in a `` element. The `position` property can be used +to specify which end of the main content to place the side content on. `position` can be either +`start` or `end` which places the side content on the left or right respectively in left-to-right +languages. If the `position` is not set, the `start` end will be assumed. A +`` can have up to two `` elements total, but only one for any +given side. + +The main content should be wrapped in a ``. If no `` is +specified for a ``, one will be created implicitly and all of the content +inside the `` other than the `` elements will be placed inside +of it. + +The following are examples of valid sidenav layouts: -The sidenav and its associated content live inside of an ``: ```html - - - + Start + Main + +``` - +```html + + Start + End +
Main
``` -A sidenav container may contain one or two `` elements. When there are two -`` elements, each must be placed on a different side of the container. -See the section on positioning below. +```html + +``` -### Sidenav mode -The sidenav can render in one of three different ways based on the `mode` property. +Anf these are examples of invalid sidenav layouts: + +```html + + Start + Start 2 + +``` + +```html + + Main + Main 2 + +``` + +```html + + +``` -| Mode | Description | -|------|-------------------------------------------------------------------------------------------| -| over | Sidenav floats _over_ the primary content, which is covered by a backdrop | -| push | Sidenav _pushes_ the primary content out of its way, also covering it with a backdrop | -| side | Sidenav appears _side-by-side_ with the primary content | +These same rules all apply to the drawer components as well. -Using the `side` mode on mobile devices can affect the performance and is also not recommended by the -[Material Design specification](https://material.io/guidelines/patterns/navigation-drawer.html#navigation-drawer-behavior). +### Opening and closing a sidenav -### Positioning the sidenav -The `position` property determines whether the sidenav appears at the `"start"` or `"end"` of the -container. This is affected by the current text direction ("ltr" or "rtl"). By default, the sidenav -appears at the start of the container. +A `` can be opened or closed using the `open()`, `close()` and `toggle()` methods. Each +of these methods returns a `Promise` that will be resolved with `true` when the sidenav +finishes opening or `false` when it finishes closing. +The opened state can also be set via a property binding in the template using the `opened` property. +The property supports 2-way binding. -### Sizing the sidenav -The `` will, by default, fit the size of its content. The width can be explicitly set -via CSS: +`` also supports output properties for just open and just close events, The `(opened)` +and `(closed)` properties respectively. + + + +All of these properties and methods work on `` as well. + +### Changing the sidenav's behavior + +The `` can render in one of three different ways based on the `mode` property. + +| Mode | Description | +|--------|-----------------------------------------------------------------------------------------| +| `over` | Sidenav floats _over_ the primary content, which is covered by a backdrop | +| `push` | Sidenav _pushes_ the primary content out of its way, also covering it with a backdrop | +| `side` | Sidenav appears _side-by-side_ with the main content, shrinking the main content's width to make space for the sidenav. | + +If no `mode` is specified, `over` is used by default. + + + +`` also supports all of these same modes. + +### Disabling automatic close + +Clicking on the backdrop or pressing the Esc key will normally close an open sidenav. +However, this automatic closing behavior can be disabled by setting the `disableClose` property on +the `` or `` that you want to disable the behavior for. + +Custom handling for Esc can be done by adding a keydown listener to the ``. +Custom handling for backdrop clicks can be done via the `(backdropClick)` output property on +``. + + + +### Setting the sidenav's size + +The `` and `` will, by default, fit the size of its content. The width can +be explicitly set via CSS: ```css mat-sidenav { @@ -48,37 +135,28 @@ mat-sidenav { Try to avoid percent based width as `resize` events are not (yet) supported. -For a fullscreen sidenav, the recommended approach is set up the DOM such that the -`` can naturally take up the full space: +### Fixed position sidenavs -```html - - - Drawer content -
Main content
-
-
-``` -```css -html, body, material-app, mat-sidenav-container, .my-content { - margin: 0; - width: 100%; - height: 100%; -} -``` +For `` only (not ``) fixed positioning is supported. It can be enabled by +setting the `fixedInViewport` property. Additionally, top and bottom space can be set via the +`fixedTopGap` and `fixedBottomGap`. These properties accept a pixel value amount of space to add at +the top or bottom. -### FABs inside sidenav -For a sidenav with a FAB (Floating Action Button) or other floating element, the recommended approach is to place the FAB -outside of the scrollable region and absolutely position it. + +### Common layout patterns -### Disabling closing of sidenav -By default, sidenav can be closed either by clicking on the backdrop or by pressing ESCAPE. -The `disableClose` attribute can be set on `mat-sidenav` to disable automatic closing when the backdrop -is clicked or ESCAPE is pressed. To add custom logic on backdrop click, add a `(backdropClick)` listener to -`mat-sidenav-container`. For custom ESCAPE logic, a standard `(keydown)` listener will suffice. -```html - - - -``` \ No newline at end of file + + +#### Full-height sidenav +#### Sidenav under toolbar +#### Mobile sidenav +#### Responsive sidenav + +### Accessibility + + + +### Troubleshooting + +