[Tabs] Support "auto" as "scrollable" value
See original GitHub issueWhen using <Tabs scrollable>
with few tabs, the first tab seems not properly aligned to the left. I need the ability to auto-set the scrollable
behavior based on the screen width and the number of tabs.
- This is a v1.x issue.
- I have searched the issues of this repository and believe that this is not a duplicate.
Expected Behavior
I would like tabs that are scrollable when there isn’t enough width, but not scrollable otherwise. The scrollable
prop should be automatically enabled based on whether the screen is large enough to display all the tabs or not. Therefore, setting scrollable
to true
or false
doesn’t work - I’d need an auto
value.
I know I can use withWidth
to do that in userland, but it’s just such a common need that I believe it should be implemented in core.
Current Behavior
scrollable
can only be set to true
or false
, so the tabs always look bad:
- if I have
scrollable
but a very large screen, the first tab isn’t properly aligned - if I have
scrollable=false
but a narrow screen, I can’t get to the last tab
Context
I’m developing a component that can contain an arbitrary number of tabs - from a few to many. In the latter case, the scrollable
option is a must. But when enabled in the first case, the first tab isn’t properly aligned on the left:
Issue Analytics
- State:
- Created 5 years ago
- Reactions:6
- Comments:10 (5 by maintainers)
Top GitHub Comments
IMO this is still an issue from a UX perspective, since without any affordance indicating the tabs are scrollable, users have no reliable way to know there are more tabs off screen. On the other hand, the additional space mentioned by the OP required with scroll=“auto” makes desktop UIs look broken. Could this issue be reopened so it can be revisited?
In the meantime, here’s a hacky workaround I came up with to hide/show the scroll buttons when the tab width exceeds that of the container (on window resize and when adding tabs): https://codesandbox.io/s/q34yxjkmwj
Maybe this could be added to the Tabs impl, controlled by a prop like scrollHide=“auto|on|off”, for ex?
IMO It’s not ideal on desktop screens to hide buttons, but I can live with that. Thanks for your answer.