MCPcopy Create free account
hub / github.com/angular/components / _updateItemLines

Function _updateItemLines

src/material/list/list-base.ts:255–294  ·  view source on GitHub ↗

* Updates the lines of the list item. Based on the projected user content and optional * explicit lines setting, the visual appearance of the list item is determined. * * This method should be invoked whenever the projected user content changes, or * when the explicit lines have been upd

(recheckUnscopedContent: boolean)

Source from the content-addressed store, hash-verified

253 * for content that is expected to not change very often.
254 */
255 _updateItemLines(recheckUnscopedContent: boolean) {
256 // If the updated is triggered too early before the view and content is initialized,
257 // we just skip the update. After view initialization the update is triggered again.
258 if (!this._lines || !this._titles || !this._unscopedContent) {
259 return;
260 }
261
262 // Re-check the DOM for unscoped text content if requested. This needs to
263 // happen before any computation or sanity checks run as these rely on the
264 // result of whether there is unscoped text content or not.
265 if (recheckUnscopedContent) {
266 this._checkDomForUnscopedTextContent();
267 }
268
269 // Sanity check the list item lines and title in the content. This is a dev-mode only
270 // check that can be dead-code eliminated by Terser in production.
271 if (typeof ngDevMode === 'undefined' || ngDevMode) {
272 sanityCheckListItemContent(this);
273 }
274
275 const numberOfLines = this._explicitLines ?? this._inferLinesFromContent();
276 const unscopedContentEl = this._unscopedContent.nativeElement;
277
278 // Update the list item element to reflect the number of lines.
279 this._hostElement.classList.toggle('mat-mdc-list-item-single-line', numberOfLines <= 1);
280 this._hostElement.classList.toggle('mdc-list-item--with-one-line', numberOfLines <= 1);
281 this._hostElement.classList.toggle('mdc-list-item--with-two-lines', numberOfLines === 2);
282 this._hostElement.classList.toggle('mdc-list-item--with-three-lines', numberOfLines === 3);
283
284 // If there is no title and the unscoped content is the is the only line, the
285 // unscoped text content will be treated as the title of the list-item.
286 if (this._hasUnscopedTextContent) {
287 const treatAsTitle = this._titles.length === 0 && numberOfLines === 1;
288 unscopedContentEl.classList.toggle('mdc-list-item__primary-text', treatAsTitle);
289 unscopedContentEl.classList.toggle('mdc-list-item__secondary-text', !treatAsTitle);
290 } else {
291 unscopedContentEl.classList.remove('mdc-list-item__primary-text');
292 unscopedContentEl.classList.remove('mdc-list-item__secondary-text');
293 }
294 }
295
296 /**
297 * Infers the number of lines based on the projected user content. This is useful

Callers

nothing calls this directly

Calls 3

toggleMethod · 0.65
removeMethod · 0.65

Tested by

no test coverage detected