Answer №1

TabScrollButton component is in charge of displaying the arrow buttons. It is possible to apply customized styles to them. Simply hiding the arrows can cause the entire tab menu to shift abruptly. I would suggest narrowing the widths of the arrows instead, to prevent a wide gap. However, if you still prefer to hide them completely, we could implement a transition effect and reduce the width of inactive arrows to 0.

import TabScrollButton from '@material-ui/core/TabScrollButton';
import { withStyles} from '@material-ui/core/styles';

const MyTabScrollButton = withStyles(theme => ({
  root: {
    width: 28,
    overflow: 'hidden',
    transition: 'width 0.5s',
    '&.Mui-disabled': {
      width: 0,
    },
  },
}))(TabScrollButton);

<Tabs 
  ScrollButtonComponent={MyTabScrollButton}
  variant="scrollable"
  scrollButtons="auto"
>

Answer №2

A different approach I took was utilizing the styled method to customize MyTabScrollButton:

const StyledTabScrollButton = styled(TabScrollButton)({
    '&.Mui-disabled': {
        width: 0,
    },
    overflow: 'hidden',
    transition: 'width 0.5s',
    width: 28,
});

Answer №3

Here is a designated area for scrollable arrows. You have the option to utilize a basic tab version that does not require

scrollable

property, eliminating any excess space.

