* Moves the tab list such that the desired tab label (marked by index) is moved into view. * * This is an expensive call that forces a layout reflow to compute box and scroll metrics and * should be called sparingly.
(labelIndex: number)
| 508 | * should be called sparingly. |
| 509 | */ |
| 510 | _scrollToLabel(labelIndex: number) { |
| 511 | if (this.disablePagination) { |
| 512 | return; |
| 513 | } |
| 514 | |
| 515 | const selectedLabel = this._items ? this._items.toArray()[labelIndex] : null; |
| 516 | |
| 517 | if (!selectedLabel) { |
| 518 | return; |
| 519 | } |
| 520 | |
| 521 | // The view length is the visible width of the tab labels. |
| 522 | const viewLength = this._tabListContainer.nativeElement.offsetWidth; |
| 523 | const {offsetLeft, offsetWidth} = selectedLabel.elementRef.nativeElement; |
| 524 | |
| 525 | let labelBeforePos: number, labelAfterPos: number; |
| 526 | if (this._getLayoutDirection() == 'ltr') { |
| 527 | labelBeforePos = offsetLeft; |
| 528 | labelAfterPos = labelBeforePos + offsetWidth; |
| 529 | } else { |
| 530 | labelAfterPos = this._tabListInner.nativeElement.offsetWidth - offsetLeft; |
| 531 | labelBeforePos = labelAfterPos - offsetWidth; |
| 532 | } |
| 533 | |
| 534 | const beforeVisiblePos = this.scrollDistance; |
| 535 | const afterVisiblePos = this.scrollDistance + viewLength; |
| 536 | |
| 537 | if (labelBeforePos < beforeVisiblePos) { |
| 538 | // Scroll header to move label to the before direction |
| 539 | this.scrollDistance -= beforeVisiblePos - labelBeforePos; |
| 540 | } else if (labelAfterPos > afterVisiblePos) { |
| 541 | // Scroll header to move label to the after direction |
| 542 | this.scrollDistance += Math.min( |
| 543 | labelAfterPos - afterVisiblePos, |
| 544 | labelBeforePos - beforeVisiblePos, |
| 545 | ); |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | /** |
| 550 | * Evaluate whether the pagination controls should be displayed. If the scroll width of the |
nothing calls this directly
no test coverage detected