Skip to content

Commit 3694714

Browse files
committed
Exported select directives
1 parent 2a1306f commit 3694714

File tree

5 files changed

+41
-24
lines changed

5 files changed

+41
-24
lines changed

components/select.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {Select, SelectValueAccessor} from './select/select.component';
2+
import {SelectOption} from './select/select-option.component';
3+
4+
export {Select, SelectValueAccessor} from './select/select.component';
5+
export {SelectOption} from './select/select-option.component';
6+
7+
export const SELECT_DIRECTIVES:Array<any> = [Select, SelectOption, SelectValueAccessor];
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import {Component, Input, HostBinding, ElementRef, HostListener} from 'angular2/core';
2+
import {Select} from '../select';
3+
4+
@Component({
5+
selector: 'sui-select-option',
6+
template: `<ng-content></ng-content>`
7+
})
8+
export class SelectOption {
9+
@HostBinding('class.item') itemClass = true;
10+
11+
@Input()
12+
public value:any;
13+
14+
constructor(private host:Select, private el:ElementRef) { }
15+
16+
@HostListener('click', ['$event'])
17+
public click(event):boolean {
18+
event.stopPropagation();
19+
this.host.selectOption(this.value, this.el.nativeElement.innerHTML);
20+
return false;
21+
}
22+
}

components/select/select.component.ts

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Component, Directive, Provider, Input, ViewChild, HostBinding, ElementRef, HostListener, forwardRef} from 'angular2/core';
1+
import {Component, Directive, Provider, ViewChild, HostBinding, ElementRef, HostListener, forwardRef} from 'angular2/core';
22
import {ControlValueAccessor, NG_VALUE_ACCESSOR} from 'angular2/common';
33
import {Search, SearchValueAccessor} from '../search';
44
import {DropdownMenu} from '../dropdown';
@@ -128,6 +128,10 @@ export class Select extends Search {
128128
this.selectedOptions.splice(index, 1);
129129
this.selectedOptionsHTML.splice(index, 1);
130130
this.selectedOptionChange.emit(this.selectedOptions);
131+
132+
if (this.isSearchable) {
133+
this.focusFirstItem();
134+
}
131135
}
132136

133137
//noinspection JSMethodCanBeStatic
@@ -181,31 +185,12 @@ export class Select extends Search {
181185
var lastSelectedOption = selectedOptions[selectedOptions.length - 1];
182186
if (lastSelectedOption) {
183187
this.deselectOption(lastSelectedOption);
188+
184189
}
185190
}
186191
}
187192
}
188193

189-
@Component({
190-
selector: 'sui-select-option',
191-
template: `<ng-content></ng-content>`
192-
})
193-
export class SelectOption {
194-
@HostBinding('class.item') itemClass = true;
195-
196-
@Input()
197-
public value:any;
198-
199-
constructor(private host:Select, private el:ElementRef) { }
200-
201-
@HostListener('click', ['$event'])
202-
public click(event):boolean {
203-
event.stopPropagation();
204-
this.host.selectOption(this.value, this.el.nativeElement.innerHTML);
205-
return false;
206-
}
207-
}
208-
209194
const CUSTOM_VALUE_ACCESSOR = new Provider(NG_VALUE_ACCESSOR, {useExisting: forwardRef(() => SelectValueAccessor), multi: true});
210195

211196
@Directive({

demo/app/components/test.page.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import {Component} from 'angular2/core';
33
import {PageTitle} from "../internal/page-title.component";
44

55
import {CHECKBOX_DIRECTIVES} from '../../../components/checkbox';
6-
import {Select, SelectValueAccessor, SelectOption} from "../../../components/select/select.component";
6+
import {SELECT_DIRECTIVES} from "../../../components/select";
77
import {TEMPLATE_DIRECTIVES} from "../../../components/template";
88

99
@Component({
1010
selector: 'test-component-page',
11-
directives: [PageTitle, CHECKBOX_DIRECTIVES, TEMPLATE_DIRECTIVES, Select, SelectValueAccessor, SelectOption],
11+
directives: [PageTitle, CHECKBOX_DIRECTIVES, TEMPLATE_DIRECTIVES, SELECT_DIRECTIVES],
1212
template: `
1313
<page-title>
1414
<div header>Test</div>
@@ -28,7 +28,7 @@ import {TEMPLATE_DIRECTIVES} from "../../../components/template";
2828
<p>Selected option: {{ selected | json }}</p>
2929
</div>
3030
<div class="ui segment">
31-
<sui-select class="fluid" [options]="options" optionsField="test" [(ngModel)]="selectedItems" [isSearchable]="false" [allowMultiple]="true" #multiSelect>
31+
<sui-select class="fluid" [options]="optionsSearch" optionsField="test" [(ngModel)]="selectedItems" [isSearchable]="true" [allowMultiple]="true" #multiSelect>
3232
<sui-select-option *ngFor="#result of multiSelect.results" [value]="result"><i class="af flag"></i>{{ result.test }}</sui-select-option>
3333
</sui-select>
3434
</div>

ng2-semantic-ui.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {PROGRESS_DIRECTIVES} from './components/progress';
88
import {MESSAGE_DIRECTIVES} from './components/message';
99
import {RATING_DIRECTIVES} from './components/rating';
1010
import {SEARCH_DIRECTIVES} from './components/search';
11+
import {SELECT_DIRECTIVES} from './components/select';
1112
import {TAB_DIRECTIVES} from './components/tab';
1213
import {TEMPLATE_DIRECTIVES} from './components/template';
1314

@@ -21,6 +22,7 @@ export * from './components/progress';
2122
export * from './components/message';
2223
export * from './components/rating';
2324
export * from './components/search';
25+
export * from './components/select';
2426
export * from './components/tab';
2527
export * from './components/template';
2628

@@ -35,6 +37,7 @@ export const DIRECTIVES: any[] = [
3537
MESSAGE_DIRECTIVES,
3638
RATING_DIRECTIVES,
3739
SEARCH_DIRECTIVES,
40+
SELECT_DIRECTIVES,
3841
TAB_DIRECTIVES,
3942
TEMPLATE_DIRECTIVES
4043
];

0 commit comments

Comments
 (0)