MCPcopy
hub / github.com/angular/components / getDimension

Function getDimension

src/material/grid-list/grid-list.spec.ts:506–523  ·  view source on GitHub ↗

Gets the computed dimension of a DebugElement in pixels.

(el: DebugElement, dimension: 'width' | 'height' | 'top' | 'left')

Source from the content-addressed store, hash-verified

504
505/** Gets the computed dimension of a DebugElement in pixels. */
506function getDimension(el: DebugElement, dimension: 'width' | 'height' | 'top' | 'left'): number {
507 const nativeElement: HTMLElement = el.nativeElement;
508
509 switch (dimension) {
510 // Note that we use direct measurements, rather than the computed style, because
511 // `getComputedStyle` can be inconsistent between browser and can cause flakes.
512 case 'width':
513 return nativeElement.getBoundingClientRect().width;
514 case 'height':
515 return nativeElement.getBoundingClientRect().height;
516 case 'top':
517 return nativeElement.offsetTop;
518 case 'left':
519 return nativeElement.offsetLeft;
520 default:
521 throw Error(`Unknown dimension ${dimension}.`);
522 }
523}
524
525/** Gets the `left` position of an element. */
526function getComputedLeft(element: DebugElement): number {

Callers 1

grid-list.spec.tsFile · 0.85

Calls 1

getBoundingClientRectMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…