From 7a4c52499f7a4bce05b6ee8143dfd68022363d05 Mon Sep 17 00:00:00 2001 From: Sergey Andrievskiy Date: Fri, 19 Apr 2019 19:27:14 +0300 Subject: [PATCH] fix(select): emit array when resetting multiple select --- .../components/select/select.component.ts | 2 +- .../theme/components/select/select.spec.ts | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/framework/theme/components/select/select.component.ts b/src/framework/theme/components/select/select.component.ts index a401a6c916..5507240558 100644 --- a/src/framework/theme/components/select/select.component.ts +++ b/src/framework/theme/components/select/select.component.ts @@ -416,7 +416,7 @@ export class NbSelectComponent implements OnInit, AfterViewInit, AfterContent this.selectionModel = []; this.hide(); this.button.nativeElement.focus(); - this.emitSelected(null); + this.emitSelected(this.multiple ? [] : null); } /** diff --git a/src/framework/theme/components/select/select.spec.ts b/src/framework/theme/components/select/select.spec.ts index c67a971dec..0d2205688a 100644 --- a/src/framework/theme/components/select/select.spec.ts +++ b/src/framework/theme/components/select/select.spec.ts @@ -252,6 +252,31 @@ describe('Component: NbSelectComponent', () => { expect(overlayContainer.querySelectorAll('nb-option.selected').length).toBe(0); }); + it('should emit selectionChange with empty array when reset option selected in multiple select', () => { + select.multiple = true; + setSelectedAndOpen(['Option 1', 'Option 2']); + + const selectionChangeSpy = createSpy('selectionChangeSpy'); + select.selectedChange.subscribe(selectionChangeSpy); + + const option = overlayContainer.querySelector('nb-option'); + option.dispatchEvent(new Event('click')); + + expect(selectionChangeSpy).toHaveBeenCalledWith([]); + }); + + it('should emit selectionChange with null when reset option selected in single select', () => { + setSelectedAndOpen('Option 1'); + + const selectionChangeSpy = createSpy('selectionChangeSpy'); + select.selectedChange.subscribe(selectionChangeSpy); + + const option = overlayContainer.querySelector('nb-option'); + option.dispatchEvent(new Event('click')); + + expect(selectionChangeSpy).toHaveBeenCalledWith(null); + }); + it('should deselect only clicked item in multiple select', () => { select.multiple = true; setSelectedAndOpen(['Option 1', 'Option 2']);