Skip to content

Commit 8f0904f

Browse files
devversionwagnermaciel
authored andcommitted
docs: add example for using ripples within table (#22797)
* docs: add example for using ripples within table (cherry picked from commit d7e2109)
1 parent 7ae3ce4 commit 8f0904f

File tree

6 files changed

+54
-2
lines changed

6 files changed

+54
-2
lines changed

src/components-examples/material/table/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ ng_module(
2121
"//src/material/button",
2222
"//src/material/button-toggle",
2323
"//src/material/checkbox",
24+
"//src/material/core",
2425
"//src/material/icon",
2526
"//src/material/input",
2627
"//src/material/paginator",

src/components-examples/material/table/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {CommonModule} from '@angular/common';
22
import {NgModule} from '@angular/core';
3+
import {MatRippleModule} from '@angular/material/core';
34
import {MatButtonModule} from '@angular/material/button';
45
import {MatButtonToggleModule} from '@angular/material/button-toggle';
56
import {MatCheckboxModule} from '@angular/material/checkbox';
@@ -42,6 +43,7 @@ import {TableWrappedExample, WrapperTable} from './table-wrapped/table-wrapped-e
4243
import {TableReorderableExample} from './table-reorderable/table-reorderable-example';
4344
import {TableRecycleRowsExample} from './table-recycle-rows/table-recycle-rows-example';
4445
import {TableHarnessExample} from './table-harness/table-harness-example';
46+
import {TableWithRipplesExample} from './table-with-ripples/table-with-ripples-example';
4547
import {TableColumnStylingExample} from './table-column-styling/table-column-styling-example';
4648
import {TableRowBindingExample} from './table-row-binding/table-row-binding-example';
4749

@@ -59,7 +61,7 @@ export {
5961
TableWrappedExample, WrapperTable,
6062
TableReorderableExample, TableRecycleRowsExample,
6163
TableHarnessExample, TableColumnStylingExample,
62-
TableRowBindingExample
64+
TableRowBindingExample, TableWithRipplesExample,
6365
};
6466

6567
const EXAMPLES = [
@@ -76,7 +78,7 @@ const EXAMPLES = [
7678
TableWrappedExample, WrapperTable,
7779
TableReorderableExample, TableRecycleRowsExample,
7880
TableHarnessExample, TableColumnStylingExample,
79-
TableRowBindingExample
81+
TableRowBindingExample, TableWithRipplesExample,
8082
];
8183

8284
@NgModule({
@@ -89,6 +91,7 @@ const EXAMPLES = [
8991
MatInputModule,
9092
MatPaginatorModule,
9193
MatProgressSpinnerModule,
94+
MatRippleModule,
9295
MatSortModule,
9396
MatTableModule,
9497
CdkTableModule,

src/components-examples/material/table/table-with-ripples/table-with-ripples-example.css

Whitespace-only changes.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<mat-table [dataSource]="dataSource" class="mat-elevation-z8">
2+
<ng-container matColumnDef="name">
3+
<mat-header-cell mat-header-cell *matHeaderCellDef> Name </mat-header-cell>
4+
<mat-cell mat-cell *matCellDef="let element"> {{element.name}} </mat-cell>
5+
</ng-container>
6+
7+
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
8+
<mat-row matRipple *matRowDef="let row; columns: displayedColumns;"></mat-row>
9+
</mat-table>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import {Component} from '@angular/core';
2+
3+
const ELEMENT_DATA = [
4+
{name: 'Hydrogen'},
5+
{name: 'Helium'},
6+
{name: 'Lithium'},
7+
{name: 'Beryllium'},
8+
{name: 'Boron'},
9+
{name: 'Carbon'},
10+
{name: 'Nitrogen'},
11+
{name: 'Oxygen'},
12+
{name: 'Fluorine'},
13+
{name: 'Neon'},
14+
];
15+
16+
/**
17+
* @title Tables with Material Design ripples.
18+
*/
19+
@Component({
20+
selector: 'table-with-ripples-example',
21+
styleUrls: ['table-with-ripples-example.css'],
22+
templateUrl: 'table-with-ripples-example.html',
23+
})
24+
export class TableWithRipplesExample {
25+
displayedColumns: string[] = ['name'];
26+
dataSource = ELEMENT_DATA;
27+
}

src/material/table/table.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,3 +421,15 @@ selectors. For example, `<table mat-table>` becomes `<mat-table>`; `<tr mat-row>
421421

422422
Note that this approach means you cannot include certain native-table features such colspan/rowspan
423423
or have columns that resize themselves based on their content.
424+
425+
### Tables with `MatRipple`
426+
427+
By default, `MatTable` does not set up Material Design ripples for rows. A ripple effect can be
428+
added to table rows by using the `MatRipple` directive from `@angular/material/core`. Due to
429+
limitations in browsers, ripples cannot be applied native `th` or `tr` elements. The recommended
430+
approach for setting up ripples is using the non-native `display: flex` variant of `MatTable`.
431+
432+
<!--- example(table-with-ripples) -->
433+
434+
More details about ripples on native table rows and their limitations can be found [in this issue](https://github.com/angular/components/issues/11883#issuecomment-634942981).
435+

0 commit comments

Comments
 (0)