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

Function activateInkBar

src/material/tabs/ink-bar.ts:98–131  ·  view source on GitHub ↗

Aligns the ink bar to the current item.

(previousIndicatorClientRect?: DOMRect)

Source from the content-addressed store, hash-verified

96
97 /** Aligns the ink bar to the current item. */
98 activateInkBar(previousIndicatorClientRect?: DOMRect) {
99 const element = this._elementRef.nativeElement;
100
101 // Early exit if no indicator is present to handle cases where an indicator
102 // may be activated without a prior indicator state
103 if (
104 !previousIndicatorClientRect ||
105 !element.getBoundingClientRect ||
106 !this._inkBarContentElement
107 ) {
108 element.classList.add(ACTIVE_CLASS);
109 return;
110 }
111
112 // This animation uses the FLIP approach. You can read more about it at the link below:
113 // https://aerotwist.com/blog/flip-your-animations/
114
115 // Calculate the dimensions based on the dimensions of the previous indicator
116 const currentClientRect = element.getBoundingClientRect();
117 const widthDelta = previousIndicatorClientRect.width / currentClientRect.width;
118 const xPosition = previousIndicatorClientRect.left - currentClientRect.left;
119 element.classList.add(NO_TRANSITION_CLASS);
120 this._inkBarContentElement.style.setProperty(
121 'transform',
122 `translateX(${xPosition}px) scaleX(${widthDelta})`,
123 );
124
125 // Force repaint before updating classes and transform to ensure the transform properly takes effect
126 element.getBoundingClientRect();
127
128 element.classList.remove(NO_TRANSITION_CLASS);
129 element.classList.add(ACTIVE_CLASS);
130 this._inkBarContentElement.style.setProperty('transform', '');
131 }
132
133 /** Removes the ink bar from the current item. */
134 deactivateInkBar() {

Callers

nothing calls this directly

Calls 3

getBoundingClientRectMethod · 0.80
removeMethod · 0.65
addMethod · 0.45

Tested by

no test coverage detected