Add flair to the ButtonBase element within a Tab component

I'm currently exploring how to override Material UI styles with a nested component. For instance, what if I want to increase the bottom border height on an active Tab, which is applied by the underlying ButtonBase.

Below is the style definition:

const useStyles = makeStyles(theme => ({
  root: {
    // A quick example of overriding, but not the cleanest. Is there a better way to handle the button?
    "& .MuiSvgIcon-root": {
      marginRight: "8px"
    }
  },
  // Overriding Tab styles
  tabWrapper: {
    flexDirection: "row"
  },
  tabSelected: {
    color: theme.palette.primary.main
  },
  tabLabelIcon: theme.mixins.toolbar, // Same minHeight as toolbar
  // TODO override buttonBase ???
  // ...
}));

Here's an example of usage:

      <Tab
        value="/"
        classes={{
          wrapper: classes.tabWrapper,
          selected: classes.tabSelected,
          labelIcon: classes.tabLabelIcon
        }}
        icon={
          <React.Fragment>
            <DashboardIcon />
          </React.Fragment>
        }
        label="Home"
        // TODO: Is this the correct syntax? TypeScript doesn't seem to like this prop...
        buttonBaseProps={{ classes: {} }}
      />

I'm unsure how to define the classes for ButtonBase in this scenario.

What should my props look like to override the style of ButtonBase?

Edit: The documentation can be found here https://material-ui.com/api/tab/. The last section describes the inheritance process, but it's quite concise.

Edit 2: The example use case might not be perfect, as we should actually be overriding ".MuiTabs-indicator" to adjust the bottom border height (which is actually an additional span, not a border). However, the question remains the same. Imagine I wanted to change the background-color of the ButtonBase.

Answer №1

It appears that there is no distinct ButtonBase component within the Tab component. Therefore, there is no prop named buttonBaseProps to be found. The tab itself serves as the button component.

If you wish to pass any styles, do so by applying them to the root inside classes. Refer to the code snippet below:

<Tab classes={{
          root: classes.customButtonBaseRoot,
          wrapper: classes.tabWrapper,
          selected: classes.tabSelected,
          labelIcon: classes.tabLabelIcon
        }}
      />

https://codesandbox.io/s/apply-style-to-buttonbase-in-a-tab-component-izgj5

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

encountering an error with hook calls within a functional component despite using hooks correctly

https://i.stack.imgur.com/iATJi.pngGreetings! I am currently working on a Next.js app using Axios and TanstackQuery. My goal is to redirect to the "/login" page when a 401 error is caught by the AxiosInterceptorInstance. The React version is 18, react-dom ...

Guide on creating my inaugural HTML embeddable widget?

A client recently requested me to create a JavaScript (MooTools)/HTML/CSS/PHP based game as a deployable widget. This will be my first time developing a widget, so I am seeking advice and insights to help me navigate any potential challenges from experie ...

Icon that can be clicked before

I'm struggling to figure out how to make the link icon in my code clickable so that users can click anywhere within the card to navigate to another page. I experimented with (" attr(href) ") but it resulted in adding the URL text next to the ...

What is the method to display just the final 3 characters within a paragraph?

Is there a way to display only the last three characters of a string using either a method or a string method? I consistently have a 13-digit number, but I specifically require showing only the final three digits. Appreciate any assistance provided. Than ...

The dividers flicker in and out of view

I have a menu with 7 elements, where clicking on an element causes its content to appear by fading in. If another element is clicked, the current content fades out and the new content fades in. I've successfully implemented this concept for 3 of the 7 ...

Is there a way to use a React-Bootstrap-Glyphicon to access the dropdown with React-Select?

I was looking to implement a dropdown using React-Select, but instead of the typical appearance as shown here: https://i.stack.imgur.com/UNSgr.png My goal was for it to have a look similar to this: https://i.stack.imgur.com/OfX40.png The current code I& ...

Leveraging CSS to automatically number nested sections

Assume we have an example HTML or XML document structured like this: <body> <section> <h1>This should be numbered 1</h1> <section> <h1>This should be numbered 1.1</h1> <p>blah& ...

Is there a way to incorporate multiple rows into my table row headings?

Could someone please assist me in achieving this specific layout shown in the attached screenshot? I am having difficulty adding the ROW TITLE and making the "Merged header title will go here and centered vertically" to expand as illustrated in t ...

JQuery Menu with Broken UL Formatting on Windows versions of IE and Firefox

Hey there! I've been struggling with a menu design that works perfectly on Mac browsers but is completely broken on Windows. I've spent hours trying to fix it and would really appreciate if a kind programmer could take a look and help me out. The ...

Tips for incorporating filtering and sorting functionality in a API-focused application using React and Next.js

In my current project, I am developing a React application using Next.js. The main goal is to fetch data from an API and display cards based on user-selected filters. Specifically, I aim to retrieve the cards initially and then filter them according to the ...

Using jQuery to select the child element of the parent that came before

Recently, I've been experimenting with creating animations using CSS and jQuery. While it has been successful so far, I'm now looking to take it a step further. Specifically, I want information to appear on top of an image when the user clicks on ...

Excessive use of Bootstrap styling causing icons to appear oversized on the webpage

Recently, I embarked on a journey with Electron and React. My goal is to incorporate Font Awesome Icons into my project, but I'm encountering some difficulties. When attempting to render an icon, combining it with the Bootstrap 'row' class r ...

Tips on invoking an API within a switch case

Having trouble with my tab component setup. I've created three tabs, each pulling data from different API endpoints. My plan was to use a switch case in the onChange function to make the API calls based on the selected tab. However, I encountered an i ...

What is the mechanism for accessing the state of React-Hot-Toast through an export statement?

How does react-hot-toast enable changing its state from other components simply by exporting the components in react-hot-toast/src/index.ts using: export default toast; Example Usage in Nextjs14: =Layout.tsx: import { Toaster } from "react-hot-toast ...

Place the delete and edit buttons on the right side of the card

I am trying to align the edit and delete buttons with the image and premise name on the same line. Both buttons should be placed on the right side and have the same size as the card. Currently, the layout looks like this: https://i.sstatic.net/sNikU.png ...

Can the Material-UI Chip component be utilized to showcase two data elements in a column layout?

Currently, I am passing two pieces of data to the "label" attribute. This results in the "name" and "email" being displayed next to each other. <Chip label={`${option.name} ${option.email}`} style={{ ...

div is consistently correct across all web browsers

After creating the following CSS code for a div to always be positioned on the right: #button > .right { background-position: -268px 1415px; height: 180px; position: fixed; right: -90px; top: 40%; width: 263px; -webkit-transform ...

Adjust the size of a Highcharts chart before printing

I'm facing an issue with a chart that doesn't have a specified height or width. My goal is to print the graph in a taller and larger size when I click on the print button. I attempted to use setSize() function, but since there are no original di ...

Position the Crossmark to align with text using CSS styling

How can I properly align a crossmark and a checkmark with the text behind them? The checkmark looks aligned well, but the crossmark appears to be slightly off to the top-right. I'm hesitant to adjust margins and paddings as it may cause issues when th ...

Customizing Bootstrap CSS

In my recent code, I included a bootstrap css reference in this manner: <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5T ...