Skip to content

Commit

Permalink
fix(select): emit array when resetting multiple select (#1399)
Browse files Browse the repository at this point in the history
  • Loading branch information
yggg committed Jun 6, 2019
1 parent 36aa416 commit fbda1d2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/framework/theme/components/select/select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ export class NbSelectComponent<T> implements OnInit, AfterViewInit, AfterContent
this.selectionModel = [];
this.hide();
this.button.nativeElement.focus();
this.emitSelected(null);
this.emitSelected(this.multiple ? [] : null);
}

/**
Expand Down
25 changes: 25 additions & 0 deletions src/framework/theme/components/select/select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,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']);
Expand Down

0 comments on commit fbda1d2

Please sign in to comment.