Aligns the ink bar to a DOM node.
(element: HTMLElement)
| 53 | |
| 54 | /** Aligns the ink bar to a DOM node. */ |
| 55 | alignToElement(element: HTMLElement) { |
| 56 | const correspondingItem = this._items.find(item => item.elementRef.nativeElement === element); |
| 57 | const currentItem = this._currentItem; |
| 58 | |
| 59 | if (correspondingItem === currentItem) { |
| 60 | return; |
| 61 | } |
| 62 | |
| 63 | currentItem?.deactivateInkBar(); |
| 64 | |
| 65 | if (correspondingItem) { |
| 66 | const domRect = currentItem?.elementRef.nativeElement.getBoundingClientRect?.(); |
| 67 | |
| 68 | // The ink bar won't animate unless we give it the `DOMRect` of the previous item. |
| 69 | correspondingItem.activateInkBar(domRect); |
| 70 | this._currentItem = correspondingItem; |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | @Directive() |
no test coverage detected