primitives icon indicating copy to clipboard operation
primitives copied to clipboard

Allow disabling the `display: table` CSS on `SrollArea`

Open hspak opened this issue 1 year ago • 6 comments

Feature request

Overview

I noticed that the ScrollArea component sets this display: table style as a strategy to recalculate thumb sizes: https://github.com/radix-ui/primitives/blob/55f9189a4b3e1a525c89297d5f337c03b2a44f61/packages/react/scroll-area/src/ScrollArea.tsx#L178-L187)

Examples in other libraries

N/A

Who does this impact? Who is this for?

There's a side navigation that I'm trying to use the ScrollArea component for that we allow for dynamic re-sizing and this table display is not respecting the width value from the parent.

Manually removing the CSS style from the browser solves the issue.

Additional context

N/A

hspak avatar Jun 20 '24 18:06 hspak

Same issue here,

In the mean time I resorted to something like this:

useEffect(() => {
  const elem: HTMLElement | null = document.querySelector(
    ".my-scroll-area > div > div"
  );
  if (elem) elem.style.display = "block";
}, []);

this works, but it's also horrible. We really need a fix for disabling display:table

matiasvlevi avatar Jun 28 '24 20:06 matiasvlevi

Same issue

f-z-coder avatar Jul 11 '24 10:07 f-z-coder

Bumping this, experiencing the same issue. Because of the display: table and min-width: 100%, the content overflows but you can't see it because of overflow: hidden and as a result, the content looks not centered (since overflow is hidden; it actually is centered). Ideal case would be allowing to override this.

aishwaryaborkar avatar Aug 06 '24 23:08 aishwaryaborkar

idk but when i check source code, this code has been changed in https://github.com/radix-ui/primitives/commit/f6d70b3050929effc910971ddd3a5259c9de17ff

did its means have been resolved?

moonrailgun avatar Aug 17 '24 19:08 moonrailgun

Yes

idk but when i check source code, this code has been changed in f6d70b3

did its means have been resolved?

Yes now it resolved in version 1.2 but currently this version is in Rc mode

f-z-coder avatar Aug 18 '24 08:08 f-z-coder

yeah, look forward 1.2.0 release.

i am watching it.

image

moonrailgun avatar Aug 18 '24 13:08 moonrailgun

This appears fixed on 1.2.0 and it's been released! 🎉

hspak avatar Oct 17 '24 04:10 hspak

Should re-open: https://github.com/radix-ui/primitives/pull/3225 the fix was reverted.

omridevk avatar Mar 29 '25 15:03 omridevk

Should re-open: #3225 the fix was reverted.

Please, please add a prop to use anything but display: table on the nested div... It's so painful to work with...

I even tried using asChild with a flex container as the immediate child of ScrollArea.Viewport, but it messed up scrolling

jkhaui avatar Jun 18 '25 00:06 jkhaui

yes, please! this breaks layout and its impossible to work with in certain scenarios as children stretch the table div (max-width is not respected as we enter table formatting context and intrinsic table width wins). for example, if you need items in a vertical scrollarea with text ellispsis and set white-space: nowrap; text-overflow: ellipsis; overflow: hidden; on the item, the items are stretched and cut off.

tgds avatar Aug 05 '25 12:08 tgds

bump

hubertoschusch avatar Aug 14 '25 09:08 hubertoschusch

i added an id to the Viewport

<ScrollArea.Viewport id="my-scroll-area-viewport" >

and then in my global css file:

#my-scroll-area-viewport > div {
  display: block !important;
}

and it works

michaelito80us avatar Aug 20 '25 17:08 michaelito80us

If you are using shadcn, adding this tailwind class [&>div]:!block to your <ScrollAreaPrimitive.Viewport/> component will do the trick.

lucasmcht avatar Aug 25 '25 18:08 lucasmcht

Bump, the issue is real. I had to spent 2 days just after this. Never knew this was from ScrollArea until I inspected the parent elements one by one. Using one of the hacks to fix now, but this should be solved in a better way.

FarhanShares avatar Aug 30 '25 05:08 FarhanShares