From 7a2f867119cc06f9b011d5526b02bc73849119d7 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Wed, 4 Dec 2024 10:22:00 -0800 Subject: [PATCH] Prevent apply on close for extra button --- .../filterable-dropdown.component.html | 2 +- .../filterable-dropdown.component.spec.ts | 20 +++++++++++++++++++ .../filterable-dropdown.component.ts | 9 +++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src-ui/src/app/components/common/filterable-dropdown/filterable-dropdown.component.html b/src-ui/src/app/components/common/filterable-dropdown/filterable-dropdown.component.html index 4b514a6dd..310edd1f1 100644 --- a/src-ui/src/app/components/common/filterable-dropdown/filterable-dropdown.component.html +++ b/src-ui/src/app/components/common/filterable-dropdown/filterable-dropdown.component.html @@ -67,7 +67,7 @@ } } @if (extraButtonTitle) { - } diff --git a/src-ui/src/app/components/common/filterable-dropdown/filterable-dropdown.component.spec.ts b/src-ui/src/app/components/common/filterable-dropdown/filterable-dropdown.component.spec.ts index 78af75607..2a4cce8d6 100644 --- a/src-ui/src/app/components/common/filterable-dropdown/filterable-dropdown.component.spec.ts +++ b/src-ui/src/app/components/common/filterable-dropdown/filterable-dropdown.component.spec.ts @@ -616,4 +616,24 @@ describe('FilterableDropdownComponent & FilterableDropdownSelectionModel', () => document.dispatchEvent(new KeyboardEvent('keydown', { key: 't' })) expect(openSpy).toHaveBeenCalled() }) + + it('should support an extra button and not apply changes when clicked', () => { + component.items = items + component.icon = 'tag-fill' + component.extraButtonTitle = 'Extra' + component.selectionModel = selectionModel + component.applyOnClose = true + let extraButtonClicked, + applied = false + component.extraButton.subscribe(() => (extraButtonClicked = true)) + component.apply.subscribe(() => (applied = true)) + fixture.nativeElement + .querySelector('button') + .dispatchEvent(new MouseEvent('click')) // open + fixture.detectChanges() + expect(fixture.debugElement.nativeElement.textContent).toContain('Extra') + component.extraButtonClicked() + expect(extraButtonClicked).toBeTruthy() + expect(applied).toBeFalsy() + }) }) diff --git a/src-ui/src/app/components/common/filterable-dropdown/filterable-dropdown.component.ts b/src-ui/src/app/components/common/filterable-dropdown/filterable-dropdown.component.ts index b7f7e2815..069865078 100644 --- a/src-ui/src/app/components/common/filterable-dropdown/filterable-dropdown.component.ts +++ b/src-ui/src/app/components/common/filterable-dropdown/filterable-dropdown.component.ts @@ -650,4 +650,13 @@ export class FilterableDropdownComponent implements OnDestroy, OnInit { this.selectionModel.get(item.id) !== ToggleableItemState.Selected ) } + + extraButtonClicked() { + // don't apply changes when clicking the extra button + const applyOnClose = this.applyOnClose + this.applyOnClose = false + this.dropdown.close() + this.extraButton.emit() + this.applyOnClose = applyOnClose + } }