Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Material-ui Tabs - how can I put scroll of them

I am using Material-ui Tablist for my in my AppBar component. The problem is that I have too many Tabs and I want to make them responsive - when I have smaller screen some of them are just not visible.

The component's docs:

https://material-ui.com/components/tabs/

You can see when I have so many tabs how it hides the lasts:

https://codesandbox.io/s/nervous-hoover-809s0?file=/src/App.js

Is it possible to add something like a scroll under AppBar component or like a little arrows to left and right when there are other components that are invisible?

Probably scroll or arrows should be added in this section:

 <AppBar position="static">
            <TabList onChange={handleChange} aria-label="simple tabs example">
              <Tab label="Business Info" value="1" icon={<ContactMailIcon />} />
              <Tab label="Financial" value="2" icon={<MonetizationOnIcon />} />
              <Tab
                label="Participants"
                value="3"
                icon={<AccessibilityIcon />}
              />
              <Tab label="Statistics" value="4" icon={<EqualizerIcon />} />
              <Tab label="Alerts" value="5" icon={<ReportProblemIcon />} />
              <Tab label="Health Care" value="6" icon={<FavoriteIcon />} />
              <Tab label="Plans" value="7" icon={<ListAltIcon />} />
              <Tab
                label="Benchmark"
                value="8"
                icon={<ListAltIcon />}
              />
              <Tab
                label="Heatmap"
                value="9"
                icon={<ListAltIcon />}
              />
              <Tab
                label="Diagnostic"
                value="10"
                icon={<ListAltIcon />}
              />
            </TabList>
          </AppBar>

But you will have better point of view in codesandbox example.

like image 237
Borislav Stefanov Avatar asked Oct 16 '25 02:10

Borislav Stefanov


1 Answers

TabList accepts a prop variant="scrollable" which sets the scrollable property and also provide a little arrows indicator on sides.

Here is the demo of scrollable tabs:- https://material-ui.com/components/tabs/#automatic-scroll-buttons

<TabList variant="scrollable" onChange={handleChange} aria-label="simple tabs example">
  <Tab label="Business Info" value="1" icon={<ContactMailIcon />} />
  <Tab label="Financial" value="2" icon={<MonetizationOnIcon />} />
  <Tab label="Participants" value="3" icon={<AccessibilityIcon />} />
  <Tab label="Statistics" value="4" icon={<EqualizerIcon />} />
  <Tab label="Alerts" value="5" icon={<ReportProblemIcon />} />
  <Tab label="Health Care" value="6" icon={<FavoriteIcon />} />
  <Tab label="Plans" value="7" icon={<ListAltIcon />} />
  <Tab label="Benchmark" value="8" icon={<ListAltIcon />} />
  <Tab label="Heatmap" value="9" icon={<ListAltIcon />} />
  <Tab label="Diagnostic" value="10" icon={<ListAltIcon />} />
</TabList>

Here is the working codesandbox link:- https://codesandbox.io/s/affectionate-firefly-z61em?file=/src/App.js

like image 174
Rajiv Avatar answered Oct 17 '25 15:10

Rajiv



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!