Creating a unique scroll icon for your Material-UI scrolling Tabs

Currently, I am utilizing the Scrollable tabs feature from Material-UI. How can I go about changing the icon of the scroll arrows in SVG format?

I came across the TabScrollButton component that is available for use. Would I need to create separate ones for the left and right arrow functionalities?

Furthermore, within the Tabs component, there is a prop called ScrollButtonComponent. How should I properly implement this feature?

Despite my attempts below, the desired outcome has not been achieved yet:

import Tab from '@material-ui/core/Tab';
import Tabs from '@material-ui/core/Tabs';
import TabScrollButton from '@material-ui/core/TabScrollButton';

import { CloseIcon } from 'app/components/atoms/icons';

const MyCarousel = ({ value }: Props) => {
  const selectedItem = value;

  const scrollButton = () => {
    return (
      <div>
        <TabScrollButton orientation="horizontal" direction="right">
          {CloseIcon}
        </TabScrollButton>
      </div>
    );
  };

  return (
    <div css={styles.root}>
      <Tabs
        value={value}
        indicatorColor="primary"
        variant="scrollable"
        scrollButtons="auto"
        aria-label="scrollable auto tabs example"
        ScrollButtonComponent={scrollButton}
      >
        <Tab label="Item One" />
        <Tab label="Item Two" />
        <Tab label="Item Three" />
        <Tab label="Item 4" />
        <Tab label="Item 5" />
        <Tab label="Item 6" />
        <Tab label="Item 7" />
        <Tab label="Item 8" />
        <Tab label="Item 9" />
      </Tabs>
    </div>
  );
};

export default MyCarousel;

Answer №1

You've got the right idea, but TabScrollButton is limited when it comes to customizing the back/forward icons. In this case, you'll need to create your own component for that purpose.

If you take a look at the TabScrollButton definition, you can use it as a starting point. Copy the code, make the necessary modifications, and insert your desired icons. Here's an example:

import ButtonBase from "@material-ui/core/ButtonBase";
import ArrowBackIcon from "@material-ui/icons/ArrowBack";
import ArrowForwardIcon from "@material-ui/icons/ArrowForward";

const MyTabScrollButton = forwardRef((props, ref) => {
  const { direction, ...other } = props;

  return (
    <ButtonBase
      component="div"
      ref={ref}
      style={{ opacity: other.disabled ? 0 : 1 }}
      {...other}
    >
      {direction === "left" ? (
        <ArrowBackIcon fontSize="small" />
      ) : (
        <ArrowForwardIcon fontSize="small" />
      )}
    </ButtonBase>
  );
});
<Tabs
  {...tabsProps}
  variant="scrollable"
  scrollButtons="auto"
  ScrollButtonComponent={MyTabScrollButton}
>
  {...}
</Tabs>

Check out the Live Demo

https://codesandbox.io/s/66982823how-create-custom-scroll-icon-inside-the-material-ui-scrolling-tabs-10pmw?file=/demo.tsx

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

Challenges with Creating a Custom Overlay Component for MUI DataGrid when No Results are

Buttons located beneath the NoResultsOverlay or NoRowsOverlay component are unresponsive because of their absolute positioning and lack of z-index. In addition, when the data grid is configured with autoHeight, the overlay components get cropped. Click o ...

Encountering errors in Vite SSR build when using MUI icons and date-time-picker

I am working on a VITE ssr playground with additional MUI packages available on GitHub. When I import any MUI icon and adapter from the date-time-picker, everything works fine in development mode. However, when I build the project, the server stops with e ...

Ways to prevent decreasing the value below zero in ReactJS?

I have created two buttons, one for increasing and another for decreasing a counter value. However, when I click on the minus button, it should not display negative values. But in my case, when I click on the minus button (initially at zero), it shows -1, ...

Steps for making a labeled TextField in React Material-UI

Is it possible to have a labeled text field in React using Material-UI with the sub-domain part prefilled? For example, like Semantic UI: https://i.stack.imgur.com/aVZfz.png Here is an example of how it can be done with Semantic UI: Semantic UI ...

Looking to organize and sum up values in DataTable REACT – is there a way to achieve this

