Skip to content

Commit

Permalink
fix(material/list): validation using wrong variable (#27638)
Browse files Browse the repository at this point in the history
Fixes that the list was using the wrong variable to verify that it has the correct number of lines.

Fixes #27582.

(cherry picked from commit 76e3172)
  • Loading branch information
crisbeto committed Nov 9, 2023
1 parent 1ac0afa commit fe339ee
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import {
} from '@angular/material-moment-adapter';
import {DateAdapter, MAT_DATE_FORMATS, MAT_DATE_LOCALE} from '@angular/material/core';
import {MatButtonModule} from '@angular/material/button';
import {MatDatepickerModule} from '@angular/material/datepicker';
import {MatDatepickerModule, MatDatepickerIntl} from '@angular/material/datepicker';
import {MatInputModule} from '@angular/material/input';
import {MatFormFieldModule} from '@angular/material/form-field';
import 'moment/locale/ja';
import 'moment/locale/fr';
import {MatDatepickerIntl} from '@angular/material/datepicker';

/** @title Datepicker with different locale */
@Component({
Expand Down
10 changes: 5 additions & 5 deletions src/material/list/list-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,23 +326,23 @@ export abstract class MatListItemBase implements AfterViewInit, OnDestroy, Rippl
*/
function sanityCheckListItemContent(item: MatListItemBase) {
const numTitles = item._titles!.length;
const numLines = item._titles!.length;
const numLines = item._lines!.length;

if (numTitles > 1) {
throw Error('A list item cannot have multiple titles.');
console.warn('A list item cannot have multiple titles.');
}
if (numTitles === 0 && numLines > 0) {
throw Error('A list item line can only be used if there is a list item title.');
console.warn('A list item line can only be used if there is a list item title.');
}
if (
numTitles === 0 &&
item._hasUnscopedTextContent &&
item._explicitLines !== null &&
item._explicitLines > 1
) {
throw Error('A list item cannot have wrapping content without a title.');
console.warn('A list item cannot have wrapping content without a title.');
}
if (numLines > 2 || (numLines === 2 && item._hasUnscopedTextContent)) {
throw Error('A list item can have at maximum three lines.');
console.warn('A list item can have at maximum three lines.');
}
}
18 changes: 1 addition & 17 deletions src/material/list/list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ describe('MDC-based MatList', () => {
ListWithItemWithCssClass,
ListWithDynamicNumberOfLines,
ListWithMultipleItems,
ListWithManyLines,
NavListWithOneAnchorItem,
NavListWithActivatedItem,
ActionListWithoutType,
Expand Down Expand Up @@ -69,7 +68,7 @@ describe('MDC-based MatList', () => {
});

it('should have a strong focus indicator configured for all list-items', () => {
const fixture = TestBed.createComponent(ListWithManyLines);
const fixture = TestBed.createComponent(ListWithThreeLineItem);
fixture.detectChanges();
const listItems = fixture.debugElement.children[0]
.queryAll(By.css('mat-list-item'))
Expand Down Expand Up @@ -555,21 +554,6 @@ class ListWithTwoLineItem extends BaseTestList {}
})
class ListWithThreeLineItem extends BaseTestList {}

@Component({
template: `
<mat-list>
@for (item of items; track item) {
<mat-list-item>
<h3 matListItemTitle>Line 1</h3>
<p matListItemLine>Line 2</p>
<p matListItemLine>Line 3</p>
<p matListItemLine>Line 4</p>
</mat-list-item>
}
</mat-list>`,
})
class ListWithManyLines extends BaseTestList {}

@Component({
template: `
<mat-list>
Expand Down

0 comments on commit fe339ee

Please sign in to comment.