Skip to content

Commit 4546c08

Browse files
committed
docs: add scroll example
1 parent 306546e commit 4546c08

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { render, screen, waitForElementToBeRemoved } from '@testing-library/angular';
2+
3+
import { CdkVirtualScrollOverviewExample } from './13-scrolling.component';
4+
import { ScrollingModule } from '@angular/cdk/scrolling';
5+
6+
test('should scroll to load more items', async () => {
7+
await render(CdkVirtualScrollOverviewExample, {
8+
imports: [ScrollingModule],
9+
});
10+
11+
const item0 = await screen.findByText(/Item #0/i);
12+
expect(item0).toBeVisible();
13+
14+
screen.getByTestId('scroll-viewport').scrollTop = 500;
15+
await waitForElementToBeRemoved(() => screen.getByText(/Item #0/i));
16+
17+
const item12 = await screen.findByText(/Item #12/i);
18+
expect(item12).toBeVisible();
19+
});
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { ChangeDetectionStrategy, Component } from '@angular/core';
2+
3+
@Component({
4+
selector: 'cdk-virtual-scroll-overview-example',
5+
template: `
6+
<cdk-virtual-scroll-viewport itemSize="50" class="example-viewport" data-testid="scroll-viewport">
7+
<div *cdkVirtualFor="let item of items" class="example-item">{{ item }}</div>
8+
</cdk-virtual-scroll-viewport>
9+
`,
10+
styles: [
11+
`
12+
.example-viewport {
13+
height: 200px;
14+
width: 200px;
15+
border: 1px solid black;
16+
}
17+
18+
.example-item {
19+
height: 50px;
20+
}
21+
`,
22+
],
23+
changeDetection: ChangeDetectionStrategy.OnPush,
24+
})
25+
export class CdkVirtualScrollOverviewExample {
26+
items = Array.from({ length: 100 }).map((_, i) => `Item #${i}`);
27+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,4 @@
6868
"ts-node": "~8.10.2",
6969
"typescript": "~3.9.5"
7070
}
71-
}
71+
}

0 commit comments

Comments
 (0)