Skip to content

Blazor Virtualize: root-level scrolling breaks on horizontal scroll enabled in the container #58200

Closed

Description

@urbanambroz

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When placing the Virtualize into a horizontally scrollable container it breaks and only ever shows the top 1000 rows if we hide the container y axis scroller that appears on the component. By design the whole page should be scrollable and a second vertical scroller shouldn't be added but it is and it makes the page look weird. If we hide it then the Virtualize component breaks as described, leaving it on and having two scrollers appear on the page makes for bad UX though so that is not an option for us.

The horizontal scrolling is needed here because there are enough simulated columns that do not fit in one screen width and that is what is our use case that the customer wants to have in the application.

Expected Behavior

The Virtualize component shows new items on scrolling to the end of the visible list of items, only one scrollbar is shown on the whole page.

Steps To Reproduce

  1. create a new project in Blazor WASM dotnet new blazorwasm
  2. add the following page to the Pages folder
@page "/virtualized-table"

<PageTitle>Virtualized Table</PageTitle>

<HeadContent>
    <style>
        html, body {
            overflow-y: scroll
        }
    </style>
</HeadContent>

<h1>Virtualized Table Example</h1>

<button @onclick="LoadData">New data</button>

<div style="position: relative; overflow-x:auto; overflow-y: hidden;">
    <table id="virtualized-table"
           style="width: 100%; table-layout: auto; text-align: left; font-size: 0.75rem; line-height: 1.25rem;">
        <thead style="position: sticky; top: 0; background-color: silver">
            <tr>
                <th>Item</th>
                @for (var i = 0; i < 20; i++)
                {
                    <th style="text-wrap: nowrap">Another column</th>
                }
            </tr>
        </thead>
        <tbody style="@(isLoading ? "opacity: 0.75" : "")">
            <Virtualize Items="fixedItems" ItemSize="30" SpacerElement="tr">
                <tr @key="context" style="height: 30px;" id="row-@context">
                    <td>Item @context</td>
                    <td>Another value</td>
                </tr>
            </Virtualize>
        </tbody>
    </table>
</div>

@code {
    private List<Guid> fixedItems = new List<Guid>();
    private bool isLoading = false;

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        await base.OnAfterRenderAsync(firstRender);
        if (firstRender)
        {
            await LoadData();
        }
    }

    private async Task LoadData()
    {
        isLoading = true;

        await InvokeAsync(StateHasChanged);

        // simulate long fetch from server
        await Task.Delay(3000);
        var maxRange = Math.Min(new Random().Next(), 10000);
        fixedItems = Enumerable.Range(0, maxRange).Select(item => Guid.NewGuid()).ToList();
        isLoading = false;

        await InvokeAsync(StateHasChanged);
    }
}

Exceptions (if any)

No response

.NET Version

8.0.400

Anything else?

No response

Activity

  1. ghost added
    area-blazor
    on Oct 2, 2024
  2. added
    feature-blazor-virtualization
    on Oct 2, 2024
  3. mkArtakMSFT commented on Oct 2, 2024

    @mkArtakMSFT
    Contributor

    @SteveSandersonMS any thoughts on this?

  4. added this to the Backlog milestone on Oct 9, 2024
  5. mrpmorris commented on Mar 5, 2025

    @mrpmorris

    Is this why I can scroll vertically with my touchpad, but only up to the point I use it to scroll horizontally?

    After I've used it to scroll horizontally then even vertical scrolling touchpad movement causes horizontal scrolling.

  6. dariatiurina commented on Nov 21, 2025

    @dariatiurina
    Contributor

    Thank you for reporting this issue!

    The problems you observed in your sample were caused by CSS settings and missing constraints that affect Virtualize component’s scroll detection and layout. Here’s what we recommend:

    • Set a fixed height on the scroll container so Virtualize knows where to scroll and how calculate the container height.

    • Setting overflow-y: hidden on the container prevents Virtualize from detecting scroll events entirely. The component relies on scroll events to know when to load more items, so hiding the vertical scrollbar causes it to only render the initial batch and never load additional rows.

    • Remove forced scrollbars on html and body to avoid double scrollbars, because using overflow-y: scroll forces scrollbars even when content doesn’t overflow.

    • Keep only one vertical scrollable area and handle horizontal overflow with overflow-x: auto. This prevents layout inconsistencies and improves UX.

    • If you want the whole page to scroll, remove custom overflow styles so html acts as the scroll container. This ensures Virtualize can detect scroll events properly.

    • Remove hardcoded row height because Virtualize calculates it automatically. You already have used ItemSize in the Virtualize component to help it approximate height in the first iteration of calculations.

    The proposed upgraded version of the sample you provided:

    @page "/virtualized-table"
    
    <PageTitle>Virtualized Table</PageTitle>
    
    <h1>Virtualized Table Example</h1>
    
    <button @onclick="LoadData">New data</button>
    
    <div style="height: 400px; width: 600px; overflow: auto; position: relative;">
        <table id="virtualized-table">
            <thead style="position: sticky; top: 0; background-color: white; z-index: 1;">
                <tr>
                    <th>Item</th>
                    @for (var i = 0; i < 20; i++)
                    {
                        <th style="text-wrap: nowrap">Another column</th>
                    }
                </tr>
            </thead>
            <tbody style="@(isLoading ? "opacity: 0.75" : "")">
                <Virtualize Items="fixedItems" ItemSize="30" SpacerElement="tr">
                    <tr @key="context" id="row-@context">
                        <td>Item @context</td>
                        <td>Another value</td>
                    </tr>
                </Virtualize>
            </tbody>
        </table>
    </div>
    
    @code {
        private List<Guid> fixedItems = new List<Guid>();
        private bool isLoading = false;
    
        protected override async Task OnAfterRenderAsync(bool firstRender)
        {
            if (firstRender)
            {
                await LoadData();
            }
        }
    
        private async Task LoadData()
        {
            isLoading = true;
            await InvokeAsync(StateHasChanged);
    
            await Task.Delay(3000);
            var maxRange = Math.Min(new Random().Next(), 10000);
            fixedItems = Enumerable.Range(0, maxRange).Select(item => Guid.NewGuid()).ToList();
            
            isLoading = false;
            await InvokeAsync(StateHasChanged);
        }
    }
  7. self-assigned this
    on Mar 11, 2026
  8. added a commit that references this issue on Mar 12, 2026
    1955c88
  9. added a commit that references this issue on Mar 16, 2026
    d77c401
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-blazorfeature-blazor-virtualizationinvestigate

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions