Skip to content

Commit

Permalink
chore: update demo with max selection warning
Browse files Browse the repository at this point in the history
  • Loading branch information
varnastadeus committed Sep 5, 2018
1 parent 32d1825 commit b4ea12d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions demo/app/examples/multi.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ import { DataService } from '../shared/data.service';
<label>Select multiple elements with a limit number of selections (e.g 3)</label>
---html,true
<div class="alert alert-warning mb-2" *ngIf="selectedPeople2.length === 3 && select.focused">
<small >Max selection reached</small>
</div>
<ng-select
#select
[items]="people$2 | async"
[multiple]="true"
[maxSelectedItems]="3"
Expand Down
10 changes: 5 additions & 5 deletions src/ng-select/ng-select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ export class NgSelectComponent implements OnDestroy, OnChanges, AfterViewInit, C
dropdownId = newId();
selectedItemId = 0;
element: HTMLElement;
focused: boolean;

private _defaultLabel = 'label';
private _primitive: boolean;
private _focused: boolean;
private _manualOpen: boolean;
private _pressedKeys: string[] = [];
private _compareWith: CompareWithFn;
Expand Down Expand Up @@ -278,7 +278,7 @@ export class NgSelectComponent implements OnDestroy, OnChanges, AfterViewInit, C
return;
}

if (!this._focused) {
if (!this.focused) {
this.focus();
}

Expand Down Expand Up @@ -474,13 +474,13 @@ export class NgSelectComponent implements OnDestroy, OnChanges, AfterViewInit, C
}

onInputFocus($event) {
if (this._focused) {
if (this.focused) {
return;
}

this.element.classList.add('ng-select-focused');
this.focusEvent.emit($event);
this._focused = true;
this.focused = true;
}

onInputBlur($event) {
Expand All @@ -489,7 +489,7 @@ export class NgSelectComponent implements OnDestroy, OnChanges, AfterViewInit, C
if (!this.isOpen && !this.disabled) {
this._onTouched();
}
this._focused = false;
this.focused = false;
}

onItemHover(item: NgOption) {
Expand Down

0 comments on commit b4ea12d

Please sign in to comment.