Skip to content

Commit 6379889

Browse files
authored
Merge pull request #27 from chris--jones/feature/auto_unselect
automatically unselect the first selected item when exceeding the sel…
2 parents c7c36e7 + 15f7a47 commit 6379889

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/multiselect-dropdown.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export interface IMultiSelectSettings {
2929
buttonClasses?: string;
3030
selectionLimit?: number;
3131
closeOnSelect?: boolean;
32+
autoUnselect?: boolean;
3233
showCheckAll?: boolean;
3334
showUncheckAll?: boolean;
3435
dynamicTitleMaxItems?: number;
@@ -132,6 +133,7 @@ export class MultiselectDropdown implements OnInit, DoCheck, ControlValueAccesso
132133
buttonClasses: 'btn btn-default',
133134
selectionLimit: 0,
134135
closeOnSelect: false,
136+
autoUnselect: false,
135137
showCheckAll: false,
136138
showUncheckAll: false,
137139
dynamicTitleMaxItems: 3,
@@ -202,8 +204,13 @@ export class MultiselectDropdown implements OnInit, DoCheck, ControlValueAccesso
202204
if (this.settings.selectionLimit === 0 || this.model.length < this.settings.selectionLimit) {
203205
this.model.push(option.id);
204206
} else {
205-
this.selectionLimitReached.emit(this.model.length);
206-
return;
207+
if (this.settings.autoUnselect) {
208+
this.model.push(option.id)
209+
this.model.shift();
210+
} else {
211+
this.selectionLimitReached.emit(this.model.length);
212+
return;
213+
}
207214
}
208215
}
209216
if (this.settings.closeOnSelect) {

0 commit comments

Comments
 (0)