Skip to content

Commit 1203f28

Browse files
authored
Merge pull request #6093 from IgniteUI/apetrov/add-list-select-vnext
docs(list): update list documentation with the new "selected" property (vnext)
2 parents 6c3548c + a6097dd commit 1203f28

2 files changed

Lines changed: 33 additions & 26 deletions

File tree

en/components/list.md

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -549,46 +549,52 @@ Finally, we need to apply the filtering pipe to our contacts data before we can
549549

550550
## List Item Selection
551551

552-
As you probably have already noticed, list items do not provide selection states. However, if your application requires your list to keep track of which item is selected, we give you an example of how this can be achieved. All you need to do is keep track of the state somewhere in your component, or in the data the list is bound to.
552+
The list items have a `selected` property that helps us track which items are "selected". This property allows us to identify and manage the selection status of each item.
553553

554-
Here's an example, in which we apply a background color to the list according to the theme's secondary 500 color, based on state tracking coming from the data the list is bound to:
554+
Here's an example illustrating how the visual style of the items changes when using the `selected` property:
555555

556556
<code-view style="height: 420px"
557557
data-demos-base-url="{environment:demosBaseUrl}"
558558
iframe-src="{environment:demosBaseUrl}/lists/list-item-selection" >
559559
</code-view>
560560

561-
What we are doing is we are adding an additional `selected` property to each data member, which defaults to `false`. Upon list item click, we're resetting all the `selected` properties in the data collection and setting the one corresponding to the clicked item to `true`. Based on the selected property, we're applying a css class to the list item which gives it the selected background.
561+
By default, the `selected` property is set to `false`. We can toggle its value using an inline expression bound to the `(click)` event on each list item, effectively switching the visual state of the item each time it's clicked.
562562

563563
```html
564564
<igx-list>
565-
<igx-list-item isHeader="true">Contacts</igx-list-item>
566-
<igx-list-item [ngClass]="contact.selected ? 'selected' : ''"
567-
(click)="selectItem(contact)"
568-
*ngFor="let contact of contacts | igxFilter: filterContacts;">
565+
<igx-list-item [isHeader]="true">Contacts</igx-list-item>
566+
@for (contact of contacts | igxFilter: filterContacts; track contact) {
567+
<igx-list-item [selected]="contact.selected" (click)="contact.selected = !contact.selected">
569568
<igx-avatar igxListThumbnail [src]="contact.photo" shape="circle"></igx-avatar>
570569
<span igxListLineTitle>{{ contact.name }}</span>
571570
<span igxListLineSubTitle>{{ contact.phone }}</span>
572-
<igx-icon igxListAction [style.color]="contact.isFavorite ? 'orange' : 'lightgray'" (click)="toggleFavorite(contact, $event)">star</igx-icon>
573-
</igx-list-item>
574-
</igx-list>
575-
```
576-
577-
```typescript
578-
public selectItem(item) {
579-
if (!item.selected) {
580-
this.contacts.forEach(c => c.selected = false);
581-
item.selected = true;
571+
<igx-icon igxListAction [style.color]="contact.isFavorite ? 'orange' : 'lightgray'" igxRipple="pink"
572+
[igxRippleCentered]="true" (click)="toggleFavorite(contact, $event)"
573+
(mousedown)="mousedown($event)">star</igx-icon>
574+
</igx-list-item>
582575
}
583-
}
576+
</igx-list>
584577
```
585578

579+
The list item also exposes a few CSS variables which you can use to style different parts of the selected elements:
580+
581+
- `--item-background-selected`
582+
- `--item-text-color-selected`
583+
- `--item-title-color-selected`
584+
- `--item-action-color-selected`
585+
- `--item-subtitle-color-selected`
586+
- `--item-thumbnail-color-selected`
587+
586588
```scss
587-
.selected {
588-
background-color: hsla(var(--igx-secondary-500))
589+
igx-list-item {
590+
--item-background-selected: var(--ig-secondary-500);
591+
--item-title-color-selected: var(--ig-secondary-500-contrast);
592+
--item-subtitle-color-selected: var(--ig-info-100);
589593
}
590594
```
591595

596+
If you prefer to use the list theming function, there are parameters available that allow you to style the selected state of the list items. You can find more information about these parameters here: [`list-theme`]({environment:sassApiUrl}/index.html#function-list-theme)
597+
592598
<div class="divider--half"></div>
593599

594600
## Chat Component

en/components/themes/palettes.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ Apart from having a single global palette, you can also create several palettes
107107
/* styles.css */
108108

109109
.blue-theme {
110-
--ig-primary-500: #0008ff;
110+
--ig-primary-500: #0008ff;
111111
}
112112

113113
.red-theme {
114-
--ig-primary-500: #ff0400;
114+
--ig-primary-500: #ff0400;
115115
}
116116
```
117117

@@ -172,12 +172,13 @@ Be mindful when changing the `gray` and `surface` color variants as they are use
172172

173173
So far we've covered the `primary`, `secondary`, `gray`, and `surface` color variants and how you can override them. There are four more colors - `info`, `success`, `warn`, and `error`. They are usually used to set the colors in different states. For example, the `igx-input-group` component uses these colors in its input validation states.
174174
They can be changed as the other color variants, all we need to do it to set the `500` variant and all of the other varints will be generated.
175+
175176
```css
176177
:root {
177-
--ig-info-500: #1377d5;
178-
--ig-success-500: #4eb862;
179-
--ig-warn-500: #faa419;
180-
--ig-error-500: #ff134a;
178+
--ig-info-500: #1377d5;
179+
--ig-success-500: #4eb862;
180+
--ig-warn-500: #faa419;
181+
--ig-error-500: #ff134a;
181182
}
182183
```
183184

0 commit comments

Comments
 (0)