Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dropdown): Adding disabled option #984 #1109

Merged
merged 1 commit into from
Apr 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions demos/app/drop-down/sample.component.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<button (click)="toggleDropDown()">Toggle</button>
<igx-drop-down [width]="width" (itemClicked)="itemClicked($event)" (onSelection)="onSelection($event)">
<igx-drop-down-item *ngFor="let item of items">
{{ item }}
<igx-drop-down (itemClicked)="itemClicked($event)">
<igx-drop-down-item *ngFor="let item of items" isDisabled={{item.disabled}}>
{{ item.field }}
</igx-drop-down-item>
<igx-drop-down-item isSelected="true">Selected</igx-drop-down-item>
</igx-drop-down>
12 changes: 8 additions & 4 deletions demos/app/drop-down/sample.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ export class DropDownSampleComponent {
@ViewChild(IgxDropDownComponent) public igxDropDown: IgxDropDownComponent;

itemsCount = 10;
items: any[] = [];
items: any[] = [
{ field: "Cables" },
{ field: "Switches", disabled: true },
{ field: "Batteries" }
];

constructor() {
for (let i = 0; i < this.itemsCount; i += 1) {
this.items.push("Item " + i);
}
//for (let i = 0; i < this.itemsCount; i += 1) {
// this.items.push("Item " + i);
//}
}

public toggleDropDown() {
Expand Down
25 changes: 23 additions & 2 deletions src/drop-down/dropDownItem.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import { IgxDropDownComponent, ISelectionEventArgs } from "./dropDown.component"
styles: [
":host { display: block; }",
":host.selected { background-color: #1A73E8; }",
":host.focused { border: 1px solid #8bb8f4; }"
":host.focused { border: 1px solid #8bb8f4; }",
":host.disabled { background-color: grey; }"
]
})
export class IgxDropDownItemComponent implements OnInit {
private _disabled = false;
get isSelected() {
return this.dropDown.selectedItem === this;
}
Expand All @@ -26,11 +28,28 @@ export class IgxDropDownItemComponent implements OnInit {
this.dropDown.onSelection.emit(args);
}

get isDisabled() {
return this._disabled;
}

@Input() set isDisabled(value: boolean) {
if (this._disabled === value) {
return;
}

this._disabled = value;
}

@HostBinding("class.selected")
get selectedStyle(): boolean {
return this.isSelected;
}

@HostBinding("class.disabled")
get disabledStyle(): boolean {
return this.isDisabled;
}

@HostBinding("class.focused")
public isFocused = false;

Expand All @@ -40,7 +59,9 @@ export class IgxDropDownItemComponent implements OnInit {
) { }

@HostListener("click", ["$event"]) clicked(event) {
this.dropDown.itemClicked.emit(this);
if (this.isDisabled) {
return;
}
const oldSelection = this.dropDown.selectedItem;
this.dropDown.selectedItem = this;
this.dropDown._initialSelectionChanged = true;
Expand Down