Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(select): emit array when resetting multiple select #1399

Merged
merged 2 commits into from
Apr 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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']);
Expand Down