How do I incorporate scrolling into Material-UI Tabs?

I am currently incorporating Material-ui Tablist into my AppBar component. However, I am facing an issue with the responsiveness of the tabs. When there are too many tabs, some of them become hidden on smaller screens.

For more information on the component, you can refer to the documentation:

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

You can visually see the problem in action here:

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

I am wondering if it is possible to implement a scrolling feature under the AppBar component or perhaps include navigation arrows when tabs exceed the visible area?

Potentially, the scroll or arrow functionality could be integrated within this part of the code snippet:

<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>

To get a clearer understanding, please check out the codesandbox example provided above.

Answer №1

TabList has a special prop called variant="scrollable" which enables the scrollable feature and adds arrow indicators on the sides.

If you want to see a demo of scrollable tabs, check out this link: 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>

If you'd like to see it in action, here's the codesandbox link: https://codesandbox.io/s/affectionate-firefly-z61em?file=/src/App.js

Answer №2

@Rajiv's solution is not compatible with mobile devices. To fix this issue, add the scrollButtons={true} and allowScrollButtonsMobile properties to your code in order to display left and right scroll buttons on all screen sizes:

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

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Transforming text colors dynamically using Vue.js

Here is an Angular code snippet: <div [style.color]="'#' + prod.id.substring(0,6)"> <small>{{ prod.id }}</small> </div> Now I want to create a similar code using vue.js. ...

jquery events fail to trigger following the dynamic loading of new content

I have developed a voting system that utilizes images. When a user clicks on an image, it submits the vote and fades out before reloading using a PHP page. The issue I'm facing is that after the first submit, clicking on the images does not trigger an ...

Tips For Making Your Bootstrap 4 Page Fit Perfectly on Mobile Screens

Currently in the process of developing . The frontpage has been created and tested using Chrome's dev console's device toolbar. Ensured that the correct viewport is set and utilized Bootstrap's column system for stacking elements. However, ...

Ways to extract the ASP.net variable value and place it inside a JavaScript textbox

Currently, I'm in the process of developing Javascript code for an ASP.net page. Within my coding framework, the string "foo" is linked to a string variable called myString. In order to transfer the value of myString to a JavaScript variable, I incl ...

Using JQuery to switch out images that do not have an ID or class assigned

Currently, I am using a Google Chrome Extension to apply an external theme to a website. Unfortunately, the logo on the site does not have an ID or class that can be used to call it. I am searching for a solution to replace it with a different image. My ...

Personalized Owl Carousel - OWL.JS Hover Pause Feature

I have been working on a slider in Codepen that is functioning well, and now I am trying to tweak it for my website. My goal is to make the carousel pause when someone hovers over it. I've experimented with all the options available on the owl slider ...

Enable landscape mode exclusively for tablet and mobile devices, excluding desktop users

Looking to rotate content on tablet and mobile devices without affecting desktop view. Attempted solutions: rotate(90deg) -> Didn't work as it rotated even on desktop @media screen and (orientation:lanscape) -> Also didn't work as it ...

Webpack doesn't seem to be able to display custom fonts

I have a small project in progress using webpack. One of the tasks I'm facing is loading custom fonts. I followed the official tutorial here, where it explains how to handle assets in webpack configuration. My custom fonts are located within the src ...

knockout.js' $root leads to a page displaying nothing

Using the $root binding context is resulting in a blank page for me. Removing it allows the page to load properly. Causing blank page: <td><input data-bind="value: name" /></td> <td><select data-bind="options: $root.availableMe ...

"The server responded with a 405 error message indicating that the requested method

I have been working on a registration form project using HTML, JS, NodeJS, and SQLite. However, I am encountering an issue with the fetch function when trying to post the inputted information into the database. I keep receiving a POST 405 (Method Not Allo ...

Event response lacks necessary latlng data from Gmaps API

Currently, I am utilizing Angular UI Google Maps and facing an issue in retrieving the latlng when a map click event occurs. Although the map is responding, it is not providing the latlng information as expected. Below is the excerpt of my code: Controlle ...

Determine the dropdown list value by analyzing the final two variables in a textfield

In my textfield, car registration numbers are meant to be entered. These registrations are based on years in the format GT 74454 12, with the last two digits "12" representing the year 2012. I am looking for a script that can automatically detect the last ...

What is the best way to pass data from the server to a Vue CLI application?

I am looking for a way to connect my Vue CLI app to a server back-end. The server will send a view template along with data payload, and I need to inject that payload as JSON into the Vue app as a data property. Here is a snippet of the index.html file ge ...

Ways to retrieve class variables within a callback in Typescript

Here is the code I'm currently working with: import {Page} from 'ionic-angular'; import {BLE} from 'ionic-native'; @Page({ templateUrl: 'build/pages/list/list.html' }) export class ListPage { devices: Array<{nam ...

What is the best way to display a div beneath the highlighted text within a textarea field?

I have encountered a situation where I want to display a div (like a popup) when text is selected in a text area. However, when using mouse-down for this action, the position of the div sometimes does not align directly below the selected text. Below is t ...

Using Three.js to transfer one object's rotation to another object

I have been attempting to transfer one object's rotation to another with no success using the following methods: //The first method rotates much faster than the original object's rotation boxme1.rotateOnAxis(new t.Vector3(0,1,0), cube.rotation.y ...

Creating a stylish menu with CSS and Bootstrap featuring two beautifully designed rows

Looking to design a header for a webpage that features a logo on the left side in the center, along with two rows of menu items positioned on the right using CSS and Bootstrap classes. Below is an example layout: ---------------------------------------- ...

Is feature recognition possible in a jQuery plugin?

Can I integrate a tool similar to Modernizr into my plugin? I want to be able to test for specific CSS3 properties without starting from scratch. ...

Redux - The same reducers, containers, and components are yielding varying outcomes

update: Issue resolved by connecting a different variable to the mapStateToProps. I'm encountering some challenges with my react-redux application and I'm struggling to pinpoint the error in my setup. You can access the source code here. The f ...

Discovering data in individual tr elements within a table with jQuery by utilizing .text()

I'm currently working on a project where I need to separate the three table rows within a dynamically generated table. My goal is to have jQuery treat each row individually in order to extract specific values like price and SKU. You can see an example ...