diff --git a/components/css/ng2-select.css b/components/css/ng2-select.css index c0aac6a3..4a133f49 100644 --- a/components/css/ng2-select.css +++ b/components/css/ng2-select.css @@ -42,6 +42,10 @@ display:none; } +.ui-select-match-close { + margin-top:2px; +} + body > .select2-container.open { z-index: 9999; /* The z-index Select2 applies to the select2-drop */ } diff --git a/components/select/select-item.ts b/components/select/select-item.ts index eff1efb9..135ebc4e 100644 --- a/components/select/select-item.ts +++ b/components/select/select-item.ts @@ -45,3 +45,4 @@ export class SelectItem { return r; } } + diff --git a/components/select/select.ts b/components/select/select.ts index 78a5c5b9..422f48e8 100644 --- a/components/select/select.ts +++ b/components/select/select.ts @@ -20,9 +20,9 @@ import {IOptionsBehavior} from './select-interfaces'; import {escapeRegexp} from './common'; let optionsTemplate = ` - - `; @Component({ - selector: 'ng-select', + selector: 'ng2-select', pipes: [HighlightPipe], template: `
(this.multiple === false || - this.multiple === true && !this.active.find(o => option.text === o.text))); + if (this.optionsOpened) + return; + + this.populateOptions(); if (this.options.length > 0) { this.behavior.first(); @@ -238,6 +249,12 @@ export class Select { this.optionsOpened = true; } + + private populateOptions() { + this.options = this.itemObjects + .filter(option => (this.multiple === false || + this.multiple === true && !this.active.find(o => option.text === o.text))); + } ngOnInit() { this.behavior = this.itemObjects[0].hasChildren() ? @@ -263,7 +280,7 @@ export class Select { return; } - if (e.srcElement.contains(context.element.nativeElement) + if (context.element.nativeElement.contains(e.srcElement) && e.srcElement && e.srcElement.className && e.srcElement.className.indexOf('ui-select') >= 0) { if (e.target.nodeName !== 'INPUT') { @@ -395,7 +412,8 @@ export class Select { } private selectActiveMatch() { - this.selectMatch(this.activeOption); + if (this.options && this.options.length > 0) + this.selectMatch(this.activeOption); } private selectMatch(value:SelectItem, e:Event = null) { @@ -405,7 +423,7 @@ export class Select { } if (this.options.length <= 0) { - return; + this.populateOptions(); //load options, if they aren't yet populated } if (this.multiple === true) { @@ -420,9 +438,11 @@ export class Select { this.doEvent('selected', value); this.hideOptions(); + this.inputValue = ''; //clear highlight pipe match if (this.multiple === true) { this.focusToInput(''); + this.open(); } else { this.focusToInput( stripTags(value.text) ); this.element.nativeElement.querySelector('.ui-select-container').focus(); @@ -629,3 +649,4 @@ export class ChildrenBehavior extends Behavior implements IOptionsBehavior { } +