components icon indicating copy to clipboard operation
components copied to clipboard

bug(VirtualScroll): Horizontal scrolling inside cdk-virtual-scroll-viewport

Open Spinnenzunge opened this issue 3 years ago • 4 comments

Is this a regression?

  • [ ] Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

Content inside the cdk-virtual-scroll-viewport does use more than 100% width and does not break anymore and instead adds horizontal scrolling.

This is especially a problem when using following css rules:

white-space: nowrap;
overflow: hidden;

The problem is the created wrapper container with the cdk-virtual-scroll-content-wrapper class that has a min-width: 100% set but no max-width and can not be changed because of the view encapsulation.

Reproduction

https://github.com/DaniLopes2003/VirtualScroll-DemoApp

Expected Behavior

No horizontal scroll bar added or width, max-width and min-width customizable with css variables?

Actual Behavior

Horizontal bar added because no min-width is set

Environment

  • Angular: 13.0.3
  • CDK/Material: 13.1.3
  • Browser(s): Chrome, Safari
  • Operating System (e.g. Windows, macOS, Ubuntu): macOS

Spinnenzunge avatar Jan 26 '22 14:01 Spinnenzunge

@mmalerba Could you take a look

wagnermaciel avatar Jan 28 '22 20:01 wagnermaciel

I'm also having this problem so am keen on a fix too, thanks all

saladfingerss avatar Jul 01 '22 06:07 saladfingerss

In my environment, this css fixed this issue:

cdk-virtual-scroll-viewport {
  height: 100%;
  width: 100%;

  .cdk-virtual-scroll-content-wrapper {
    max-width: 100% !important;
  }
}

rdlabo avatar Aug 30 '22 05:08 rdlabo

This worked for me, thanks @rdlabo

saladfingerss avatar Sep 06 '22 16:09 saladfingerss

Can confirm this fix works, and that this is still an issue in Angular CDK 15. While the fix is simple finding the issue is not. If this is intended functionality it could at the very least be mentioned in the docs, along with this option if a fixed 100% width is desired.

andersonjohnf avatar Dec 06 '22 04:12 andersonjohnf

Workaround does not work as is for me because of the encapsulation (as mentioned in the issue description). I would have to use ng-deep.

cdk-virtual-scroll-viewport {
    height: 100%;
    width: 100%;

    ::ng-deep .cdk-virtual-scroll-content-wrapper {
        max-width: 100% !important;
    }
}

Which I'd prefer not to since it is not recommended.

mchlroy avatar Apr 13 '23 16:04 mchlroy

Any update on this?

pozsegam avatar Aug 15 '23 08:08 pozsegam

Also asking for an update, still an issue in Angular CDK 16.

artemisclyde avatar Oct 12 '23 15:10 artemisclyde

Workaround does not work as is for me because of the encapsulation (as mentioned in the issue description). I would have to use ng-deep.

cdk-virtual-scroll-viewport {
    height: 100%;
    width: 100%;

    ::ng-deep .cdk-virtual-scroll-content-wrapper {
        max-width: 100% !important;
    }
}

Which I'd prefer not to since it is not recommended.

I put the code suggested by @rdlabo into my main style file: src/styles.scss which means you don't need the ng::deep stuff that is needed if you put it in a component style file.

Can't comment on an actual fix in the main package though.

saladfingerss avatar Oct 13 '23 08:10 saladfingerss