From a02b08c4c19bae5d1805a40aeb4714e9fbe2965a Mon Sep 17 00:00:00 2001 From: joseph rosenthal Date: Tue, 26 Sep 2023 11:46:39 -0400 Subject: [PATCH] properly fix issue #13361 merge pull request #13392 fixed issue #13361 but caused filters not to automatically close when clicking different filter buttons. This change properly fixes issue #13361 and as a result fixes the bug that was induced by the original attempted fix. Instead of stopping the click event propagation, the isFilterElement method is improved by calling a new isFilterElementIconOrButton method --- src/app/components/table/table.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/app/components/table/table.ts b/src/app/components/table/table.ts index 7b381c1966b..cb7a8620200 100644 --- a/src/app/components/table/table.ts +++ b/src/app/components/table/table.ts @@ -3338,7 +3338,7 @@ export class SortableColumn implements OnInit, OnDestroy { @HostListener('click', ['$event']) onClick(event: MouseEvent) { - if (this.isEnabled()) { + if (this.isEnabled() && !this.isFilterElement(event.target)) { this.updateSortState(); this.dt.sort({ originalEvent: event, @@ -3358,6 +3358,13 @@ export class SortableColumn implements OnInit, OnDestroy { return this.pSortableColumnDisabled !== true; } + isFilterElement(element: HTMLElement) { + return this.isFilterElementIconOrButton(element) || this.isFilterElementIconOrButton(element?.parentElement?.parentElement); + } + private isFilterElementIconOrButton(element: HTMLElement) { + return DomHandler.hasClass(element, 'pi-filter-icon') || DomHandler.hasClass(element, 'p-column-filter-menu-button'); + } + ngOnDestroy() { if (this.subscription) { this.subscription.unsubscribe(); @@ -4777,7 +4784,7 @@ export class ReorderableRow implements AfterViewInit { aria-haspopup="true" [attr.aria-expanded]="overlayVisible" [ngClass]="{ 'p-column-filter-menu-button-open': overlayVisible, 'p-column-filter-menu-button-active': hasFilter() }" - (click)="toggleMenu($event)" + (click)="toggleMenu()" (keydown)="onToggleButtonKeyDown($event)" > @@ -5108,9 +5115,8 @@ export class ColumnFilter implements AfterContentInit { } } - toggleMenu(event: any) { + toggleMenu() { this.overlayVisible = !this.overlayVisible; - event.stopPropagation(); } onToggleButtonKeyDown(event: KeyboardEvent) {