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

Scroll in Tabs #2270

Closed
vijaystroup opened this issue Jan 2, 2024 · 21 comments
Closed

Scroll in Tabs #2270

vijaystroup opened this issue Jan 2, 2024 · 21 comments
Labels
stale? Is this issue stale? Stale

Comments

@vijaystroup
Copy link

vijaystroup commented Jan 2, 2024

https://ui.shadcn.com/docs/components/scroll-area
https://ui.shadcn.com/docs/components/tabs

Looking to implement a elegant horizontal scroll in a Tabs component so I tried using a Scroll component around the Tabs Trigger components.

Outcome was not as expected:
image

Code:

<Tabs defaultValue='account'>
  <div className='flex justify-center p-5'>
    <TabsList className=''>
      <ScrollArea orientation='horizontal'>
        <TabsTrigger value='account'>Account</TabsTrigger>
        <TabsTrigger value='password'>Password</TabsTrigger>
      </ScrollArea>
    </TabsList>
  </div>
  <TabsContent value='account'>
    Make changes to your account here.
  </TabsContent>
  <TabsContent value='password'>
    Change your password here.
  </TabsContent>
</Tabs>

Without <Scroll/> performs normally:
image

Overflow of <TabsTrigger /> without <Scroll />:
image

Interested in a solution like this in the event more items get added to TabsList that overflow the parent container.

@sandercoffee
Copy link

Would it be because you are using "justify-center" in the parent div?

@vijaystroup
Copy link
Author

vijaystroup commented Jan 3, 2024

Would it be because you are using "justify-center" in the parent div?

Removing the wrapper produced the same overflow error as the screen shot; just starting at justify-start instead of justify-center.
However, removing the parent div and introducing the <ScrollArea /> component again, there seems to be some type of wrapping going on:
image

Couldn't get a fix with overflow scroll and display flex with no wrap though..

@harsh-1923
Copy link

The orientation="horizontal" should be a part of <ScrollBar /> I guess.

Consider this structure once:

<Tabs> <ScrollArea> <TabList /> // {either map or individually} <ScrollBar orientation="horizontal" /> </ScrollArea> <TabsContent> </TabsContent? </Tabs>

@vijaystroup
Copy link
Author

Produced the same result as wrapping above.

@vijaystroup
Copy link
Author

@vijaystroup not sure why is @harsh-1923's solution working for you but here is a sandbox for your reference: LINK

That is odd. I am trying to reproduce with your code exactly within the ScrollArea but it is still overflowing without any scroll.
I think it may be the div wrapper I have to center and pad the tab menu.

@HMoen
Copy link

HMoen commented Jan 19, 2024

@vijaystroup , did you find a solution?

@vijaystroup
Copy link
Author

@vijaystroup , did you find a solution?

No unfortunately. Currently it is not a hindrance to my application, but it may be in the future, that is why I opened this issue now.

@shadcn
Copy link
Collaborator

shadcn commented Feb 26, 2024

This issue has been automatically closed because it received no activity for a while. If you think it was closed by accident, please leave a comment. Thank you.

@shadcn shadcn closed this as completed Feb 26, 2024
@mineraux
Copy link

Please reopen it

@BertVanHecke
Copy link

Reopen. Issue is not resolved.

@randysmachado
Copy link

Reopen, I'm needed this

@vijaystroup
Copy link
Author

vijaystroup commented Mar 22, 2024

Not solved yet.
@shadcn

@sotirelisc
Copy link

Please, reopen!

@marwanbukhori
Copy link

parking, look forward for this

@SweydManaf
Copy link

The orientation="horizontal" should be a part of <ScrollBar /> I guess.

Consider this structure once:

<Tabs> <ScrollArea> <TabList /> // {either map or individually} <ScrollBar orientation="horizontal" /> </ScrollArea> <TabsContent> </TabsContent? </Tabs>

work for me ❤️

@mrvfino
Copy link

mrvfino commented Apr 9, 2024

Looking for this feature as well.

Here's a workaround I did for now:

   <div className="relative rounded-sm overflow-x-scroll h-10 bg-muted">
      <TabsList className="absolute flex flex-row justify-stretch w-full">
        {tabs.map((value, index) => (
          <TabsTrigger
            className="w-full"
            key={`tab_trigger_${index}`}
            value={value}
          >
            {value}
          </TabsTrigger>
        ))}
      </TabsList>
    </div>

Not ideal, but I used "bg-muted" on the outer div to give an illusion of a continuous bg for the tab list

@4doist
Copy link

4doist commented Apr 20, 2024

Reopen pls

@gianicolajara
Copy link

      <ScrollArea>
        <div className="w-full relative h-10">
          <TabsList className="flex absolute h-10">
            {tabsHeadList.map(({ id, value, label }) => (
              <TabsTrigger key={id} value={value}>
                {label}
              </TabsTrigger>
            ))}
          </TabsList>
        </div>
        <ScrollBar orientation="horizontal" />
      </ScrollArea>

@burxtx
Copy link

burxtx commented Apr 23, 2024

How to add tailwindcss scroll snap align?

@abubakerx1da49
Copy link

I get somewhat workable code as:

<TabsList className='flex items-center justify-start flex-wrap h-auto space-y-1'> </TabsList>

@timreach
Copy link

timreach commented Jul 3, 2024

      <ScrollArea>
        <div className="w-full relative h-10">
          <TabsList className="flex absolute h-10">
            {tabsHeadList.map(({ id, value, label }) => (
              <TabsTrigger key={id} value={value}>
                {label}
              </TabsTrigger>
            ))}
          </TabsList>
        </div>
        <ScrollBar orientation="horizontal" />
      </ScrollArea>

Thank yo so much @gianicolajara - this is great and solves the issue.

I set the scroll area component to render a div as per this discussion and then added pb-2 to make the bar render beneath the tabs instead of quatting the bottom padding of the TabTriggers. Is there a way to detect if the tabs have overflown or not so I can conditionally apply that pb?

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

No branches or pull requests