Skip to content

Commit 76e3172

Browse files
authored
fix(material/list): validation using wrong variable (#27638)
Fixes that the list was using the wrong variable to verify that it has the correct number of lines. Fixes #27582.
1 parent 4229519 commit 76e3172

File tree

3 files changed

+7
-24
lines changed

3 files changed

+7
-24
lines changed

src/components-examples/material/datepicker/datepicker-locale/datepicker-locale-example.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@ import {
66
} from '@angular/material-moment-adapter';
77
import {DateAdapter, MAT_DATE_FORMATS, MAT_DATE_LOCALE} from '@angular/material/core';
88
import {MatButtonModule} from '@angular/material/button';
9-
import {MatDatepickerModule} from '@angular/material/datepicker';
9+
import {MatDatepickerModule, MatDatepickerIntl} from '@angular/material/datepicker';
1010
import {MatInputModule} from '@angular/material/input';
1111
import {MatFormFieldModule} from '@angular/material/form-field';
1212
import 'moment/locale/ja';
1313
import 'moment/locale/fr';
14-
import {MatDatepickerIntl} from '@angular/material/datepicker';
1514

1615
/** @title Datepicker with different locale */
1716
@Component({

src/material/list/list-base.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -326,23 +326,23 @@ export abstract class MatListItemBase implements AfterViewInit, OnDestroy, Rippl
326326
*/
327327
function sanityCheckListItemContent(item: MatListItemBase) {
328328
const numTitles = item._titles!.length;
329-
const numLines = item._titles!.length;
329+
const numLines = item._lines!.length;
330330

331331
if (numTitles > 1) {
332-
throw Error('A list item cannot have multiple titles.');
332+
console.warn('A list item cannot have multiple titles.');
333333
}
334334
if (numTitles === 0 && numLines > 0) {
335-
throw Error('A list item line can only be used if there is a list item title.');
335+
console.warn('A list item line can only be used if there is a list item title.');
336336
}
337337
if (
338338
numTitles === 0 &&
339339
item._hasUnscopedTextContent &&
340340
item._explicitLines !== null &&
341341
item._explicitLines > 1
342342
) {
343-
throw Error('A list item cannot have wrapping content without a title.');
343+
console.warn('A list item cannot have wrapping content without a title.');
344344
}
345345
if (numLines > 2 || (numLines === 2 && item._hasUnscopedTextContent)) {
346-
throw Error('A list item can have at maximum three lines.');
346+
console.warn('A list item can have at maximum three lines.');
347347
}
348348
}

src/material/list/list.spec.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ describe('MDC-based MatList', () => {
1717
ListWithItemWithCssClass,
1818
ListWithDynamicNumberOfLines,
1919
ListWithMultipleItems,
20-
ListWithManyLines,
2120
NavListWithOneAnchorItem,
2221
NavListWithActivatedItem,
2322
ActionListWithoutType,
@@ -69,7 +68,7 @@ describe('MDC-based MatList', () => {
6968
});
7069

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

558-
@Component({
559-
template: `
560-
<mat-list>
561-
@for (item of items; track item) {
562-
<mat-list-item>
563-
<h3 matListItemTitle>Line 1</h3>
564-
<p matListItemLine>Line 2</p>
565-
<p matListItemLine>Line 3</p>
566-
<p matListItemLine>Line 4</p>
567-
</mat-list-item>
568-
}
569-
</mat-list>`,
570-
})
571-
class ListWithManyLines extends BaseTestList {}
572-
573557
@Component({
574558
template: `
575559
<mat-list>

0 commit comments

Comments
 (0)