Alternatively, you can customize the current scrollable arrows by implementing your own component with appropriate styles such as absolute positioning. For instance:

        <Tabs
          ScrollButtonComponent={() => {
            return (
              <a style={
               { height: "10px", position: "absolute" }}>
                scroll
              </a>
            );
         />

Answer №4

By enabling the scrollable feature, you can make the navbar scroll within its viewport if it doesn't fit. The default behavior includes adding a space to accommodate the navigation arrows.

import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import AppBar from '@material-ui/core/AppBar';
import Tabs from '@material-ui/core/Tabs';
import Tab from '@material-ui/core/Tab';
import Typography from '@material-ui/core/Typography';

function TabContainer(props) {
  return (
    <Typography component="div" style={{ padding: 8 * 3 }}>
      {props.children}
    </Typography>
  );
}

TabContainer.propTypes = {
  children: PropTypes.node.isRequired,
};

const styles = theme => ({
  root: {
    flexGrow: 1,
    width: '100%',
    backgroundColor: theme.palette.background.paper,
  },
});

class ScrollableTabsButtonAuto extends React.Component {
  state = {
    value: 0,
  };

  handleChange = (event, value) => {
    this.setState({ value });
  };

  render() {
    const { classes } = this.props;
    const { value } = this.state;

    return (
      <div className={classes.root}>
        <AppBar position="static" color="default">
          <Tabs
            value={value}
            onChange={this.handleChange}
            indicatorColor="primary"
            textColor="primary"
            scrollButtons="auto"
          >
            <Tab label="Item One" />
            <Tab label="Item Two" />
            <Tab label="Item Three" />
            <Tab label="Item Four" />
            <Tab label="Item Five" />
            <Tab label="Item Six" />
            <Tab label="Item Seven" />
          </Tabs>
        </AppBar>
        {value === 0 && <TabContainer>Item One</TabContainer>}
        {value === 1 && <TabContainer>Item Two</TabContainer>}
        {value === 2 && <TabContainer>Item Three</TabContainer>}
        {value === 3 && <TabContainer>Item Four</TabContainer>}
        {value === 4 && <TabContainer>Item Five</TabContainer>}
        {value === 5 && <TabContainer>Item Six</TabContainer>}
        {value === 6 && <TabContainer>Item Seven</TabContainer>}
      </div>
    );
  }
}

ScrollableTabsButtonAuto.propTypes = {
  classes: PropTypes.object.isRequired,
};

export default withStyles(styles)(ScrollableTabsButtonAuto);

Hopefully, this information is beneficial! :)

Answer №5

I came up with a CSS solution for this problem

.parentDiv div[class*="MuiTabs-scrollButtonsAuto"] {
    display: none;
}

; where .parentDiv refers to the parent div's class.

In one of the 2 empty boxes, you will find a class named MuiTabs-scrollButtonsAuto-nnn, and vice versa.

Note: This solution may not be effective on production builds as MUI classes could be minified into short-hand class names like .jss3001 (unknown which plugin does the minification during build). I have encountered this issue on production builds myself.

Update: To address issues in build versions where class names are minified or converted, I have another workaround. The tabs are located between two scroll arrows, one of them being a button when active. By targeting the 1st and 3rd child divs, this method hides those elements. While not very flexible, it eliminates the need to use multiple MUI Tab versions. It is compatible with both development and production builds.

.parentDiv > div:nth-child(2) > div:nth-child(1):not([type="button"]) {
    display: none;
}
.parentDiv > div:nth-child(2) > div:nth-child(3):not([type="button"]) {
    display: none;
}

Answer №6

To achieve this, simply apply padding to the Tab component using inline styles as demonstrated in this example.

<Tabs value={value} onChange={this.handleChange}>
    <Tab style={{paddingLeft: 0, paddingRight: 0}} label="Item One" />
    <Tab label="Item Two" />
    <Tab label="Item Three" />
</Tabs> 

Answer №7

This is the CSS code that worked perfectly for me:

.MuiTabScrollButton-root.Mui-disabled {
  display: none;
}

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

The mui-datatables demo fails to display the code snippet as intended

Just diving into React and attempting to grasp MUI-datatables. The code snippet from the Codebox provided on the library's page isn't displaying in my browser, resulting in an empty page. Surprisingly, the console isn't showing any errors. ...

How can I define Record values in Typescript based on their specific keys?

I am working on creating a custom data structure that allows me to store values with string keys within the union string | number | boolean: type FilterKey = string; type FilterValue = string | number | boolean; type Filters<K extends FilterKey, T exten ...

react-relay Attempting to use @refetchable incorrectly within fragment definition

Currently, I am delving into learning react-relay (v13) and encountering an issue when trying to specify a pagination fragment with @refetchable. Despite having a straightforward structure, everything functions as intended without the usage of @refetchable ...

Tips for optimizing app launch speed in react native

Currently, I am working on a news app using react native. One issue that I am facing is the slow launch or startup time of the app before the home screen appears. Any suggestions to enhance the speed would be highly appreciated. It takes approximately 3-4 ...

Style your index with a Wordpress plugin

I've been attempting to modify a plugin's stylesheet, but I'm having trouble locating the CSS file that contains the necessary styles. Despite Chrome's developer tool indicating that it is styled directly on the index site, I have searc ...

Use parameters with initialRouteName in React Native StackNavigator

When using the 'react-navigation' library, I am wondering how to pass parameters with the initialRouteName in Stack.Navigator. return ( <Stack.Navigator initialRouteName={routeName} screenOptions={{ animation: 'sl ...

Challenge with Adding Padding to Icon and Label

https://i.stack.imgur.com/OSCnh.png Incorporating paddingtop to the Floating Label and positioning the DrawableRight Icon in the center. <android.support.design.widget.TextInputLayout android:id="@+id/input_layout_password" android:layout_wid ...

Arranging elements on a CSS grid with overlapping placements

I have a comments box that overlaps an image and should remain fixed to the bottom of the image. However, the 'existing-comments-container' keeps stretching to the end of the page instead of just across the width of the image container as expecte ...

When attempting to print a Bootstrap 4 HTML page in Chrome, the browser headers and footers are being clipped

Currently experiencing an issue with printing an HTML page styled using Bootstrap 4 (Bootstrap 3.3.7 works fine) on Chrome where the header and footer are partly covered up. Take a look at this screenshot to see what I mean - the date, title, and file/url ...

Tips for keeping the footer firmly planted at the bottom of your Bootstrap 4 page

I have a question that might sound familiar! I want my footer to sit at the bottom of the page, but not remain fixed in place when I scroll. I'm aiming for a footer similar to what you see at the bottom of this webpage Footer Example. Here's the ...

I.E Compatibility Problem with Button CSS Styling

I've created a button with some styling that looks great on Firefox and Chrome, but unfortunately doesn't work quite right on Internet Explorer (all versions). Check out the JsFiddle DEMO : http://jsfiddle.net/Mhded/1/ Below is the code I' ...

I recently added Tailwindcss to my project and set up the configuration after initialization. However, I am facing issues as my styles are not being applied to the page

This is my current tailwind configuration file. I have attempted different suggestions found on Stack Overflow, but none seem to be resolving the issue. Does anyone have any insights or catch any mistakes that may not be related to the content? Thank you ...

Creating custom Bootstrap Card Groups by dynamically generating the specified number of cards with Angular directives

I am currently using Angular 9.1.8 for my project. For my Angular component, I have implemented Bootstrap Card Groups and Cards to display a large result set of cards in rows with more than two cards per row. Below are four example cards: <div class=&q ...

Encountering an 'Error: Page Not Found' message on the live Heroku website

I have a MERN stack application in progress. The Node server is running locally and connected to the MongoDB Database. It is also set up to build and deploy on Heroku. However, when I click on "Open App" on the Heroku page, it displays "Cannot GET /". I m ...

Using CSS3 and Javascript to create engaging transition animations

I'm facing an issue with a DIV class that I've set up like this: div.map_view{ height: 420px; transition: height 2s; -moz-transition: height 2s; /* Firefox 4 */ -webkit-transition: height 2s; /* Safari and Chrome */ -o-transition: height 2s; /* ...

Utilizing Bootstrap 3 to eliminate the blue border surrounding the Contact Button

Recently, I integrated Bootstrap 3 into my website and encountered an issue. After selecting the Contact button and closing the popup window, it remains highlighted which is not desirable. https://i.sstatic.net/pzfKy.png I want to modify my CSS file so t ...

Experiencing an unexpected abundance of console logs when implementing React Hooks

I am attempting to retrieve data from an API. The desired result is being obtained, but when I attempt to log it to the console, it logs 4 times. Within my app.js, I am utilizing the fetchData function: import React, {useEffect, useState} from 'rea ...

What is the best way to pass parameters to child functions in a React component?

Looking to add a ripple effect in React using the react-water-wave package? Check out this repository: https://github.com/xxhomey19/react-water-wave While I can successfully call child methods without parameters, I'm running into issues when trying t ...

Addressing padding inconsistencies in mobile email HTML templates

I am new to the world of HTML and CSS. I apologize if this question seems trivial, as I have searched extensively online with no success! You can access my email HTML template here. The issue I am facing is: The top and bottom padding around the backgrou ...

Making the most of emotion with theme.transitions.create: A guide

I had this Material-UI v4 code that was working perfectly: <Button aria-expanded={optionsExpanded} onClick={() => dispatch(toggleOptionsExpanded())} endIcon={ <ExpandMoreIcon className={clsx(classes.expand, { [class ...