Skip to content

Commit 06eeaba

Browse files
authored
Merge pull request #3646 from IgniteUI/apetrov/add-select-state/list-sample
feat(list): add the new "selected" property to samples
2 parents 22b7fd5 + 36ae3e9 commit 06eeaba

3 files changed

Lines changed: 25 additions & 29 deletions

File tree

src/app/lists/list/list-item-selection/list-item-selection.component.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
<igx-list>
1515
<igx-list-item [isHeader]="true">Contacts</igx-list-item>
1616
@for (contact of contacts | igxFilter: filterContacts; track contact) {
17-
<igx-list-item [ngClass]="contact.selected ? 'selected' : ''" (click)="selectItem(contact)"
18-
>
17+
<igx-list-item [selected]="contact.selected" (click)="contact.selected = !contact.selected">
1918
<igx-avatar igxListThumbnail [src]="contact.photo" shape="circle"></igx-avatar>
2019
<span igxListLineTitle>{{ contact.name }}</span>
2120
<span igxListLineSubTitle>{{ contact.phone }}</span>
Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
11
:host {
2-
display: block;
3-
padding: 16px;
2+
display: block;
3+
padding: 16px;
44

5-
.selected {
6-
background-color: var(--ig-secondary-500)
7-
}
8-
9-
.list-sample {
10-
box-shadow: 0px 1px 3px 0px rgba(0, 0, 0, 0.2),
11-
0px 1px 1px 0px rgba(0, 0, 0, 0.14),
12-
0px 2px 1px -1px rgba(0, 0, 0, 0.12);
13-
}
5+
igx-list-item:hover {
6+
cursor: pointer;
7+
}
8+
}
149

15-
igx-icon {
16-
cursor: pointer;
17-
position: relative;
18-
}
10+
.list-sample {
11+
box-shadow: 0px 1px 3px 0px rgba(0, 0, 0, 0.2),
12+
0px 1px 1px 0px rgba(0, 0, 0, 0.14),
13+
0px 2px 1px -1px rgba(0, 0, 0, 0.12);
14+
}
1915

20-
.search {
21-
margin-bottom: 16px;
22-
}
16+
igx-icon {
17+
cursor: pointer;
18+
position: relative;
19+
}
2320

21+
.search {
22+
margin-bottom: 16px;
2423
}
24+
25+
igx-list-item {
26+
--item-background-selected: var(--ig-secondary-500);
27+
--item-title-color-selected: var(--ig-secondary-500-contrast);
28+
--item-subtitle-color-selected: var(--ig-info-100);
29+
}

src/app/lists/list/list-item-selection/list-item-selection.component.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { Component } from '@angular/core';
22
import { IgxFilterOptions, IgxInputGroupComponent, IgxPrefixDirective, IgxIconComponent, IgxInputDirective, IgxSuffixDirective, IgxListComponent, IgxListItemComponent, IgxAvatarComponent, IgxListThumbnailDirective, IgxListLineTitleDirective, IgxListLineSubTitleDirective, IgxListActionDirective, IgxRippleDirective, IgxFilterPipe } from 'igniteui-angular';
33
import { FormsModule } from '@angular/forms';
4-
import { NgClass } from '@angular/common';
54

65
@Component({
76
selector: 'app-list-item-selection',
87
templateUrl: './list-item-selection.component.html',
98
styleUrls: ['./list-item-selection.component.scss'],
10-
imports: [IgxInputGroupComponent, IgxPrefixDirective, IgxIconComponent, FormsModule, IgxInputDirective, IgxSuffixDirective, IgxListComponent, IgxListItemComponent, NgClass, IgxAvatarComponent, IgxListThumbnailDirective, IgxListLineTitleDirective, IgxListLineSubTitleDirective, IgxListActionDirective, IgxRippleDirective, IgxFilterPipe]
9+
imports: [IgxInputGroupComponent, IgxPrefixDirective, IgxIconComponent, FormsModule, IgxInputDirective, IgxSuffixDirective, IgxListComponent, IgxListItemComponent, IgxAvatarComponent, IgxListThumbnailDirective, IgxListLineTitleDirective, IgxListLineSubTitleDirective, IgxListActionDirective, IgxRippleDirective, IgxFilterPipe]
1110
})
1211
export class ListItemSelectionComponent {
1312
public searchContact: string;
@@ -55,13 +54,6 @@ export class ListItemSelectionComponent {
5554
contact.isFavorite = !contact.isFavorite;
5655
}
5756

58-
public selectItem(item) {
59-
if (!item.selected) {
60-
this.contacts.forEach(c => c.selected = false);
61-
item.selected = true;
62-
}
63-
}
64-
6557
get filterContacts() {
6658
const fo = new IgxFilterOptions();
6759
fo.key = 'name';

0 commit comments

Comments
 (0)