Skip to content

Commit

Permalink
refactor on button states
Browse files Browse the repository at this point in the history
  • Loading branch information
cetincakiroglu committed Feb 23, 2024
1 parent 468ed09 commit f09e454
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/app/components/tabview/tabview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import { Subscription } from 'rxjs';
import { TabViewChangeEvent, TabViewCloseEvent } from './tabview.interface';
import { UniqueComponentId } from 'primeng/utils';
import { Nullable } from 'primeng/ts-helpers';
import { AnimationStyleMetadata } from '@angular/animations';

/**
* TabPanel is a helper component for TabView component.
Expand Down Expand Up @@ -496,6 +495,7 @@ export class TabView implements AfterContentInit, AfterViewChecked, OnDestroy, B

this.tabChangesSubscription = (this.tabPanels as QueryList<TabPanel>).changes.subscribe((_) => {
this.initTabs();
this.refreshButtonState();
});

(this.templates as QueryList<PrimeTemplate>).forEach((item) => {
Expand Down Expand Up @@ -524,7 +524,7 @@ export class TabView implements AfterContentInit, AfterViewChecked, OnDestroy, B
this.list = DomHandler.findSingle(this.el.nativeElement, '[data-pc-section="nav"]');

this.resizeObserver = new ResizeObserver(() => {
if (this.list.offsetWidth > this.container.offsetWidth) {
if (this.list.offsetWidth >= this.container.offsetWidth) {
this.buttonVisible = true;
} else {
this.buttonVisible = false;
Expand Down Expand Up @@ -812,6 +812,20 @@ export class TabView implements AfterContentInit, AfterViewChecked, OnDestroy, B
this.forwardIsDisabled = scrollLeft === scrollWidth - width;
}

refreshButtonState() {
this.container = DomHandler.findSingle(this.el.nativeElement, '[data-pc-section="navcontent"]');
this.list = DomHandler.findSingle(this.el.nativeElement, '[data-pc-section="nav"]');
if (this.list.offsetWidth >= this.container.offsetWidth) {
if (this.list.offsetWidth >= this.container.offsetWidth) {
this.buttonVisible = true;
} else {
this.buttonVisible = false;
}
this.updateButtonState();
this.cd.markForCheck();
}
}

onScroll(event: Event) {
this.scrollable && this.updateButtonState();

Expand Down

0 comments on commit f09e454

Please sign in to comment.