最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Material-ui Tabs - how can I put scroll of them - Stack Overflow

programmeradmin3浏览0评论

I am using Material-ui Tablist for my in my AppBar ponent. 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 ponent's docs:

/

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

=/src/App.js

Is it possible to add something like a scroll under AppBar ponent or like a little arrows to left and right when there are other ponents 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.

I am using Material-ui Tablist for my in my AppBar ponent. 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 ponent's docs:

https://material-ui./ponents/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 ponent or like a little arrows to left and right when there are other ponents 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.

Share Improve this question edited Oct 27, 2023 at 3:20 Rajiv 3,7722 gold badges17 silver badges32 bronze badges asked Jan 4, 2021 at 6:56 Borislav StefanovBorislav Stefanov 7313 gold badges19 silver badges45 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 11

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./ponents/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

@Rajiv's answer doesn't work on mobile. Apply scrollButtons={true} and the allowScrollButtonsMobile prop to display the left and right scroll buttons on all viewports:

<Tabs
  value={value}
  onChange={handleChange}
  variant="scrollable"
  scrollButtons
  allowScrollButtonsMobile
  aria-label="scrollable force tabs example"
>
发布评论

评论列表(0)

  1. 暂无评论