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

What causes the data to flicker between the old and new values when the state is updated in ReactJS?

Currently, I am developing a single-page application that fetches data from the Star Wars API. In the character section of the project, the goal is to display characters per page with the ability to navigate to the next or previous pages by clicking on but ...

React - Material UI - Empty Table

In my React and Material UI project, I am dynamically rendering a table. One issue I encountered is when the table has no corresponding rows - in such cases, I want to display a simple info message stating that there is no data available. To address this, ...

Learn how to dynamically incorporate multiple Bootstrap collapse elements in PHP

I've encountered an issue with my code that contains both HTML and PHP. The problem arises when there are multiple elements in a collapse, as only the first element works properly. This is due to the fact that each element has the same id named "colla ...

"When utilizing the useReducer hook with the useContext hook in Next.js and pasting the token, it

Struggling with incorporating useReducer and useContext in my Next.js project. I'm attempting to use the token generated by useReducer and useContext, but it keeps returning as undefined. Any guidance on how to resolve this issue? Here's a snipp ...

Is there a way to move the cards to the next line within a wrapper when the screen size is reached?

My goal is to showcase multiple elements in cards, obtained from my routing system, much like how I'm setting up my sidebar (which is functioning correctly). I have all the titles and icons ready, and the linking works seamlessly. This is where I&apo ...

What's the best way to modify the React state following a successful tRPCv10 request?

Looking to adapt the new tRPC version 10 for a basic shopping list CRUD Nextjs app. Managed to set up the tRPC endpoint successfully with "get all" and "create" handlers, both working fine when tested from the front end. However, facing an issue updating t ...

React components cannot be updated while in an unmounted state, unless utilizing a stateless component

What if I were to assume I understand the error and its usual cause, but now I'm at a loss as to why React is complaining? This error seems to be originating from a simple component: export interface PostHandlerOutProps { posts: PostFragment[]; } ...

What is the best way to use useContext in React while ensuring adherence to the rules of hooks?

I'm perplexed about integrating a login function for Google or Github within my context provider. What is the correct method to invoke a context provider in Next JS while adhering to the rules of hooks? // user.js const Context = createContext(); co ...

What is causing justifyContent: space-between not to function properly?

I want to display Text1Text2Text3Text4Text5Text6Text7 at the top with text alignment using justifyContent: 'space-between'. However, when I tried to do so, all texts ended up at the top. <div style={{display: 'flex-item', flex: 1, ...

The delay function in RxJS allows for waiting to return a value until a specific condition is met within a stream and

Currently, I am facing an issue with a method in my application that triggers a server request. This method has access to a stream from the redux-store and needs to execute a callback only when the result of the request is found in the mentioned stream. Th ...

Ensure that the Map reference object is accessible when the first modal window is displayed or opened

My issue involves a table where selecting a row should display the item's location on a map using react-map-gl in a Dialog component. However, upon clicking the row, the mapref returns null during the initial render, even though it should provide mapr ...

Fetch request encountered a 500 error due to the absence of the 'Access-Control-Allow-Origin' header on the requested resource

Currently, I am in the process of developing a front-end web application using create-react-app and need to make a request to the ProPublica API. The fetch call code snippet is as follows: export const fetchSenators = () => dispatch => { fetch(' ...

Employ material-ui default prop conditionally

I am implementing a StepLabel component in material ui. Depending on the props passed to the parent, I may need to make changes to the icon property of the StepLabel: interface Props { customClasses?: ClassNameMap; customIcon?: ReactNode; } const MySt ...

Struggling to Display/Retrieve a MongoDB Entry by its Unique Identifier in React

Despite my best efforts and a few minor setbacks, I am still struggling to retrieve an object by its ID in my React frontend. The issue arises when trying to access properties of the object in my Post Component. Even though the data seems available based o ...

Tips on presenting messages to users after clicking the submit button?

I am trying to extract data from a table. I am unsure if my current code is able to retrieve the value from the table. <script> function validateForm() { var x = document.forms["assessmentForm"]["perf_rating11"].value; var y = document.f ...

The issue of CSS imports not functioning when bundling JavaScript files with Parcel.js has been encountered

Since updating Parcel.js from version 2.9.0 to 2.12.0 in my project, I've encountered a problem with importing CSS into .tsx files. The project utilizes React, TypeScript, and CSS without using CSS modules. The CSS imports are structured like this: / ...

Is this the proper method for developing a bespoke hook in React? Avoiding unnecessary SWR invocations?

Take into consideration the following: I'm interested in abstracting Vercel's conditional SWR hook: hooks.js file import useSWR from 'swr'; import { useEffect, useState } from "react"; import axios from 'axios' a ...

Tips on loading content with setContent in Tiptap while using React

They have provided thorough information on content and commands in general. However, I've been searching everywhere using ctrl+F to find where "commands" should be inserted in the code. My goal is to load HTML that I previously exported with the Tipta ...

Implementing the Reactjs module CSS with multiple class selectors

When I click a button, I am trying to implement or add multiple classes to our container. However, the styling does not seem to be applied correctly. Here is the code snippet: Layout.module.css .Content { padding-left: 240px; min-height: calc(10 ...

Module 'csstype' not found

I am diving into the world of React with TypeScript. After setting up react and react-dom, I also installed @types/react and @types/react-dom which all went smoothly. However, a pesky error message keeps popping up: ERROR in [at-loader] ./node_modules/@t ...