Skip to content

Commit 156153a

Browse files
committed
chore(angular): simplify e2e row iteration in measure element
1 parent d101293 commit 156153a

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

packages/angular-virtual/e2e/app/src/app/measure-element.component.ts

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,37 +30,38 @@ const initialItems: Array<Item> = [
3030
style="position: relative; width: 100%;"
3131
[style.height.px]="virtualizer.getTotalSize()"
3232
>
33-
@for (row of virtualizer.getVirtualItems(); track itemKey(row.index)) {
33+
@for (row of virtualizer.getVirtualItems(); track row.key) {
34+
@let item = this.items()[row.index]!;
3435
<div
3536
#virtualItem
36-
[attr.data-testid]="itemKey(row.index)"
37+
[attr.data-testid]="item.id"
3738
[attr.data-index]="row.index"
3839
style="position: absolute; top: 0; left: 0; width: 100%;"
3940
[style.transform]="'translateY(' + row.start + 'px)'"
4041
>
4142
<div style="display: flex; gap: 8px; align-items: center; padding: 4px;">
42-
<span>Row {{ itemFor(row.index).label }}</span>
43+
<span>Row {{ item.label }}</span>
4344
<button
44-
[attr.data-testid]="'expand-' + itemKey(row.index)"
45+
[attr.data-testid]="'expand-' + item.id"
4546
type="button"
46-
(click)="toggleExpand(itemKey(row.index))"
47+
(click)="toggleExpand(item.id)"
4748
>
48-
{{ expandedId() === itemKey(row.index) ? 'Collapse' : 'Expand' }}
49+
{{ expandedId() === item.id ? 'Collapse' : 'Expand' }}
4950
</button>
5051
<button
51-
[attr.data-testid]="'delete-' + itemKey(row.index)"
52+
[attr.data-testid]="'delete-' + item.id"
5253
type="button"
53-
(click)="deleteItem(itemKey(row.index))"
54+
(click)="deleteItem(item.id)"
5455
>
5556
Delete
5657
</button>
5758
</div>
58-
@if (expandedId() === itemKey(row.index)) {
59+
@if (expandedId() === item.id) {
5960
<div
60-
[attr.data-testid]="'content-' + itemKey(row.index)"
61+
[attr.data-testid]="'content-' + item.id"
6162
style="height: 124px; background: #eee; padding: 8px;"
6263
>
63-
Expanded content for {{ itemFor(row.index).label }}
64+
Expanded content for {{ item.label }}
6465
</div>
6566
}
6667
</div>
@@ -94,14 +95,6 @@ export class MeasureElementComponent {
9495
getItemKey: (index) => this.items()[index]!.id,
9596
}))
9697

97-
itemFor(index: number) {
98-
return this.items()[index]!
99-
}
100-
101-
itemKey(index: number) {
102-
return this.items()[index]!.id
103-
}
104-
10598
toggleExpand(id: string) {
10699
this.expandedId.update((current) => (current === id ? null : id))
107100
}

0 commit comments

Comments
 (0)