Skip to content

Commit bf7fa14

Browse files
committed
feat(template): make virtual views not set a height by default
1 parent 1385c9a commit bf7fa14

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

apps/docs/docs/template/virtual-view-directive.mdx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,20 @@ This setup will:
8484
2. Render the content of rxVirtualViewContent when the element is visible.
8585
3. Show the rxVirtualViewPlaceholder when the element is not visible.
8686

87-
:::tip Define placeholder dimensions
87+
### Define placeholder dimensions
8888

8989
The placeholder is what makes or breaks your experience with `RxVirtualView`. In best case it's just
90-
an empty container which has just the same dimensions as its content it should replace.
90+
an empty container that has just the same dimensions as its content it should replace.
9191

9292
This will make sure you don't run into stuttery scrolling behavior and layout shifts.
9393

94-
:::
94+
You can use the `--rx-vw-h` and `--rx-vw-w` CSS variables to define the placeholder dimensions after the virtual view is rendered at least once.
95+
96+
```html
97+
<div style="min-height: var(--rx-vw-h, 100px); min-width: var(--rx-vw-w, 50px);"></div>
98+
```
99+
100+
If the virtual view is not rendered at least once, the 100px and 50px values will be used as fallback the first time, and after that, the values will be updated to the actual dimensions of the virtual view.
95101

96102
### Optimize lists with @for
97103

libs/template/virtual-view/src/lib/virtual-view.directive.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,11 @@ export class RxVirtualView
173173
readonly size = signal({ width: 0, height: 0 });
174174

175175
readonly width = computed(() =>
176-
this.size().width ? `${this.size().width}px` : 'auto',
176+
this.size().width ? `${this.size().width}px` : null,
177177
);
178178

179179
readonly height = computed(() =>
180-
this.size().height ? `${this.size().height}px` : 'auto',
180+
this.size().height ? `${this.size().height}px` : null,
181181
);
182182

183183
readonly containment = computed(() => {

0 commit comments

Comments
 (0)