I have a script that I'm working with and I want to group the data by the AKONT field and then totalize it based on the UM01S field. Is this something that can be done? const options = { UM01S: (item) => <td>{formatColumn('currency' ...

Installation of the rsuite package in React Suite is not successful

Encountered an error while trying to install the rsuite package (version 4.9.3) using the command: npm i rsuite I need some assistance with resolving this installation issue. Here is the error message that I received: npm ERR! code ERESOLVE npm ERR! ERESO ...

Material UI Typography in ReactJS is a powerful combination for creating

Is there a way to make the cursor appear like a button when hovering over typography? Also, how can I incorporate browser router routing to enable clicking? <Grid item lg={12} md={12} sm={12} xs={12} > <Typography noWrap className={c ...

Error: React Beautiful D&D is unable to retrieve dimensions when no reference is specified

Hey everyone! I'm currently working on a meta form creator and having some trouble with performance issues. I created a sandbox to ask for help, but keep getting the error message "Cannot get dimension when no ref is set" when trying to drag a second ...

Adjust the circle's background color according to the numeric value in NextJS

I am trying to customize the background circle color depending on the {id} parameter. I am currently implementing this feature in my project using NextJs and Tailwind CSS for styling. <div className="rounded-full bg-fixed h-8 w-8" style={{c ...

When clicking on the CardActionArea component from Material UI, the React Component fails to render

Encountering a unique problem I've never faced before. Utilizing Material UI components, specifically using CardActionArea in conjunction with Redirect from react-router-dom When the user clicks on the CardActionArea, the intention is to direct th ...

I'm having trouble locating the module "script!foundation-sites/dist/foundation.min.js on Heroic."

This is the content of my webpack.config.js file: var webpack = require('webpack'); var path = require('path'); process.env.NODE_ENV = process.env.NODE_ENV || 'development'; module.exports = { entry: [ 'script!jque ...

Dealing with useEffect being invoked twice within strictMode for processes that should only execute once

React's useEffect function is being called twice in strict mode, causing issues that need to be addressed. Specifically, how can we ensure that certain effects are only run once? This dilemma has arisen in a next.js environment, where it is essential ...

The process of updating a nested object property in Redux and React

Initially, the user object is established with properties such as name, color, and age using the SET_USER method. I need to modify the name property within the user object utilizing UPDATE_USER_NAME. However, despite trying a nested loop within UPDATE_USER ...

What is the best method for sending React and AJAX data to a Rails server?

I'm currently working on an application using reactjs for the frontend and rails for the backend. Although I'm new to rails, I've managed to create a registration system using reactjs. Now, my next challenge is posting data to the server wi ...

Exploring the world of end-to-end testing for playwright. How to handle oauth2 and email-passwordless authentication in your testing

As I delve into e2e testing with Playwright, I've encountered a challenge. The application I need to test can only be accessed through Github OAuth or email authentication links, managed by next-auth in a NextJS project. I'm unsure how to approa ...

Updating the pointer style in Material UI version 5 for disabled MuiButton components

Is there a way to change the cursor and startIcon for disabled buttons in my theme without having to repeat it for each button? I've been trying to figure it out but can't seem to find a solution. The &:hover doesn't work as expected, an ...

Most effective approach to managing state in a React UI Component

I recently delved into the world of React. I've been using it to build a design system library for my work, which consists of standalone UI components tailored for use in React applications. I've developed a specific approach to managing the sta ...

Component for Next.js that operates on the server side

I have been developing an open-source package specifically designed for integration with a Next.js application. One of the key components in this package is a custom replacement for the standard Link component. In order to expose the necessary APIs to user ...

Handling Events for the UNO Material Bottom Navigation Bar

Incorporating Uno.Material's BottomNavigationBar in my app has been a success so far, except for figuring out the event handler when a bottomnavigationbaritem is clicked. I've tried various options like ItemInvoked, OnPressed, OnTouch, OnClick, a ...

What is the process for customizing the appearance of a prop within the <TextField> component?

Using my custom DatePicker.js component, I have two instances of <TextField>. When the user clicks on the <CalendarIcon> within the <TextField>, a small calendar pops up. However, I want to style the label in the <TextField> in a sp ...