Styling Icons for Tabs in Material UI

I am dynamically using these tabs:

<Tabs
          value={value}
          onChange={handleChange}
          variant="scrollable"
          scrollButtons="off"
          indicatorColor="primary"
          textColor="primary"
          aria-label="scrollable"
          classes={{
            indicator: classes.indicator,
            flexContainer: classes.flexContainer,
          }}
        >
          {routes.map((value, index) => (
            <Tab
              classes={{
                root: classes.tabRoot,
                wrapper: classes.wrapper,
                labelIcon: classes.labelIcon,
                selected: classes.selected,
              }}
              key={index}
              label={strings(value)}
              icon={getIcon(value)}
              {...a11yProps(index)}
            />
          ))}
          {<Grid container>
            <Grid item xs>
              <PrintButton
                type= "widget"
                params={queryParams}
                style={{
                  textTransform: "capitalize",
                  float: "right"
                }}
              />
            </Grid>
          </Grid>}
        </Tabs>

This is the function to get the icon:

const getIcon = (value) => {
  if (value === eventType.view) return <PageviewIcon />;
  if (value === eventType.lead) return <ContactsIcon />;
  if (value === eventType.share) return <ShareIcon />;
  if (value === eventType.follow) return <GroupAddIcon />;
  if (value === eventType.media) return <PermMediaIcon />;
  if (value === eventType.print) return <FindInPageIcon />;
  return null;
};

Each tab looks like this: https://i.sstatic.net/60Cla.png

I am trying to add padding between the icon and the label like this: https://i.sstatic.net/QTTlE.png

However, I have been unable to modify the default class MuiTab-labelIcon .MuiTab-wrapper which appears like this by default: https://i.sstatic.net/gKh6E.png

This issue only arose after updating to Material UI v4

I attempted using inline styling on the icons but it results in very small icons: https://i.sstatic.net/zPNUi.png

<ShareIcon style={{paddingBottom: '0px', paddingRight: "10px"}}/>

Any assistance would be greatly appreciated. Thank you in advance!

Answer №1

Encapsulate Text and Icon within a container element and add

style={{ display: 'flex', alignItems: 'center', flexDirection: 'row', justifyContent: 'center' }}

Answer №2

To change the icon position in the Tab component, make use of the iconposition prop.

<Tab icon={<PhoneMissedIcon />} iconPosition="start" label="start" />

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 could be causing vertices in Three.js to not update?

I currently have a loop of circles that are moving independently. My goal is to draw lines from the center of the canvas to each circle's location. The issue I am facing is that the lines are not updating their vertices correctly during rendering, eve ...

How can AngularJS catch the HTML element and data responsible for triggering an error handled by $exceptionHandler?

My application is equipped with a functional $exceptionHandler. It effectively captures angularJS errors and sends the error data to my email for analysis. However, there seems to be an issue where it fails to capture the HTML element responsible for trigg ...

The annoying Facebook "add a comment" popup refuses to close

Occasionally, the "add a comment" popup (iframe) in Facebook's Like plug-in fails to close and obstructs access to the content underneath. This issue has been noted while using Chrome 21 and Firefox 15. To replicate this problem, you can visit the fo ...

What is the process for adding my JSON data to a select dropdown list?

Looking to populate a selectlist in HTML with options retrieved from an API. Below is the HTML code : <div id="example" role="application"> <div class="demo-section k-header"> <select id="FeaturesSelec ...

Using JavaScript to display dynamic data pulled from Django models

I am currently in the process of designing my own personal blog template, but I have encountered a roadblock when it comes to creating a page that displays previews of all posts. This particular page consists of two columns, #content-column-left and #conte ...

Stripe: Either a source or customer must be provided

I've been working on incorporating Stripe into my online shopping cart project, but I've hit a roadblock. Whenever I try to submit the checkout form, I keep encountering the error message: "Must provide source or customer." I suspect there might ...

Displaying icons from an array using Material-UI

Issue at Hand: Currently, I am utilizing react and material-ui to develop my project. To maintain a clean code structure, I am populating menu items from a constant array as shown below: const menuItems = [ { label: "Home", path: "/home& ...

The Recharts Line chart fails to display newly added data points when data is updated

My app features a straightforward tool that enables users to monitor their weight changes over time. Despite successfully receiving new data in the props, the chart does not update and display the new point. Recharts Component: import React from 'rea ...

I'm looking to output a list of variables from a function using console.log in javascript within a node.js environment

function courseList(course1, course2, course3){ let course1=[{ Id: 154532, name:'basic digital marketing', duration: '15 days', price: 100000, }]; let course2=[{ Id: 154533, ...

Troubleshooting Unresolved Issues with MongoDB and Node.js Promises

In my node.js code, I have utilized MongoDB to retrieve certain numbers. Below is the snippet of my code: MongoClient.connect('mongodb://localhost:27017/mongomart', function(err, db) { assert.equal(null, err); var numItems = db.col ...

Instructions for securing a React Front End with Node.js Express-Sessions authentication:

I have decided to move away from using Firestore auth in order to develop my own authentication system. Here is my goal: To create a React web app that allows users to sign up and sign in. Authenticated users should be able to interact with a REST API, w ...

A guide on how to display slotted ng-template within Angular applications

I've created a customized component called tab. The structure of the template for the tab component is as follows: <ng-content></ng-content> When utilizing the tab component, it is done like this: <tab> <ng-template> . ...

Ensure your mobile device is age 13 or over before proceeding

I am developing a project with Next js. Here, I want to render a component if it is a mobile device. However, if I use the isMobileDevice value in jsx, I get the errors below. import useTranslation from "next-translate/useTranslation"; import isM ...

Creating an NPM package using Visual Studio 2017: A Step-by-Step Guide

I enjoy developing and publishing NPM packages using Visual Studio 2017. My preferred method is using TypeScript to generate the JavaScript files. Which project template would be best suited for this particular project? ...

Utilizing conditional formatting to set background colors in an HTML table

Our manufacturing company collects and documents data for the parts we produce. Currently, this information is logged on a spreadsheet with drawing dimensions in one column and actual measured values in another. The cell where the actual measured value i ...

Tips for pinpointing the root cause of a function call

This question may seem strange, but I need to distinguish between these two scenarios. Firstly, I have a function: function calculatePerDayRentCost(){ //body } and I am calling this function in two ways: Firstly, programmatically: $('#qtyExtraDri ...

Is it unnecessary to mention both JavaScript and AJAX together?

During a recent conversation I had, someone mentioned that it is inaccurate to state that since Ajax is JavaScript. The scenario was: "How can I perform an action on a webpage without requiring a page refresh?" My response: "Utilize JavaScript along wi ...

Upon logging in to the first HTML page, the user will be automatically redirected to the second HTML page while passing values

Is there a way to automatically redirect users to Login2.html when selecting "TEAM" in the dropdown on Login1.html, using the values entered in Login1.html? Similarly, can we redirect them to the Premium page when they select "Premium"? I need a solution u ...

Behavior of jQuery resizable when being used on elements can sometimes

A live demonstration showcasing unusual behavior can be found at: If you attempt to resize the window by grabbing the right border and adjusting it horizontally, the vertical alignment goes awry. This issue persists across all open windows accessed throug ...

Angular debounce on checkboxes allows you to prevent multiple rapid changes from

Managing multiple checkboxes to filter a dataset can be tricky. I am looking for a way to debounce the checkbox selection so that the filter is only triggered after a certain period of time, like waiting 500ms to a second after the last checkbox has been c ...