Skip to content

Commit aaa1853

Browse files
committed
docs(list): update list documentation with the new "selected" property
1 parent b8eeba7 commit aaa1853

2 files changed

Lines changed: 24 additions & 26 deletions

File tree

en/components/list.md

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -549,46 +549,43 @@ 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` state property that helps us track which items have been 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, in which by using the `selected` property we apply a background color to the list items that we select:
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+
To make list items selectable, we simply need to add the `selected` property value to each list item we want to be able to select. By default, this property will be set to `false`. Then, we add a `(click)` event to each list item, which will toggle the `selected` property value between `true` and `false`, effectively switching the selection state each time the item is 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+
When a list item is selected, the class `.igx-list__item-base--selected` is added to the element. We can use this class to style the selected state of the element.
580+
586581
```scss
587-
.selected {
588-
background-color: hsla(var(--igx-secondary-500))
582+
.igx-list__item-base--selected .igx-list__item-content {
583+
background-color: var(--ig-secondary-500);
589584
}
590585
```
591586

587+
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)
588+
592589
<div class="divider--half"></div>
593590

594591
## 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)