Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ScrollArea] Consider dropping the inner div and the overflow style #1205

Open
vladmoroz opened this issue Dec 20, 2024 · 1 comment
Open

Comments

@vladmoroz
Copy link
Contributor

<ScrollArea.Viewport>
  {children}
</ScrollArea.Viewport>

currently renders:

<div style={{ overflow: 'scroll' }}>
  <div style={{ minWidth: 'fit-content' }}>
    {children}
  </div>
</div>

I've already run into slight hiccups with both when styling the components for the docs and had to use the render prop to remove the offending pieces. I think it's worth a thought to render a single div without any styles.

Overflow scroll:

  • Assumes you want overflow on both axes
  • Assumes you want overflow unconditionally (and not conditionally on/off like in the docs demo code block)

Extra div:

  • Generally useful in most cases and/or not affecting the layout when it doesn't matter, but since scroll container styling can get gnarly and this inner div isn't accessible directly, I'd prefer to add this as a suggestion in the docs and as Base UI user have total control over my layout instead. As a really simplistic example, setting className="flex flex-col gap-2" on the viewport isn't going to add a gap between the items.
@atomiks
Copy link
Contributor

atomiks commented Dec 21, 2024

So essentially the docs will just have the child div, or should this just be a new (semi-optional) part?:

<ScrollArea.Viewport>
  <div style={{ minWidth: 'fit-content' }}>
    your content
  </div>
</ScrollArea.Viewport>

And the overflow: scroll style is where the @layer idea you suggested in #1110 would come in handy.


Workarounds

At least both these have a workaround currently:

  1. Get rid of the inner div using render:
<ScrollArea.Viewport
  render={(props) => <div {...props}>{props.children.props.children}</div>}
/>
  1. Specify style with overflow: undefined:
<ScrollArea.Viewport style={{ overflow: undefined }} />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants