Skip to content

Commit d80c596

Browse files
committed
reduce the number of ng-template's needed in list-item and list-option
1 parent 362dc9f commit d80c596

File tree

4 files changed

+30
-15
lines changed

4 files changed

+30
-15
lines changed
Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
1-
<ng-content select="[mat-list-avatar],[matListAvatar],[mat-list-icon],[matListIcon]"></ng-content>
2-
3-
<!-- If lines were explicitly given, use those as the text. -->
4-
<ng-container *ngIf="lines.length">
5-
<span class="mdc-list-item__text"><ng-content select="[mat-line],[matLine]"></ng-content></span>
6-
</ng-container>
7-
8-
<!--
9-
If lines were not explicitly given, assume the remaining content is the text, otherwise assume it
10-
is an action that belongs in the "meta" section.
11-
-->
12-
<span [class.mdc-list-item__text]="!lines.length" [class.mdc-list-item__meta]="!!lines.length">
1+
<!-- Save icons and unclassified content to be places later -->
2+
<ng-template #icons>
3+
<ng-content select="[mat-list-avatar],[matListAvatar],[mat-list-icon],[matListIcon]"></ng-content>
4+
</ng-template>
5+
<ng-template #unsortedContent>
136
<ng-content></ng-content>
14-
</span>
7+
</ng-template>
158

9+
<!-- Prefix -->
10+
<span class="mdc-list-item__graphic" *ngIf="checkboxPosition !== 'after' else icons">
11+
<mat-pseudo-checkbox></mat-pseudo-checkbox>
12+
</span>
13+
<!-- Text -->
14+
<span class="mdc-list-item__text">
15+
<ng-content *ngIf="lines.length else unsortedContent" select="[mat-line],[matLine]"></ng-content>
16+
</span>
17+
<!-- Suffix -->
18+
<span class="mdc-list-item__meta">
19+
<span class="mdc-list-item__graphic" *ngIf="checkboxPosition === 'after' else icons">
20+
<mat-pseudo-checkbox></mat-pseudo-checkbox>
21+
</span>
22+
<ng-container *ngIf="lines.length" [ngTemplateOutlet]="unsortedContent"></ng-container>
23+
</span>
24+
<!-- Divider -->
1625
<ng-content select="mat-divider"></ng-content>

src/material-experimental/mdc-list/list.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,8 @@
108108
right: 0;
109109
opacity: 0;
110110
}
111+
112+
.mat-mdc-list-option .mdc-list-item__meta .mdc-list-item__graphic {
113+
margin-right: 0;
114+
vertical-align: middle;
115+
}

src/material-experimental/mdc-list/module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import {CommonModule} from '@angular/common';
1010
import {NgModule} from '@angular/core';
11-
import {MatLineModule, MatRippleModule} from '@angular/material/core';
11+
import {MatLineModule, MatPseudoCheckboxModule, MatRippleModule} from '@angular/material/core';
1212
import {MatDividerModule} from '@angular/material/divider';
1313
import {MatActionList} from './action-list';
1414
import {
@@ -26,6 +26,7 @@ import {MatListOption, MatSelectionList} from './selection-list';
2626
CommonModule,
2727
MatLineModule,
2828
MatRippleModule,
29+
MatPseudoCheckboxModule,
2930
],
3031
exports: [
3132
MatList,

src/material-experimental/mdc-list/selection-list.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export class MatListOption extends MatListItemBase {
106106

107107
// TODO: Implement these inputs.
108108
@Input() disableRipple: boolean;
109-
@Input() checkboxPosition: 'before' | 'after';
109+
@Input() checkboxPosition: 'before' | 'after' = 'before';
110110
@Input() color: ThemePalette;
111111
@Input() value: any;
112112
@Input() disabled: boolean;

0 commit comments

Comments
 (0)