Skip to content

Commit a60372b

Browse files
committed
Updated docs for select element
1 parent 11f25db commit a60372b

File tree

5 files changed

+71
-60
lines changed

5 files changed

+71
-60
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import {Component, HostBinding, ElementRef, Renderer, HostListener, Input, ViewContainerRef, EventEmitter, ViewChild} from "@angular/core";
2+
import {SuiTransition} from "../transition/transition";
3+
4+
@Component({
5+
selector: 'sui-select-multi-label',
6+
template: `
7+
<span #optionRenderTarget></span>
8+
<span *ngIf="!useTemplate">{{ readValue(value) }}</span>
9+
<i class="delete icon" (click)="deselectOption()"></i>
10+
`
11+
})
12+
export class SuiSelectMultiLabel {
13+
@HostBinding('class.ui')
14+
@HostBinding('class.label') classes = true;
15+
16+
private _transition:SuiTransition;
17+
constructor(private el:ElementRef, private renderer:Renderer) {
18+
this._transition = new SuiTransition(el, renderer);
19+
this._transition.animate({
20+
name: "scale",
21+
direction: "in",
22+
display: "inline-block",
23+
duration: 100
24+
});
25+
}
26+
27+
public useTemplate:boolean = false;
28+
29+
@HostListener('click', ['$event'])
30+
public click(event:MouseEvent):boolean {
31+
event.stopPropagation();
32+
return false;
33+
}
34+
35+
public readValue = (value:any) => "";
36+
37+
@Input()
38+
public value:any;
39+
40+
public selected:EventEmitter<any> = new EventEmitter<any>();
41+
42+
@ViewChild('optionRenderTarget', { read: ViewContainerRef })
43+
public viewContainerRef:ViewContainerRef;
44+
45+
public deselectOption() {
46+
event.stopPropagation();
47+
this._transition.animate({
48+
name: "scale",
49+
direction: "out",
50+
duration: 100,
51+
callback: () => this.selected.emit(this.value)
52+
});
53+
return false;
54+
}
55+
}

components/select/multi-select.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import {
66
import {NG_VALUE_ACCESSOR, ControlValueAccessor} from '@angular/forms';
77

88
import {SuiDropdownMenu} from "../dropdown/dropdown-menu";
9-
import {SuiSelectOption, SuiSelectMultiLabel} from "./select-option";
9+
import {SuiSelectOption} from "./select-option";
1010
import {KeyCode} from '../../components/dropdown/dropdown.service';
1111
import {Subscription} from "rxjs";
1212
import {SuiDropdownService} from "../dropdown/dropdown.service";
1313
import {Input, Output} from "@angular/core/src/metadata/directives";
1414
import {SuiSearchService} from "../search/search.service";
15+
import {SuiSelectMultiLabel} from "./multi-select-label";
1516

1617
@Component({
1718
selector: 'sui-multi-select',

components/select/select-option.ts

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import {
22
Component, Input, HostBinding, HostListener, EventEmitter, ViewContainerRef, ViewChild,
3-
ElementRef, Renderer
43
} from '@angular/core';
5-
import {SuiTransition} from "../transition/transition";
64

75
@Component({
86
selector: 'sui-select-option',
@@ -35,56 +33,3 @@ export class SuiSelectOption {
3533
return false;
3634
}
3735
}
38-
39-
@Component({
40-
selector: 'sui-select-multi-label',
41-
template: `
42-
<span #optionRenderTarget></span>
43-
<span *ngIf="!useTemplate">{{ readValue(value) }}</span>
44-
<i class="delete icon" (click)="deselectOption()"></i>
45-
`
46-
})
47-
export class SuiSelectMultiLabel {
48-
@HostBinding('class.ui')
49-
@HostBinding('class.label') classes = true;
50-
51-
private _transition:SuiTransition;
52-
constructor(private el:ElementRef, private renderer:Renderer) {
53-
this._transition = new SuiTransition(el, renderer);
54-
this._transition.animate({
55-
name: "scale",
56-
direction: "in",
57-
display: "inline-block",
58-
duration: 100
59-
});
60-
}
61-
62-
public useTemplate:boolean = false;
63-
64-
@HostListener('click', ['$event'])
65-
public click(event:MouseEvent):boolean {
66-
event.stopPropagation();
67-
return false;
68-
}
69-
70-
public readValue = (value:any) => "";
71-
72-
@Input()
73-
public value:any;
74-
75-
public selected:EventEmitter<any> = new EventEmitter<any>();
76-
77-
@ViewChild('optionRenderTarget', { read: ViewContainerRef })
78-
public viewContainerRef:ViewContainerRef;
79-
80-
public deselectOption() {
81-
event.stopPropagation();
82-
this._transition.animate({
83-
name: "scale",
84-
direction: "out",
85-
duration: 100,
86-
callback: () => this.selected.emit(this.value)
87-
});
88-
return false;
89-
}
90-
}

components/select/select.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ import {
66
import {NG_VALUE_ACCESSOR, ControlValueAccessor} from '@angular/forms';
77

88
import {SuiDropdownMenu} from "../dropdown/dropdown-menu";
9-
import {SuiSelectOption, SuiSelectMultiLabel} from "./select-option";
9+
import {SuiSelectOption} from "./select-option";
1010
import {KeyCode} from '../../components/dropdown/dropdown.service';
1111
import {Subscription} from "rxjs";
1212
import {SuiDropdownService} from "../dropdown/dropdown.service";
1313
import {Input, Output} from "@angular/core/src/metadata/directives";
1414
import {SuiSearchService} from "../search/search.service";
1515
import {SuiMultiSelect, SuiMultiSelectValueAccessor} from "./multi-select";
16+
import {SuiSelectMultiLabel} from "./multi-select-label";
1617

1718
@Component({
1819
selector: 'sui-select',
@@ -209,6 +210,7 @@ export class SuiSelect implements AfterContentInit, AfterViewInit {
209210
this._searchService.updateQuery(this._searchService.readValue(option), false);
210211
this._dropdownService.isOpen = false;
211212
this.renderSelectedItem();
213+
212214
this._searchService.updateQuery("");
213215
}
214216

demo/app/pages/select/select.page.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@ export class SelectPage {
2020
description: "Sets the options available to the select component."
2121
},
2222
{
23-
name: "optionsField",
23+
name: "displayField",
2424
description: "Sets the property name that the select element uses to display each option. Supports dot notation for nested properties."
2525
},
26+
{
27+
name: "keyField",
28+
description: "Sets the property name that the select element uses to bind to ngModel. Leaving this blank uses the entire object. Supports dot notation for nested properties."
29+
},
2630
{
2731
name: "isDisabled",
2832
description: "Sets whether or not the select is disabled",
@@ -66,9 +70,13 @@ export class SelectPage {
6670
description: "Sets the options available to the select component."
6771
},
6872
{
69-
name: "optionsField",
73+
name: "displayField",
7074
description: "Sets the property name that the select element uses to display each option. Supports dot notation for nested properties."
7175
},
76+
{
77+
name: "keyField",
78+
description: "Sets the property name that the select element uses to bind to ngModel. Leaving this blank uses the entire object. Supports dot notation for nested properties."
79+
},
7280
{
7381
name: "isDisabled",
7482
description: "Sets whether or not the select is disabled",
@@ -189,7 +197,7 @@ export class SelectPage {
189197
template: new SelectPage().exampleStandardTemplate
190198
})
191199
export class SelectExampleStandard {
192-
public selectedGender = "Female";
200+
193201
}
194202

195203
@Component({

0 commit comments

Comments
 (0)