Skip to content

Commit 008ee07

Browse files
crisbetommalerba
authored andcommitted
docs: add overview docs for bottom sheet (#9809)
Adds the initial readme and overview example for the bottom sheet component.
1 parent 669d607 commit 008ee07

File tree

6 files changed

+157
-1
lines changed

6 files changed

+157
-1
lines changed

src/demo-app/bottom-sheet/bottom-sheet-demo.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ export class BottomSheetDemo {
4949
template: `
5050
<mat-nav-list>
5151
<a href="#" mat-list-item (click)="handleClick($event)" *ngFor="let action of [1, 2, 3]">
52-
<mat-icon mat-list-icon>folder</mat-icon>
5352
<span mat-line>Action {{ link }}</span>
5453
<span mat-line>Description</span>
5554
</a>

src/lib/bottom-sheet/bottom-sheet.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
The `MatBottomSheet` service can be used to open Material Design panels to the bottom of the screen.
2+
These panels are intended primarily as an interaction on mobile devices where they can be used as an
3+
alternative to dialogs and menus.
4+
5+
<!-- example(bottom-sheet-overview) -->
6+
7+
You can open a bottom sheet by calling the `open` method with a component to be loaded and an
8+
optional config object. The `open` method will return an instance of `MatBottomSheetRef`:
9+
10+
```ts
11+
const bottomSheetRef = bottomSheet.open(SocialShareComponent, {
12+
ariaLabel: 'Share on social media'
13+
});
14+
```
15+
16+
The `MatBottomSheetRef` is a reference to the currently-opened bottom sheet and can be used to close
17+
it or to subscribe to events. Note that only one bottom sheet can be open at a time. Any component
18+
contained inside of a bottom sheet can inject the `MatBottomSheetRef` as well.
19+
20+
```ts
21+
bottomSheetRef.afterDismissed().subscribe(() => {
22+
console.log('Bottom sheet has been dismissed.');
23+
});
24+
25+
bottomSheetRef.dismiss();
26+
```
27+
28+
### Sharing data with the bottom sheet component.
29+
If you want to pass in some data to the bottom sheet, you can do so using the `data` property:
30+
31+
```ts
32+
const bottomSheetRef = bottomSheet.open(HobbitSheet, {
33+
data: { names: ['Frodo', 'Bilbo'] },
34+
});
35+
```
36+
37+
Afterwards you can access the injected data using the `MAT_BOTTOM_SHEET_DATA` injection token:
38+
39+
```ts
40+
import {Component, Inject} from '@angular/core';
41+
import {MAT_BOTTOM_SHEET_DATA} from '@angular/material';
42+
43+
@Component({
44+
selector: 'hobbit-sheet',
45+
template: 'passed in {{ data.names }}',
46+
})
47+
export class HobbitSheet {
48+
constructor(@Inject(MAT_BOTTOM_SHEET_DATA) public data: any) { }
49+
}
50+
```
51+
52+
### Configuring bottom sheet content via `entryComponents`
53+
54+
Similarly to `MatDialog`, `MatBottomSheet` instantiates components at run-time. In order for it to
55+
work, the Angular compiler needs extra information to create the necessary `ComponentFactory` for
56+
your bottom sheet content component.
57+
58+
Any components that are include inside of a bottom sheet have to be added to the `entryComponents`
59+
inside your `NgModule`.
60+
61+
62+
```ts
63+
@NgModule({
64+
imports: [
65+
// ...
66+
MatBottomSheetModule
67+
],
68+
69+
declarations: [
70+
AppComponent,
71+
ExampleBottomSheetComponent
72+
],
73+
74+
entryComponents: [
75+
ExampleBottomSheetComponent
76+
],
77+
78+
providers: [],
79+
bootstrap: [AppComponent]
80+
})
81+
export class AppModule {}
82+
```
83+
84+
### Accessibility
85+
By default, the bottom sheet has `role="dialog"` on the root element and can be labelled using the
86+
`ariaLabel` property on the `MatBottomSheetConfig`.
87+
88+
When a bottom sheet is opened, it will move focus to the first focusable element that it can find.
89+
In order to prevent users from tabbing into elements in the background, the Material bottom sheet
90+
uses a [focus trap](https://material.angular.io/cdk/a11y/overview#focustrap) to contain focus
91+
within itself. Once a bottom sheet is closed, it will return focus to the element that was focused
92+
before it was opened.
93+
94+
#### Focus management
95+
By default, the first tabbable element within the bottom sheet will receive focus upon open.
96+
This can be configured by setting the `cdkFocusInitial` attribute on another focusable element.
97+
98+
#### Keyboard interaction
99+
By default pressing the escape key will close the bottom sheet. While this behavior can
100+
be turned off via the `disableClose` option, users should generally avoid doing so
101+
as it breaks the expected interaction pattern for screen-reader users.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<mat-nav-list>
2+
<a href="https://keep.google.com/" mat-list-item (click)="openLink($event)">
3+
<span mat-line>Google Keep</span>
4+
<span mat-line>Add to a note</span>
5+
</a>
6+
7+
<a href="https://docs.google.com/" mat-list-item (click)="openLink($event)">
8+
<span mat-line>Google Docs</span>
9+
<span mat-line>Embed in a document</span>
10+
</a>
11+
12+
<a href="https://plus.google.com/" mat-list-item (click)="openLink($event)">
13+
<span mat-line>Google Plus</span>
14+
<span mat-line>Share with your friends</span>
15+
</a>
16+
17+
<a href="https://hangouts.google.com/" mat-list-item (click)="openLink($event)">
18+
<span mat-line>Google Hangouts</span>
19+
<span mat-line>Show to your coworkers</span>
20+
</a>
21+
</mat-nav-list>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/** No CSS for this example */
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<p>You have receive a file called "cat-picture.jpeg".</p>
2+
3+
<button mat-raised-button (click)="openBottomSheet()">Open file</button>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import {Component} from '@angular/core';
2+
import {MatBottomSheet, MatBottomSheetRef} from '@angular/material';
3+
4+
/**
5+
* @title Bottom Sheet Overview
6+
*/
7+
@Component({
8+
selector: 'bottom-sheet-overview-example',
9+
templateUrl: 'bottom-sheet-overview-example.html',
10+
styleUrls: ['bottom-sheet-overview-example.css'],
11+
})
12+
export class BottomSheetOverviewExample {
13+
constructor(private bottomSheet: MatBottomSheet) {}
14+
15+
openBottomSheet(): void {
16+
this.bottomSheet.open(BottomSheetOverviewExampleSheet);
17+
}
18+
}
19+
20+
@Component({
21+
selector: 'bottom-sheet-overview-example-sheet',
22+
templateUrl: 'bottom-sheet-overview-example-sheet.html',
23+
})
24+
export class BottomSheetOverviewExampleSheet {
25+
constructor(private bottomSheetRef: MatBottomSheetRef<BottomSheetOverviewExampleSheet>) {}
26+
27+
onNoClick(event: MouseEvent): void {
28+
this.bottomSheetRef.dismiss();
29+
event.preventDefault();
30+
}
31+
}

0 commit comments

Comments
 (0)